diff --git a/Makefile b/Makefile index b1acca61..3e63a195 100644 --- a/Makefile +++ b/Makefile @@ -22,22 +22,24 @@ watch: DUNE_OPTS_BENCH?=--profile=release N?=40 -NITER?=3 +NITER?=2 BENCH_PSIZE?=1,4,8,20 +BENCH_KIND?=simple,pool BENCH_CUTOFF?=20 bench-fib: @echo running for N=$(N) dune build $(DUNE_OPTS_BENCH) benchs/fib_rec.exe - hyperfine -L psize $(BENCH_PSIZE) --warmup=1 \ - './_build/default/benchs/fib_rec.exe -cutoff $(BENCH_CUTOFF) -niter $(NITER) -psize={psize} -n $(N)' + hyperfine -L psize $(BENCH_PSIZE) -L kind $(BENCH_KIND) --warmup=1 \ + './_build/default/benchs/fib_rec.exe -cutoff $(BENCH_CUTOFF) -niter $(NITER) -psize={psize} -kind={kind} -n $(N)' PI_NSTEPS?=100_000_000 PI_MODES?=seq,par1,forkjoin +PI_KIND?=simple,pool bench-pi: @echo running for N=$(PI_NSTEPS) dune build $(DUNE_OPTS_BENCH) benchs/pi.exe - hyperfine -L mode $(PI_MODES) --warmup=1 \ - './_build/default/benchs/pi.exe -mode={mode} -n $(PI_NSTEPS)' + hyperfine -L mode $(PI_MODES) -L kind $(PI_KIND) --warmup=1 \ + './_build/default/benchs/pi.exe -mode={mode} -kind={kind} -n $(PI_NSTEPS)' .PHONY: test clean bench-fib bench-pi diff --git a/benchs/dune b/benchs/dune index 2c798176..0ae20bf3 100644 --- a/benchs/dune +++ b/benchs/dune @@ -3,4 +3,4 @@ (names fib_rec pi) (preprocess (action (run %{project_root}/src/cpp/cpp.exe %{input-file}))) - (libraries moonpool unix)) + (libraries moonpool unix trace trace-tef)) diff --git a/benchs/fib_rec.ml b/benchs/fib_rec.ml index 1a3d3288..57a444f0 100644 --- a/benchs/fib_rec.ml +++ b/benchs/fib_rec.ml @@ -18,8 +18,14 @@ let rec fib ~on x : int Fut.t = let () = assert (List.init 10 fib_direct = [ 1; 1; 2; 3; 5; 8; 13; 21; 34; 55 ]) -let run ~psize ~n ~seq ~niter () : unit = - let pool = lazy (Pool.create ~min:psize ()) in +let create_pool ~psize ~kind () = + match kind with + | "simple" -> Simple_pool.create ~min:psize () + | "pool" -> Pool.create ~min:psize () + | _ -> assert false + +let run ~psize ~n ~seq ~niter ~kind () : unit = + let pool = lazy (create_pool ~kind ~psize ()) in for _i = 1 to niter do let res = if seq then ( @@ -39,6 +45,7 @@ let () = let psize = ref 16 in let seq = ref false in let niter = ref 3 in + let kind = ref "pool" in let opts = [ "-psize", Arg.Set_int psize, " pool size"; @@ -46,9 +53,12 @@ let () = "-seq", Arg.Set seq, " sequential"; "-niter", Arg.Set_int niter, " number of iterations"; "-cutoff", Arg.Set_int cutoff, " cutoff for sequential computation"; + ( "-kind", + Arg.Symbol ([ "pool"; "simple" ], ( := ) kind), + " pick pool implementation" ); ] |> Arg.align in Arg.parse opts ignore ""; - run ~psize:!psize ~n:!n ~seq:!seq ~niter:!niter () + run ~psize:!psize ~n:!n ~seq:!seq ~niter:!niter ~kind:!kind () diff --git a/benchs/pi.ml b/benchs/pi.ml index 1dd55fb9..36b4e92a 100644 --- a/benchs/pi.ml +++ b/benchs/pi.ml @@ -17,15 +17,23 @@ let run_sequential (num_steps : int) : float = pi (** Create a pool *) -let with_pool f = - if !j = 0 then - Pool.with_ ~per_domain:1 f - else - Pool.with_ ~min:!j f +let with_pool ~kind f = + match kind with + | "pool" -> + if !j = 0 then + Pool.with_ ~per_domain:1 f + else + Pool.with_ ~min:!j f + | "simple" -> + if !j = 0 then + Simple_pool.with_ ~per_domain:1 f + else + Simple_pool.with_ ~min:!j f + | _ -> assert false (** Run in parallel using {!Fut.for_} *) -let run_par1 (num_steps : int) : float = - let@ pool = with_pool () in +let run_par1 ~kind (num_steps : int) : float = + let@ pool = with_pool ~kind () in let num_tasks = Pool.size pool in @@ -53,8 +61,8 @@ let run_par1 (num_steps : int) : float = [@@@ifge 5.0] -let run_fork_join num_steps : float = - let@ pool = with_pool () in +let run_fork_join ~kind num_steps : float = + let@ pool = with_pool ~kind () in let num_tasks = Pool.size pool in @@ -90,9 +98,11 @@ type mode = | Fork_join let () = + let@ () = Trace_tef.with_setup () in let mode = ref Sequential in let n = ref 1000 in let time = ref false in + let kind = ref "pool" in let set_mode = function | "seq" -> mode := Sequential @@ -109,6 +119,9 @@ let () = " mode of execution" ); "-j", Arg.Set_int j, " number of threads"; "-t", Arg.Set time, " printing timing"; + ( "-kind", + Arg.Symbol ([ "pool"; "simple" ], ( := ) kind), + " pick pool implementation" ); ] |> Arg.align in @@ -118,8 +131,8 @@ let () = let res = match !mode with | Sequential -> run_sequential !n - | Par1 -> run_par1 !n - | Fork_join -> run_fork_join !n + | Par1 -> run_par1 ~kind:!kind !n + | Fork_join -> run_fork_join ~kind:!kind !n in let elapsed : float = Unix.gettimeofday () -. t_start in