mirror of
https://github.com/c-cube/moonpool.git
synced 2025-12-05 19:00:33 -05:00
fix tests to use new API
This commit is contained in:
parent
d09da9c092
commit
8aaed6d951
20 changed files with 53 additions and 47 deletions
|
|
@ -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 = <abstr>
|
||||
|
||||
# begin
|
||||
|
|
|
|||
|
|
@ -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 <n>";
|
||||
"-seq", Arg.Set seq, " sequential";
|
||||
"-dl", Arg.Set dl, " domainslib";
|
||||
|
|
|
|||
|
|
@ -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_} *)
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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 () ->
|
||||
|
|
|
|||
|
|
@ -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 =
|
||||
|
|
|
|||
|
|
@ -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 =
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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 ());
|
||||
|
||||
()
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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 () =
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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 () =
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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 ->
|
||||
|
|
|
|||
|
|
@ -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 () =
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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 *)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue