Skip to content

Commit 0921912

Browse files
committed
Benchmark parallel CMP using various number of domains
1 parent 68b9c89 commit 0921912

File tree

1 file changed

+47
-41
lines changed

1 file changed

+47
-41
lines changed

bench/bench_parallel_cmp.ml

Lines changed: 47 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,66 @@
11
open Kcas
22
open Bench
33

4-
let run_one ?(factor = 1) ?(n_iter = 10 * factor * Util.iter_factor) () =
4+
let run_one ~n_domains ?(factor = 1) ?(n_ops = 50 * factor * Util.iter_factor)
5+
() =
6+
let n_ops = n_ops * n_domains in
7+
58
let a = Loc.make ~padded:true 10 in
69
let b = Loc.make ~padded:true 52 in
10+
let xs = Loc.make_array ~padded:true n_domains 0 in
11+
12+
let n_ops_todo = Atomic.make n_ops |> Multicore_magic.copy_as_padded in
13+
14+
let init i = Array.unsafe_get xs i in
715

8-
let init _ = Loc.make ~padded:true 0 in
9-
let work i x =
10-
if i land 1 = 0 then begin
11-
let tx1 ~xt =
12-
let a = Xt.get ~xt a in
13-
let b = Xt.get ~xt b in
14-
Xt.set ~xt x (b - a)
15-
and tx2 ~xt =
16-
let a = Xt.get ~xt a in
17-
let b = Xt.get ~xt b in
18-
Xt.set ~xt x (a + b)
19-
in
20-
let tx1 = { Xt.tx = tx1 } and tx2 = { Xt.tx = tx2 } in
21-
for _ = 1 to n_iter asr 1 do
22-
Xt.commit tx1;
23-
Xt.commit tx2
24-
done
25-
end
26-
else begin
27-
let tx1 ~xt =
28-
let a = Xt.get ~xt a in
29-
let b = Xt.get ~xt b in
30-
Xt.set ~xt x (b - a)
31-
and tx2 ~xt =
32-
let a = Xt.get ~xt a in
33-
let b = Xt.get ~xt b in
34-
Xt.set ~xt x (a + b)
35-
in
36-
let tx1 = { Xt.tx = tx1 } and tx2 = { Xt.tx = tx2 } in
37-
for _ = 1 to n_iter asr 1 do
38-
Xt.commit tx1;
39-
Xt.commit tx2
40-
done
41-
end
16+
let work _ x =
17+
let tx1 ~xt =
18+
let a = Xt.get ~xt a in
19+
let b = Xt.get ~xt b in
20+
Xt.set ~xt x (b - a)
21+
and tx2 ~xt =
22+
let a = Xt.get ~xt a in
23+
let b = Xt.get ~xt b in
24+
Xt.set ~xt x (a + b)
25+
in
26+
let rec work () =
27+
let n = Util.alloc n_ops_todo in
28+
if n <> 0 then begin
29+
for _ = 1 to n asr 1 do
30+
Xt.commit { tx = tx1 };
31+
Xt.commit { tx = tx2 }
32+
done;
33+
work ()
34+
end
35+
in
36+
work ()
4237
in
4338

44-
let times = Times.record ~n_domains:2 ~init ~work () in
39+
let after () = Atomic.set n_ops_todo n_ops in
40+
41+
let times = Times.record ~n_domains ~init ~work ~after () in
42+
43+
let name metric =
44+
Printf.sprintf "%s/%d worker%s" metric n_domains
45+
(if n_domains = 1 then "" else "s")
46+
in
4547

4648
List.concat
4749
[
4850
Stats.of_times times
49-
|> Stats.scale (1_000_000_000.0 /. Float.of_int n_iter)
50-
|> Stats.to_json ~name:"time per transaction"
51+
|> Stats.scale (1_000_000_000.0 /. Float.of_int n_ops)
52+
|> Stats.to_json
53+
~name:(name "time per transaction")
5154
~description:"Time to perform a single transaction" ~units:"ns";
5255
Times.invert times |> Stats.of_times
53-
|> Stats.scale (Float.of_int (n_iter * 2) /. 1_000_000.0)
54-
|> Stats.to_json ~name:"transactions over time"
56+
|> Stats.scale (Float.of_int (n_ops * n_domains) /. 1_000_000.0)
57+
|> Stats.to_json
58+
~name:(name "transactions over time")
5559
~description:
5660
"Number of transactions performed over time using 2 domains"
5761
~units:"M/s";
5862
]
5963

60-
let run_suite ~factor = run_one ~factor ()
64+
let run_suite ~factor =
65+
[ 1; 2; 4 ]
66+
|> List.concat_map @@ fun n_domains -> run_one ~n_domains ~factor ()

0 commit comments

Comments
 (0)