Skip to content

Commit

Permalink
fix tests to use new API
Browse files Browse the repository at this point in the history
  • Loading branch information
c-cube committed Oct 28, 2023
1 parent d09da9c commit 8aaed6d
Show file tree
Hide file tree
Showing 20 changed files with 53 additions and 47 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 14 additions & 8 deletions benchs/fib_rec.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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";
Expand Down
8 changes: 4 additions & 4 deletions benchs/pi.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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_} *)
Expand Down
4 changes: 2 additions & 2 deletions test/effect-based/t_fib1.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions test/effect-based/t_fib_fork_join.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions test/effect-based/t_fib_fork_join_all.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 () ->
Expand Down
8 changes: 4 additions & 4 deletions test/effect-based/t_fork_join.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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 =
Expand Down
2 changes: 1 addition & 1 deletion test/effect-based/t_fork_join_heavy.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
2 changes: 1 addition & 1 deletion test/effect-based/t_futs1.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions test/effect-based/t_many.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 ());

()
Expand Down
2 changes: 1 addition & 1 deletion test/effect-based/t_sort.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/t_bench1.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 () =
Expand Down
2 changes: 1 addition & 1 deletion test/t_chan_train.ml
Original file line number Diff line number Diff line change
@@ -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)

Expand Down
4 changes: 2 additions & 2 deletions test/t_fib.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions test/t_fib_rec.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 () =
Expand Down
4 changes: 2 additions & 2 deletions test/t_futs1.ml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions test/t_props.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 ->
Expand Down
4 changes: 2 additions & 2 deletions test/t_resource.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 () =
Expand Down
4 changes: 2 additions & 2 deletions test/t_tree_futs.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions test/t_unfair.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 *)
Expand Down

0 comments on commit 8aaed6d

Please sign in to comment.