mirror of
https://github.com/c-cube/moonpool.git
synced 2025-12-06 03:05:30 -05:00
use new tracing support in tests and benchs
This commit is contained in:
parent
092ad5f2ce
commit
dd9206b5b8
3 changed files with 21 additions and 5 deletions
|
|
@ -1,4 +1,7 @@
|
||||||
open Moonpool
|
open Moonpool
|
||||||
|
module Trace = Trace_core
|
||||||
|
|
||||||
|
let ( let@ ) = ( @@ )
|
||||||
|
|
||||||
let rec fib_direct x =
|
let rec fib_direct x =
|
||||||
if x <= 1 then
|
if x <= 1 then
|
||||||
|
|
@ -10,7 +13,7 @@ let cutoff = ref 20
|
||||||
|
|
||||||
let rec fib ~on x : int Fut.t =
|
let rec fib ~on x : int Fut.t =
|
||||||
if x <= !cutoff then
|
if x <= !cutoff then
|
||||||
Fut.spawn ~on (fun () -> fib_direct x)
|
Fut.spawn ~name:"fib" ~on (fun () -> fib_direct x)
|
||||||
else
|
else
|
||||||
let open Fut.Infix in
|
let open Fut.Infix in
|
||||||
let+ t1 = fib ~on (x - 1) and+ t2 = fib ~on (x - 2) in
|
let+ t1 = fib ~on (x - 1) and+ t2 = fib ~on (x - 2) in
|
||||||
|
|
@ -27,14 +30,14 @@ let fib_fj ~on x : int Fut.t =
|
||||||
n1 + n2
|
n1 + n2
|
||||||
)
|
)
|
||||||
in
|
in
|
||||||
Fut.spawn ~on (fun () -> fib_rec x)
|
Fut.spawn ~name:"fib" ~on (fun () -> fib_rec x)
|
||||||
|
|
||||||
let fib_await ~on x : int Fut.t =
|
let fib_await ~on x : int Fut.t =
|
||||||
let rec fib_rec x : int Fut.t =
|
let rec fib_rec x : int Fut.t =
|
||||||
if x <= !cutoff then
|
if x <= !cutoff then
|
||||||
Fut.spawn ~on (fun () -> fib_direct x)
|
Fut.spawn ~name:"fib" ~on (fun () -> fib_direct x)
|
||||||
else
|
else
|
||||||
Fut.spawn ~on (fun () ->
|
Fut.spawn ~name:"fib" ~on (fun () ->
|
||||||
let n1 = fib_rec (x - 1) in
|
let n1 = fib_rec (x - 1) in
|
||||||
let n2 = fib_rec (x - 2) in
|
let n2 = fib_rec (x - 2) in
|
||||||
let n1 = Fut.await n1 in
|
let n1 = Fut.await n1 in
|
||||||
|
|
@ -66,6 +69,7 @@ let str_of_int_opt = function
|
||||||
| Some i -> Printf.sprintf "Some %d" i
|
| Some i -> Printf.sprintf "Some %d" i
|
||||||
|
|
||||||
let run ~psize ~n ~seq ~dl ~fj ~await ~niter ~kind () : unit =
|
let run ~psize ~n ~seq ~dl ~fj ~await ~niter ~kind () : unit =
|
||||||
|
let@ _sp = Trace.with_span ~__FILE__ ~__LINE__ "fib.run" in
|
||||||
let pool = lazy (create_pool ~kind ~psize ()) in
|
let pool = lazy (create_pool ~kind ~psize ()) in
|
||||||
let dl_pool =
|
let dl_pool =
|
||||||
lazy
|
lazy
|
||||||
|
|
@ -108,6 +112,7 @@ let run ~psize ~n ~seq ~dl ~fj ~await ~niter ~kind () : unit =
|
||||||
Ws_pool.shutdown (Lazy.force pool)
|
Ws_pool.shutdown (Lazy.force pool)
|
||||||
|
|
||||||
let () =
|
let () =
|
||||||
|
let@ () = Trace_tef.with_setup () in
|
||||||
let n = ref 40 in
|
let n = ref 40 in
|
||||||
let psize = ref None in
|
let psize = ref None in
|
||||||
let seq = ref false in
|
let seq = ref false in
|
||||||
|
|
|
||||||
11
benchs/pi.ml
11
benchs/pi.ml
|
|
@ -7,6 +7,7 @@ let j = ref 0
|
||||||
let spf = Printf.sprintf
|
let spf = Printf.sprintf
|
||||||
|
|
||||||
let run_sequential (num_steps : int) : float =
|
let run_sequential (num_steps : int) : float =
|
||||||
|
let@ _sp = Trace.with_span ~__FILE__ ~__LINE__ "pi.seq" in
|
||||||
let step = 1. /. float num_steps in
|
let step = 1. /. float num_steps in
|
||||||
let sum = ref 0. in
|
let sum = ref 0. in
|
||||||
for i = 0 to num_steps - 1 do
|
for i = 0 to num_steps - 1 do
|
||||||
|
|
@ -42,6 +43,11 @@ let run_par1 ~kind (num_steps : int) : float =
|
||||||
|
|
||||||
(* one chunk of the work *)
|
(* one chunk of the work *)
|
||||||
let run_task _idx_task : unit =
|
let run_task _idx_task : unit =
|
||||||
|
let@ _sp =
|
||||||
|
Trace.with_span ~__FILE__ ~__LINE__ "pi.slice" ~data:(fun () ->
|
||||||
|
[ "i", `Int _idx_task ])
|
||||||
|
in
|
||||||
|
|
||||||
let sum = ref 0. in
|
let sum = ref 0. in
|
||||||
let i = ref 0 in
|
let i = ref 0 in
|
||||||
while !i < num_steps do
|
while !i < num_steps do
|
||||||
|
|
@ -69,7 +75,7 @@ let run_fork_join ~kind num_steps : float =
|
||||||
let step = 1. /. float num_steps in
|
let step = 1. /. float num_steps in
|
||||||
let global_sum = Lock.create 0. in
|
let global_sum = Lock.create 0. in
|
||||||
|
|
||||||
Ws_pool.run_wait_block pool (fun () ->
|
Ws_pool.run_wait_block ~name:"pi.fj" pool (fun () ->
|
||||||
Fork_join.for_
|
Fork_join.for_
|
||||||
~chunk_size:(3 + (num_steps / num_tasks))
|
~chunk_size:(3 + (num_steps / num_tasks))
|
||||||
num_steps
|
num_steps
|
||||||
|
|
@ -99,6 +105,9 @@ type mode =
|
||||||
|
|
||||||
let () =
|
let () =
|
||||||
let@ () = Trace_tef.with_setup () in
|
let@ () = Trace_tef.with_setup () in
|
||||||
|
Trace.set_thread_name "main";
|
||||||
|
let@ _sp = Trace.with_span ~__FILE__ ~__LINE__ "main" in
|
||||||
|
|
||||||
let mode = ref Sequential in
|
let mode = ref Sequential in
|
||||||
let n = ref 1000 in
|
let n = ref 1000 in
|
||||||
let time = ref false in
|
let time = ref false in
|
||||||
|
|
|
||||||
|
|
@ -33,10 +33,12 @@ let run ~min () =
|
||||||
let l1, l2 =
|
let l1, l2 =
|
||||||
Fork_join.both
|
Fork_join.both
|
||||||
(fun () ->
|
(fun () ->
|
||||||
|
let@ _sp = Trace.with_span ~__FILE__ ~__LINE__ "fj.left" in
|
||||||
Fork_join.map_list ~chunk_size
|
Fork_join.map_list ~chunk_size
|
||||||
(Fork_join.map_list ~chunk_size neg)
|
(Fork_join.map_list ~chunk_size neg)
|
||||||
l)
|
l)
|
||||||
(fun () ->
|
(fun () ->
|
||||||
|
let@ _sp = Trace.with_span ~__FILE__ ~__LINE__ "fj.right" in
|
||||||
Fork_join.map_list ~chunk_size
|
Fork_join.map_list ~chunk_size
|
||||||
(Fork_join.map_list ~chunk_size neg)
|
(Fork_join.map_list ~chunk_size neg)
|
||||||
ref_l1)
|
ref_l1)
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue