diff --git a/README.md b/README.md index ab451e08..b06a1975 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ the workers of `pool`, as soon as one is available. No result is returned by `ru ```ocaml # #require "threads";; -# let pool = Moonpool.Fifo_pool.create ~min:4 ();; +# let pool = Moonpool.Fifo_pool.create ~num_threads:4 ();; val pool : Moonpool.Runner.t = # begin diff --git a/benchs/fib_rec.ml b/benchs/fib_rec.ml index d3df44df..571b8495 100644 --- a/benchs/fib_rec.ml +++ b/benchs/fib_rec.ml @@ -57,10 +57,14 @@ let () = assert (List.init 10 fib_direct = [ 1; 1; 2; 3; 5; 8; 13; 21; 34; 55 ]) let create_pool ~psize ~kind () = match kind with - | "fifo" -> Fifo_pool.create ~min:psize () - | "pool" -> Ws_pool.create ~min:psize () + | "fifo" -> Fifo_pool.create ?num_threads:psize () + | "pool" -> Ws_pool.create ?num_threads:psize () | _ -> assert false +let str_of_int_opt = function + | None -> "None" + | Some i -> Printf.sprintf "Some %d" i + let run ~psize ~n ~seq ~dl ~fj ~await ~niter ~kind () : unit = let pool = lazy (create_pool ~kind ~psize ()) in let dl_pool = @@ -80,14 +84,16 @@ let run ~psize ~n ~seq ~dl ~fj ~await ~niter ~kind () : unit = Domainslib.Task.run pool (fun () -> Domainslib.Task.await pool @@ fib_dl ~pool n) ) else if fj then ( - Printf.printf "compute fib %d using fork-join with pool size=%d\n%!" n - psize; + Printf.printf "compute fib %d using fork-join with pool size=%s\n%!" n + (str_of_int_opt psize); fib_fj ~on:(Lazy.force pool) n |> Fut.wait_block_exn ) else if await then ( - Printf.printf "compute fib %d using await with pool size=%d\n%!" n psize; + Printf.printf "compute fib %d using await with pool size=%s\n%!" n + (str_of_int_opt psize); fib_await ~on:(Lazy.force pool) n |> Fut.wait_block_exn ) else ( - Printf.printf "compute fib %d with pool size=%d\n%!" n psize; + Printf.printf "compute fib %d with pool size=%s\n%!" n + (str_of_int_opt psize); fib ~on:(Lazy.force pool) n |> Fut.wait_block_exn ) in @@ -103,7 +109,7 @@ let run ~psize ~n ~seq ~dl ~fj ~await ~niter ~kind () : unit = let () = let n = ref 40 in - let psize = ref 16 in + let psize = ref None in let seq = ref false in let niter = ref 3 in let kind = ref "pool" in @@ -112,7 +118,7 @@ let () = let fj = ref false in let opts = [ - "-psize", Arg.Set_int psize, " pool size"; + "-psize", Arg.Int (fun i -> psize := Some i), " pool size"; "-n", Arg.Set_int n, " fib "; "-seq", Arg.Set seq, " sequential"; "-dl", Arg.Set dl, " domainslib"; diff --git a/benchs/pi.ml b/benchs/pi.ml index 65304a80..c8ef57b5 100644 --- a/benchs/pi.ml +++ b/benchs/pi.ml @@ -21,14 +21,14 @@ let with_pool ~kind f = match kind with | "pool" -> if !j = 0 then - Ws_pool.with_ ~per_domain:1 f + Ws_pool.with_ f else - Ws_pool.with_ ~min:!j f + Ws_pool.with_ ~num_threads:!j f | "fifo" -> if !j = 0 then - Fifo_pool.with_ ~per_domain:1 f + Fifo_pool.with_ f else - Fifo_pool.with_ ~min:!j f + Fifo_pool.with_ ~num_threads:!j f | _ -> assert false (** Run in parallel using {!Fut.for_} *) diff --git a/test/effect-based/t_fib1.ml b/test/effect-based/t_fib1.ml index ca3f2861..a7c8ebee 100644 --- a/test/effect-based/t_fib1.ml +++ b/test/effect-based/t_fib1.ml @@ -26,13 +26,13 @@ let fib ~on x : int Fut.t = let () = assert (List.init 10 fib_direct = [ 1; 1; 2; 3; 5; 8; 13; 21; 34; 55 ]) let fib_40 : int = - let pool = Ws_pool.create ~min:8 () in + let pool = Ws_pool.create ~num_threads:8 () in fib ~on:pool 40 |> Fut.wait_block_exn let () = Printf.printf "fib 40 = %d\n%!" fib_40 let run_test () = - let pool = Ws_pool.create ~min:8 () in + let pool = Ws_pool.create ~num_threads:8 () in assert ( List.init 10 (fib ~on:pool) diff --git a/test/effect-based/t_fib_fork_join.ml b/test/effect-based/t_fib_fork_join.ml index bdf60337..4e6639b2 100644 --- a/test/effect-based/t_fib_fork_join.ml +++ b/test/effect-based/t_fib_fork_join.ml @@ -27,13 +27,13 @@ let fib ~on x : int Fut.t = let () = assert (List.init 10 fib_direct = [ 1; 1; 2; 3; 5; 8; 13; 21; 34; 55 ]) let fib_40 : int = - let pool = Ws_pool.create ~min:8 () in + let pool = Ws_pool.create ~num_threads:8 () in fib ~on:pool 40 |> Fut.wait_block_exn let () = Printf.printf "fib 40 = %d\n%!" fib_40 let run_test () = - let pool = Ws_pool.create ~min:8 () in + let pool = Ws_pool.create ~num_threads:8 () in assert ( List.init 10 (fib ~on:pool) diff --git a/test/effect-based/t_fib_fork_join_all.ml b/test/effect-based/t_fib_fork_join_all.ml index ed82902e..3caee9b9 100644 --- a/test/effect-based/t_fib_fork_join_all.ml +++ b/test/effect-based/t_fib_fork_join_all.ml @@ -22,13 +22,13 @@ let rec fib x : int = ) let fib_40 : int = - let@ pool = Ws_pool.with_ ~min:8 () in + let@ pool = Ws_pool.with_ ~num_threads:8 () in Fut.spawn ~on:pool (fun () -> fib 40) |> Fut.wait_block_exn let () = Printf.printf "fib 40 = %d\n%!" fib_40 let run_test () = - let@ pool = Ws_pool.with_ ~min:8 () in + let@ pool = Ws_pool.with_ ~num_threads:8 () in let fut = Fut.spawn ~on:pool (fun () -> diff --git a/test/effect-based/t_fork_join.ml b/test/effect-based/t_fork_join.ml index 5b467187..5c7134ca 100644 --- a/test/effect-based/t_fork_join.ml +++ b/test/effect-based/t_fork_join.ml @@ -5,7 +5,7 @@ let ( let@ ) = ( @@ ) open! Moonpool -let pool = Ws_pool.create ~min:4 () +let pool = Ws_pool.create ~num_threads:4 () let () = let x = @@ -270,7 +270,7 @@ end let t_eval = let arb = Q.set_stats [ "size", Evaluator.size ] Evaluator.arb in Q.Test.make ~name:"same eval" arb (fun e -> - let@ pool = Ws_pool.with_ ~min:4 () in + let@ pool = Ws_pool.with_ ~num_threads:4 () in (* Printf.eprintf "eval %s\n%!" (Evaluator.show e); *) let x = Evaluator.eval_seq e in let y = Evaluator.eval_fork_join ~pool e in @@ -288,7 +288,7 @@ let t_for_nested ~min ~chunk_size () = let ref_l2 = List.map (List.map neg) ref_l1 in let l1, l2 = - let@ pool = Ws_pool.with_ ~min () in + let@ pool = Ws_pool.with_ ~num_threads:min () in let@ () = Ws_pool.run_wait_block pool in let l1 = Fork_join.map_list ~chunk_size (Fork_join.map_list ~chunk_size neg) l @@ -310,7 +310,7 @@ let t_map ~chunk_size () = Q.Test.make ~name:"map1" Q.(small_list small_int |> Q.set_stats [ "len", List.length ]) (fun l -> - let@ pool = Ws_pool.with_ ~min:4 () in + let@ pool = Ws_pool.with_ ~num_threads:4 () in let@ () = Ws_pool.run_wait_block pool in let a1 = diff --git a/test/effect-based/t_fork_join_heavy.ml b/test/effect-based/t_fork_join_heavy.ml index ad9f7044..a981bee1 100644 --- a/test/effect-based/t_fork_join_heavy.ml +++ b/test/effect-based/t_fork_join_heavy.ml @@ -27,7 +27,7 @@ let run ~min () = let@ _sp = Trace.with_span ~__FILE__ ~__LINE__ "step" in let l1, l2 = - let@ pool = Ws_pool.with_ ~min () in + let@ pool = Ws_pool.with_ ~num_threads:min () in let@ () = Ws_pool.run_wait_block pool in let l1, l2 = diff --git a/test/effect-based/t_futs1.ml b/test/effect-based/t_futs1.ml index 182ca9d5..4df18226 100644 --- a/test/effect-based/t_futs1.ml +++ b/test/effect-based/t_futs1.ml @@ -2,7 +2,7 @@ open! Moonpool -let pool = Ws_pool.create ~min:4 () +let pool = Ws_pool.create ~num_threads:4 () let () = let fut = Array.init 10 (fun i -> Fut.spawn ~on:pool (fun () -> i)) in diff --git a/test/effect-based/t_many.ml b/test/effect-based/t_many.ml index 4362932c..6a2b5918 100644 --- a/test/effect-based/t_many.ml +++ b/test/effect-based/t_many.ml @@ -30,19 +30,19 @@ let run ~pool () = let () = (print_endline "with fifo"; - let@ pool = Fifo_pool.with_ ~min:4 () in + let@ pool = Fifo_pool.with_ ~num_threads:4 () in run ~pool ()); (print_endline "with WS(1)"; - let@ pool = Ws_pool.with_ ~min:1 () in + let@ pool = Ws_pool.with_ ~num_threads:1 () in run ~pool ()); (print_endline "with WS(2)"; - let@ pool = Ws_pool.with_ ~min:2 () in + let@ pool = Ws_pool.with_ ~num_threads:2 () in run ~pool ()); (print_endline "with WS(4)"; - let@ pool = Ws_pool.with_ ~min:4 () in + let@ pool = Ws_pool.with_ ~num_threads:4 () in run ~pool ()); () diff --git a/test/effect-based/t_sort.ml b/test/effect-based/t_sort.ml index 8d3fe17c..8ccc372f 100644 --- a/test/effect-based/t_sort.ml +++ b/test/effect-based/t_sort.ml @@ -59,7 +59,7 @@ let rec quicksort arr i len : unit = (fun () -> quicksort arr !low (len - (!low - i))) ) -let pool = Moonpool.Ws_pool.create ~min:8 () +let pool = Moonpool.Ws_pool.create ~num_threads:8 () let () = let arr = Array.init 400_000 (fun _ -> Random.int 300_000) in diff --git a/test/t_bench1.ml b/test/t_bench1.ml index 95cd87a5..cd1a8bfd 100644 --- a/test/t_bench1.ml +++ b/test/t_bench1.ml @@ -8,7 +8,7 @@ let rec fib x = let run ~psize ~n ~j () : _ Fut.t = Printf.printf "pool size=%d, n=%d, j=%d\n%!" psize n j; - let pool = Ws_pool.create ~min:psize ~per_domain:0 () in + let pool = Ws_pool.create ~num_threads:psize () in (* TODO: a ppx for tracy so we can use instrumentation *) let loop () = diff --git a/test/t_chan_train.ml b/test/t_chan_train.ml index bb3e24f7..132d5540 100644 --- a/test/t_chan_train.ml +++ b/test/t_chan_train.ml @@ -1,7 +1,7 @@ open Moonpool (* large pool, some of our tasks below are long lived *) -let pool = Ws_pool.create ~min:30 () +let pool = Ws_pool.create ~num_threads:30 () open (val Fut.infix pool) diff --git a/test/t_fib.ml b/test/t_fib.ml index 3a98e395..3fc53bf9 100644 --- a/test/t_fib.ml +++ b/test/t_fib.ml @@ -4,8 +4,8 @@ let ( let@ ) = ( @@ ) let with_pool ~kind () f = match kind with - | `Fifo_pool -> Fifo_pool.with_ ~min:4 () f - | `Ws_pool -> Ws_pool.with_ ~min:4 () f + | `Fifo_pool -> Fifo_pool.with_ ~num_threads:4 () f + | `Ws_pool -> Ws_pool.with_ ~num_threads:4 () f let rec fib x = if x <= 1 then diff --git a/test/t_fib_rec.ml b/test/t_fib_rec.ml index 286e6aac..94e206b7 100644 --- a/test/t_fib_rec.ml +++ b/test/t_fib_rec.ml @@ -25,7 +25,7 @@ let () = assert (List.init 10 fib_direct = [ 1; 1; 2; 3; 5; 8; 13; 21; 34; 55 ]) let fib_40 : int lazy_t = lazy (let@ _sp = Trace.with_span ~__FILE__ ~__LINE__ "fib40" in - let pool = Fifo_pool.create ~min:8 () in + let pool = Fifo_pool.create ~num_threads:8 () in let r = fib ~on:pool 40 |> Fut.wait_block_exn in Ws_pool.shutdown pool; r) @@ -49,12 +49,12 @@ let run_test ~pool () = let run_test_size ~size () = Printf.printf "test pool(%d)\n%!" size; - let@ pool = Ws_pool.with_ ~min:size () in + let@ pool = Ws_pool.with_ ~num_threads:size () in run_test ~pool () let run_test_fifo ~size () = Printf.printf "test fifo(%d)\n%!" size; - let@ pool = Fifo_pool.with_ ~min:size () in + let@ pool = Fifo_pool.with_ ~num_threads:size () in run_test ~pool () let setup_counter () = diff --git a/test/t_futs1.ml b/test/t_futs1.ml index ee2d96a6..03a1ac13 100644 --- a/test/t_futs1.ml +++ b/test/t_futs1.ml @@ -1,7 +1,7 @@ open! Moonpool -let pool = Ws_pool.create ~min:4 () -let pool2 = Ws_pool.create ~min:2 () +let pool = Ws_pool.create ~num_threads:4 () +let pool2 = Ws_pool.create ~num_threads:2 () let () = let fut = Fut.return 1 in diff --git a/test/t_props.ml b/test/t_props.ml index 9fa64fbe..698650fd 100644 --- a/test/t_props.ml +++ b/test/t_props.ml @@ -7,8 +7,8 @@ let add_test t = tests := t :: !tests let with_pool ~kind () f = match kind with - | `Fifo_pool -> Fifo_pool.with_ ~min:4 ~per_domain:1 () f - | `Ws_pool -> Ws_pool.with_ ~min:4 ~per_domain:1 () f + | `Fifo_pool -> Fifo_pool.with_ () f + | `Ws_pool -> Ws_pool.with_ () f let () = add_test @@ fun ~kind -> diff --git a/test/t_resource.ml b/test/t_resource.ml index c990f708..4c20e9fb 100644 --- a/test/t_resource.ml +++ b/test/t_resource.ml @@ -4,8 +4,8 @@ let ( let@ ) = ( @@ ) let with_pool ~kind () f = match kind with - | `Fifo_pool -> Fifo_pool.with_ ~min:4 ~per_domain:1 () f - | `Ws_pool -> Ws_pool.with_ ~min:4 ~per_domain:1 () f + | `Fifo_pool -> Fifo_pool.with_ () f + | `Ws_pool -> Ws_pool.with_ () f (* test proper resource handling *) let run ~kind () = diff --git a/test/t_tree_futs.ml b/test/t_tree_futs.ml index 3507be0a..0bc96a03 100644 --- a/test/t_tree_futs.ml +++ b/test/t_tree_futs.ml @@ -4,8 +4,8 @@ let ( let@ ) = ( @@ ) let with_pool ~kind ~j () f = match kind with - | `Fifo_pool -> Fifo_pool.with_ ~min:j () f - | `Ws_pool -> Ws_pool.with_ ~min:j () f + | `Fifo_pool -> Fifo_pool.with_ ~num_threads:j () f + | `Ws_pool -> Ws_pool.with_ ~num_threads:j () f type 'a tree = | Leaf of 'a diff --git a/test/t_unfair.ml b/test/t_unfair.ml index f535a450..cee4373e 100644 --- a/test/t_unfair.ml +++ b/test/t_unfair.ml @@ -20,8 +20,8 @@ let run ~kind () = in match kind with - | `Simple -> Fifo_pool.create ~min:3 ~on_init_thread ~around_task () - | `Ws_pool -> Ws_pool.create ~min:3 ~on_init_thread ~around_task () + | `Simple -> Fifo_pool.create ~num_threads:3 ~on_init_thread ~around_task () + | `Ws_pool -> Ws_pool.create ~num_threads:3 ~on_init_thread ~around_task () in (* make all threads busy *)