mirror of
https://github.com/c-cube/moonpool.git
synced 2025-12-05 19:00:33 -05:00
repro for #41
This commit is contained in:
parent
95de0e7e27
commit
8770d4fb9c
3 changed files with 67 additions and 0 deletions
8
Makefile
8
Makefile
|
|
@ -67,6 +67,14 @@ bench-pi:
|
|||
'./_build/default/benchs/pi.exe -n $(PI_NSTEPS) -j 16 -mode forkjoin -kind=pool' \
|
||||
'./_build/default/benchs/pi.exe -n $(PI_NSTEPS) -j 20 -mode forkjoin -kind=pool'
|
||||
|
||||
bench-repro-41:
|
||||
dune build $(DUNE_OPTS_BENCH) examples/repro_41/run.exe
|
||||
hyperfine --warmup=1 \
|
||||
"./_build/default/examples/repro_41/run.exe 4 domainslib" \
|
||||
"./_build/default/examples/repro_41/run.exe 4 moonpool" \
|
||||
"./_build/default/examples/repro_41/run.exe 5 moonpool" \
|
||||
"./_build/default/examples/repro_41/run.exe 5 seq"
|
||||
|
||||
.PHONY: test clean bench-fib bench-pi
|
||||
|
||||
VERSION=$(shell awk '/^version:/ {print $$2}' moonpool.opam)
|
||||
|
|
|
|||
5
examples/repro_41/dune
Normal file
5
examples/repro_41/dune
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
(executables
|
||||
(names run)
|
||||
(enabled_if
|
||||
(>= %{ocaml_version} 5.0))
|
||||
(libraries moonpool trace trace-tef domainslib))
|
||||
54
examples/repro_41/run.ml
Normal file
54
examples/repro_41/run.ml
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
(* fibo.ml *)
|
||||
let cutoff = 25
|
||||
let input = 40
|
||||
|
||||
let rec fibo_seq n =
|
||||
if n <= 1 then
|
||||
n
|
||||
else
|
||||
fibo_seq (n - 1) + fibo_seq (n - 2)
|
||||
|
||||
let rec fibo_domainslib ctx n =
|
||||
if n <= cutoff then
|
||||
fibo_seq n
|
||||
else
|
||||
let open Domainslib in
|
||||
let fut1 = Task.async ctx (fun () -> fibo_domainslib ctx (n - 1)) in
|
||||
let fut2 = Task.async ctx (fun () -> fibo_domainslib ctx (n - 2)) in
|
||||
Task.await ctx fut1 + Task.await ctx fut2
|
||||
|
||||
let rec fibo_moonpool ctx n =
|
||||
if n <= cutoff then
|
||||
fibo_seq n
|
||||
else
|
||||
let open Moonpool in
|
||||
let fut1 = Fut.spawn ~on:ctx (fun () -> fibo_moonpool ctx (n - 1)) in
|
||||
let fut2 = Fut.spawn ~on:ctx (fun () -> fibo_moonpool ctx (n - 2)) in
|
||||
Fut.await fut1 + Fut.await fut2
|
||||
|
||||
let usage =
|
||||
"fibo.exe <num_domains> [ domainslib | moonpool | moonpool_fifo | seq ]"
|
||||
|
||||
let num_domains = try int_of_string Sys.argv.(1) with _ -> failwith usage
|
||||
let implem = try Sys.argv.(2) with _ -> failwith usage
|
||||
|
||||
let () =
|
||||
let output =
|
||||
match implem with
|
||||
| "moonpool" ->
|
||||
let open Moonpool in
|
||||
let ctx = Ws_pool.create ~num_threads:num_domains () in
|
||||
Ws_pool.run_wait_block ctx (fun () -> fibo_moonpool ctx input)
|
||||
| "moonpool_fifo" ->
|
||||
let open Moonpool in
|
||||
let ctx = Fifo_pool.create ~num_threads:num_domains () in
|
||||
Ws_pool.run_wait_block ctx (fun () -> fibo_moonpool ctx input)
|
||||
| "domainslib" ->
|
||||
let open Domainslib in
|
||||
let pool = Task.setup_pool ~num_domains () in
|
||||
Task.run pool (fun () -> fibo_domainslib pool input)
|
||||
| "seq" -> fibo_seq input
|
||||
| _ -> failwith usage
|
||||
in
|
||||
print_int output;
|
||||
print_newline ()
|
||||
Loading…
Add table
Reference in a new issue