From 92eb41b593356028c9135944847a8e96e4fac5f8 Mon Sep 17 00:00:00 2001 From: Anmol Sahoo Date: Tue, 6 Oct 2020 17:31:59 +0530 Subject: [PATCH 1/8] added lockfree map --- benchmarks/multicore-lockfree/ctrie-dune.inc | 16 +++ benchmarks/multicore-lockfree/ctrie.ml | 117 ++++++++++++++++++ benchmarks/multicore-lockfree/dune | 3 +- benchmarks/multicore-lockfree/test_ctrie.ml | 25 ++++ .../test_ctrie_sequential.ml | 25 ++++ multicore_parallel_run_config.json | 22 ++++ 6 files changed, 207 insertions(+), 1 deletion(-) create mode 100644 benchmarks/multicore-lockfree/ctrie-dune.inc create mode 100644 benchmarks/multicore-lockfree/ctrie.ml create mode 100644 benchmarks/multicore-lockfree/test_ctrie.ml create mode 100644 benchmarks/multicore-lockfree/test_ctrie_sequential.ml diff --git a/benchmarks/multicore-lockfree/ctrie-dune.inc b/benchmarks/multicore-lockfree/ctrie-dune.inc new file mode 100644 index 0000000000..27154ba622 --- /dev/null +++ b/benchmarks/multicore-lockfree/ctrie-dune.inc @@ -0,0 +1,16 @@ +(library + (name ctrie) + (modules ctrie) + (libraries base)) + +(executable + (name test_ctrie) + (modules test_ctrie) + (libraries ctrie)) + +(executable + (name test_ctrie_sequential) + (modules test_ctrie_sequential) + (libraries ctrie)) + +(alias (name multibench_parallel) (deps test_ctrie.exe test_ctrie_sequential.exe)) diff --git a/benchmarks/multicore-lockfree/ctrie.ml b/benchmarks/multicore-lockfree/ctrie.ml new file mode 100644 index 0000000000..e4123429f3 --- /dev/null +++ b/benchmarks/multicore-lockfree/ctrie.ml @@ -0,0 +1,117 @@ +(* Concurrent, hash array mapped trie based on - + Prokopec, A. et al. (2011) + Cache-Aware Lock-Free Concurrent Hash Tries. Technical Report, 2011. *) + +(* configuration parameters *) +let shift = 5 + +(* data definition *) +type node = + | Empty + | Cnode of { map : int ; nodes : (node Atomic.t) array } + | Inode of { key : int ; values : int list ; delete : bool } + +type t = node Atomic.t + +(* helper functions *) + +(* detect flag of key in map *) +let flag k l _map = + let i = + (k lsr (l * shift)) + land + ((1 lsl shift) - 1) in + i + +(* check if flag is set *) +let set i map = + ((1 lsl i) land map) <> 0 + +(* detect position in array *) +let pos flag map = + (Base.Int.popcount (((1 lsl flag) - 1) land map)) + +(* create empty map *) +let empty () = Atomic.make Empty + +(* insert key and value binding into map *) +let rec insert_aux k v l t = + match Atomic.get t with + | Empty -> + let i = flag k l 0 in + let map = 1 lsl i in + let nodes = [| + (Atomic.make (Inode {key = k ; values = [v] ; delete = false})) + |] in + let new_node = Cnode { map ; nodes } in + Atomic.compare_and_set t Empty new_node + | Cnode { map ; nodes } as c -> + let i = flag k l map in + if (set i map) then begin + let p = pos i map in + insert_aux k v (l+1) nodes.(p) + end else begin + let map = (1 lsl i) lor (map) in + let p = pos i map in + let old_len = Array.length nodes in + let new_nodes = Array.init (old_len + 1) (fun i -> + if i < p then nodes.(i) else + if i = p then + Atomic.make (Inode {key = k; values = [v] ; delete = false}) + else + nodes.(i-1)) in + let new_node = Cnode { map ; nodes = new_nodes } in + Atomic.compare_and_set t c new_node + end + | Inode { key ; values ; delete} as inode -> + if key = k then begin + let new_values = v :: values in + let new_node = Inode { key ; values = new_values ; delete } in + Atomic.compare_and_set t inode new_node + end else begin + let i = flag key l 0 in + let ni = flag k l 0 in + let map = (1 lsl i) lor 0 in + let map = (1 lsl ni) lor map in + let nodes = + if (ni > i) then + ([| + Atomic.make (Inode { key ; values ; delete }) ; + Atomic.make (Inode { key = k ; values = [v] ; delete = false }) + |], true) + else if (ni < i) then + ([| + Atomic.make (Inode { key = k ; values = [v] ; delete = false }) ; + Atomic.make (Inode { key ; values ; delete }) + |], true) + else begin + let i = flag key (l+1) 0 in + let nmap = (1 lsl i) lor 0 in + let nnodes = [|Atomic.make (Inode {key ; values; delete})|] in + ([| + Atomic.make (Cnode { map = nmap ; nodes = nnodes }) + |], false) + end in + let (nodes, new_level) = nodes in + let new_node = Cnode { map ; nodes } in + Atomic.compare_and_set t inode new_node && new_level + end + +let rec insert k v t = + if insert_aux k v 0 t then () else insert k v t + +(* check if key in map *) +let rec mem k l t = + match Atomic.get t with + | Empty -> false + | Cnode { map ; nodes } -> + let f = flag k l map in + if (set f map) then begin + let p = pos f map in + mem k (l+1) nodes.(p) + end else begin + false + end + | Inode { key ; _ } -> if key = k then true else false + +let mem k t = mem k 0 t diff --git a/benchmarks/multicore-lockfree/dune b/benchmarks/multicore-lockfree/dune index 6a22c97dff..3921a731ac 100644 --- a/benchmarks/multicore-lockfree/dune +++ b/benchmarks/multicore-lockfree/dune @@ -2,4 +2,5 @@ (include wsqueue-dune.inc) (include bag-dune.inc) (include msqueue-dune.inc) -(include list-dune.inc) \ No newline at end of file +(include list-dune.inc) +(include ctrie-dune.inc) diff --git a/benchmarks/multicore-lockfree/test_ctrie.ml b/benchmarks/multicore-lockfree/test_ctrie.ml new file mode 100644 index 0000000000..88a221e803 --- /dev/null +++ b/benchmarks/multicore-lockfree/test_ctrie.ml @@ -0,0 +1,25 @@ +let threads = int_of_string Sys.argv.(1) +let insert_percent = int_of_string Sys.argv.(2) +let num_opers = int_of_string Sys.argv.(3) + +let () = Random.init 42 + +let tree = Ctrie.empty () + +let work () = + for _ = 1 to num_opers do + if Random.int 100 > insert_percent then + ignore (Ctrie.mem (Random.int 1000000) tree) + else + Ctrie.insert (Random.int 1000000) 0 tree + done + +let () = + let rec spawn_thread n = + match n with + | 0 -> [] + | _ -> (Domain.spawn work) :: spawn_thread (n-1) + in + let threads = spawn_thread (threads - 1) in + ignore (work ()); + ignore (List.map (fun d -> Domain.join d) threads) diff --git a/benchmarks/multicore-lockfree/test_ctrie_sequential.ml b/benchmarks/multicore-lockfree/test_ctrie_sequential.ml new file mode 100644 index 0000000000..b9da64adb1 --- /dev/null +++ b/benchmarks/multicore-lockfree/test_ctrie_sequential.ml @@ -0,0 +1,25 @@ +let threads = 1 +let insert_percent = int_of_string Sys.argv.(1) +let num_opers = int_of_string Sys.argv.(2) + +let () = Random.init 42 + +let tree = Ctrie.empty () + +let work () = + for _ = 1 to num_opers do + if Random.int 100 > insert_percent then + ignore (Ctrie.mem (Random.int 1000000) tree) + else + Ctrie.insert (Random.int 1000000) 0 tree + done + +let () = + let rec spawn_thread n = + match n with + | 0 -> [] + | _ -> (Domain.spawn work) :: spawn_thread (n-1) + in + let threads = spawn_thread (threads - 1) in + ignore (work ()); + ignore (List.map (fun d -> Domain.join d) threads) diff --git a/multicore_parallel_run_config.json b/multicore_parallel_run_config.json index ea514e617c..d1ec03bf7f 100644 --- a/multicore_parallel_run_config.json +++ b/multicore_parallel_run_config.json @@ -679,6 +679,28 @@ } ] }, + { + "executable": "benchmarks/multicore-lockfree/test_ctrie_sequential.exe", + "name": "lockfree-map", + "ismacrobench": false, + "runs": [ + { "params": "80 1000000", "paramwrapper": "taskset --cpu-list 2-13 chrt -r 1"} + ] + }, + { + "executable": "benchmarks/multicore-lockfree/test_ctrie.exe", + "name": "lockfree-map_multicore", + "ismacrobench": false, + "runs": [ + { "params": "2 80 1000000", "paramwrapper": "taskset --cpu-list 2-13 chrt -r 1"}, + { "params": "4 80 1000000", "paramwrapper": "taskset --cpu-list 2-13 chrt -r 1" }, + { "params": "8 80 1000000", "paramwrapper": "taskset --cpu-list 2-13 chrt -r 1" }, + { "params": "12 80 1000000", "paramwrapper": "taskset --cpu-list 2-13 chrt -r 1" }, + { "params": "16 80 1000000", "paramwrapper": "taskset --cpu-list 2-13,16-27 chrt -r 1" }, + { "params": "20 80 1000000", "paramwrapper": "taskset --cpu-list 2-13,16-27 chrt -r 1" }, + { "params": "24 80 1000000", "paramwrapper": "taskset --cpu-list 2-13,16-27 chrt -r 1" } + ] + }, { "executable": "benchmarks/simple-tests/alloc_multicore.exe", "name": "alloc_multicore", From 1f3f0cdb06b99d1883bb9752a1687943090fa676 Mon Sep 17 00:00:00 2001 From: Anmol Sahoo Date: Tue, 6 Oct 2020 18:31:50 +0530 Subject: [PATCH 2/8] split up operations per thread --- benchmarks/multicore-lockfree/test_ctrie.ml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/benchmarks/multicore-lockfree/test_ctrie.ml b/benchmarks/multicore-lockfree/test_ctrie.ml index 88a221e803..568a9440e8 100644 --- a/benchmarks/multicore-lockfree/test_ctrie.ml +++ b/benchmarks/multicore-lockfree/test_ctrie.ml @@ -1,6 +1,6 @@ let threads = int_of_string Sys.argv.(1) let insert_percent = int_of_string Sys.argv.(2) -let num_opers = int_of_string Sys.argv.(3) +let num_opers = int_of_string Sys.argv.(3) / threads let () = Random.init 42 From 34a776af501138647feeba557549ca5cbd91d61b Mon Sep 17 00:00:00 2001 From: Anmol Sahoo Date: Tue, 6 Oct 2020 23:01:49 +0530 Subject: [PATCH 3/8] added DLS --- benchmarks/multicore-lockfree/test_ctrie.ml | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/benchmarks/multicore-lockfree/test_ctrie.ml b/benchmarks/multicore-lockfree/test_ctrie.ml index 568a9440e8..cc925e0fc9 100644 --- a/benchmarks/multicore-lockfree/test_ctrie.ml +++ b/benchmarks/multicore-lockfree/test_ctrie.ml @@ -2,16 +2,18 @@ let threads = int_of_string Sys.argv.(1) let insert_percent = int_of_string Sys.argv.(2) let num_opers = int_of_string Sys.argv.(3) / threads -let () = Random.init 42 +let state_key = Domain.DLS.new_key Random.State.make_self_init let tree = Ctrie.empty () let work () = + let state = Domain.DLS.get state_key in + let rand_int n = Random.State.int state n in for _ = 1 to num_opers do - if Random.int 100 > insert_percent then - ignore (Ctrie.mem (Random.int 1000000) tree) + if rand_int 100 > insert_percent then + ignore (Ctrie.mem (rand_int 1000000) tree) else - Ctrie.insert (Random.int 1000000) 0 tree + Ctrie.insert (rand_int 1000000) 0 tree done let () = From 791979187be1f2ad1b10ac8e5adcfd59a8ff9251 Mon Sep 17 00:00:00 2001 From: Anmol Sahoo Date: Sat, 22 May 2021 17:59:17 -0400 Subject: [PATCH 4/8] updated multicore lockfree --- benchmarks/multicore-lockfree/ctrie-dune.inc | 16 -- benchmarks/multicore-lockfree/ctrie.ml | 117 -------------- .../multicore-lockfree/ctrie_parallel.ml | 148 ++++++++++++++++++ .../multicore-lockfree/ctrie_sequential.ml | 148 ++++++++++++++++++ benchmarks/multicore-lockfree/dune | 45 +++++- .../{test_hash.ml => hash_parallel.ml} | 0 .../multicore-lockfree/hash_sequential.ml | 25 +++ benchmarks/multicore-lockfree/test_ctrie.ml | 27 ---- .../test_ctrie_sequential.ml | 25 --- .../{test_wsqueue.ml => wsqueue_parallel.ml} | 0 .../multicore-lockfree/wsqueue_sequential.ml | 36 +++++ multicore_parallel_run_config.json | 49 ++++-- 12 files changed, 432 insertions(+), 204 deletions(-) delete mode 100644 benchmarks/multicore-lockfree/ctrie-dune.inc delete mode 100644 benchmarks/multicore-lockfree/ctrie.ml create mode 100644 benchmarks/multicore-lockfree/ctrie_parallel.ml create mode 100644 benchmarks/multicore-lockfree/ctrie_sequential.ml rename benchmarks/multicore-lockfree/{test_hash.ml => hash_parallel.ml} (100%) create mode 100644 benchmarks/multicore-lockfree/hash_sequential.ml delete mode 100644 benchmarks/multicore-lockfree/test_ctrie.ml delete mode 100644 benchmarks/multicore-lockfree/test_ctrie_sequential.ml rename benchmarks/multicore-lockfree/{test_wsqueue.ml => wsqueue_parallel.ml} (100%) create mode 100644 benchmarks/multicore-lockfree/wsqueue_sequential.ml diff --git a/benchmarks/multicore-lockfree/ctrie-dune.inc b/benchmarks/multicore-lockfree/ctrie-dune.inc deleted file mode 100644 index 27154ba622..0000000000 --- a/benchmarks/multicore-lockfree/ctrie-dune.inc +++ /dev/null @@ -1,16 +0,0 @@ -(library - (name ctrie) - (modules ctrie) - (libraries base)) - -(executable - (name test_ctrie) - (modules test_ctrie) - (libraries ctrie)) - -(executable - (name test_ctrie_sequential) - (modules test_ctrie_sequential) - (libraries ctrie)) - -(alias (name multibench_parallel) (deps test_ctrie.exe test_ctrie_sequential.exe)) diff --git a/benchmarks/multicore-lockfree/ctrie.ml b/benchmarks/multicore-lockfree/ctrie.ml deleted file mode 100644 index e4123429f3..0000000000 --- a/benchmarks/multicore-lockfree/ctrie.ml +++ /dev/null @@ -1,117 +0,0 @@ -(* Concurrent, hash array mapped trie based on - - Prokopec, A. et al. (2011) - Cache-Aware Lock-Free Concurrent Hash Tries. Technical Report, 2011. *) - -(* configuration parameters *) -let shift = 5 - -(* data definition *) -type node = - | Empty - | Cnode of { map : int ; nodes : (node Atomic.t) array } - | Inode of { key : int ; values : int list ; delete : bool } - -type t = node Atomic.t - -(* helper functions *) - -(* detect flag of key in map *) -let flag k l _map = - let i = - (k lsr (l * shift)) - land - ((1 lsl shift) - 1) in - i - -(* check if flag is set *) -let set i map = - ((1 lsl i) land map) <> 0 - -(* detect position in array *) -let pos flag map = - (Base.Int.popcount (((1 lsl flag) - 1) land map)) - -(* create empty map *) -let empty () = Atomic.make Empty - -(* insert key and value binding into map *) -let rec insert_aux k v l t = - match Atomic.get t with - | Empty -> - let i = flag k l 0 in - let map = 1 lsl i in - let nodes = [| - (Atomic.make (Inode {key = k ; values = [v] ; delete = false})) - |] in - let new_node = Cnode { map ; nodes } in - Atomic.compare_and_set t Empty new_node - | Cnode { map ; nodes } as c -> - let i = flag k l map in - if (set i map) then begin - let p = pos i map in - insert_aux k v (l+1) nodes.(p) - end else begin - let map = (1 lsl i) lor (map) in - let p = pos i map in - let old_len = Array.length nodes in - let new_nodes = Array.init (old_len + 1) (fun i -> - if i < p then nodes.(i) else - if i = p then - Atomic.make (Inode {key = k; values = [v] ; delete = false}) - else - nodes.(i-1)) in - let new_node = Cnode { map ; nodes = new_nodes } in - Atomic.compare_and_set t c new_node - end - | Inode { key ; values ; delete} as inode -> - if key = k then begin - let new_values = v :: values in - let new_node = Inode { key ; values = new_values ; delete } in - Atomic.compare_and_set t inode new_node - end else begin - let i = flag key l 0 in - let ni = flag k l 0 in - let map = (1 lsl i) lor 0 in - let map = (1 lsl ni) lor map in - let nodes = - if (ni > i) then - ([| - Atomic.make (Inode { key ; values ; delete }) ; - Atomic.make (Inode { key = k ; values = [v] ; delete = false }) - |], true) - else if (ni < i) then - ([| - Atomic.make (Inode { key = k ; values = [v] ; delete = false }) ; - Atomic.make (Inode { key ; values ; delete }) - |], true) - else begin - let i = flag key (l+1) 0 in - let nmap = (1 lsl i) lor 0 in - let nnodes = [|Atomic.make (Inode {key ; values; delete})|] in - ([| - Atomic.make (Cnode { map = nmap ; nodes = nnodes }) - |], false) - end in - let (nodes, new_level) = nodes in - let new_node = Cnode { map ; nodes } in - Atomic.compare_and_set t inode new_node && new_level - end - -let rec insert k v t = - if insert_aux k v 0 t then () else insert k v t - -(* check if key in map *) -let rec mem k l t = - match Atomic.get t with - | Empty -> false - | Cnode { map ; nodes } -> - let f = flag k l map in - if (set f map) then begin - let p = pos f map in - mem k (l+1) nodes.(p) - end else begin - false - end - | Inode { key ; _ } -> if key = k then true else false - -let mem k t = mem k 0 t diff --git a/benchmarks/multicore-lockfree/ctrie_parallel.ml b/benchmarks/multicore-lockfree/ctrie_parallel.ml new file mode 100644 index 0000000000..7d2ee4da99 --- /dev/null +++ b/benchmarks/multicore-lockfree/ctrie_parallel.ml @@ -0,0 +1,148 @@ +module Ctrie = struct + (* Concurrent, hash array mapped trie based on - + Prokopec, A. et al. (2011) + Cache-Aware Lock-Free Concurrent Hash Tries. Technical Report, 2011. *) + + (* configuration parameters *) + let shift = 5 + + (* data definition *) + type node = + | Empty + | Cnode of { map : int ; nodes : (node Atomic.t) array } + | Inode of { key : int ; values : int list ; delete : bool } + + type t = node Atomic.t + + (* helper functions *) + + (* detect flag of key in map *) + let flag k l _map = + let i = + (k lsr (l * shift)) + land + ((1 lsl shift) - 1) in + i + + (* check if flag is set *) + let set i map = + ((1 lsl i) land map) <> 0 + + (* detect position in array *) + let pos flag map = + (Base.Int.popcount (((1 lsl flag) - 1) land map)) + + (* create empty map *) + let empty () = Atomic.make Empty + + (* insert key and value binding into map *) + let rec insert_aux k v l t = + match Atomic.get t with + | Empty -> + let i = flag k l 0 in + let map = 1 lsl i in + let nodes = [| + (Atomic.make (Inode {key = k ; values = [v] ; delete = false})) + |] in + let new_node = Cnode { map ; nodes } in + Atomic.compare_and_set t Empty new_node + | Cnode { map ; nodes } as c -> + let i = flag k l map in + if (set i map) then begin + let p = pos i map in + insert_aux k v (l+1) nodes.(p) + end else begin + let map = (1 lsl i) lor (map) in + let p = pos i map in + let old_len = Array.length nodes in + let new_nodes = Array.init (old_len + 1) (fun i -> + if i < p then nodes.(i) else + if i = p then + Atomic.make (Inode {key = k; values = [v] ; delete = false}) + else + nodes.(i-1)) in + let new_node = Cnode { map ; nodes = new_nodes } in + Atomic.compare_and_set t c new_node + end + | Inode { key ; values ; delete} as inode -> + if key = k then begin + let new_values = v :: values in + let new_node = Inode { key ; values = new_values ; delete } in + Atomic.compare_and_set t inode new_node + end else begin + let i = flag key l 0 in + let ni = flag k l 0 in + let map = (1 lsl i) lor 0 in + let map = (1 lsl ni) lor map in + let nodes = + if (ni > i) then + ([| + Atomic.make (Inode { key ; values ; delete }) ; + Atomic.make (Inode { key = k ; values = [v] ; delete = false }) + |], true) + else if (ni < i) then + ([| + Atomic.make (Inode { key = k ; values = [v] ; delete = false }) ; + Atomic.make (Inode { key ; values ; delete }) + |], true) + else begin + let i = flag key (l+1) 0 in + let nmap = (1 lsl i) lor 0 in + let nnodes = [|Atomic.make (Inode {key ; values; delete})|] in + ([| + Atomic.make (Cnode { map = nmap ; nodes = nnodes }) + |], false) + end in + let (nodes, new_level) = nodes in + let new_node = Cnode { map ; nodes } in + Atomic.compare_and_set t inode new_node && new_level + end + + let rec insert k v t = + if insert_aux k v 0 t then () else insert k v t + + (* check if key in map *) + let rec mem k l t = + match Atomic.get t with + | Empty -> false + | Cnode { map ; nodes } -> + let f = flag k l map in + if (set f map) then begin + let p = pos f map in + mem k (l+1) nodes.(p) + end else begin + false + end + | Inode { key ; _ } -> if key = k then true else false + + let mem k t = mem k 0 t +end + +module T = Domainslib.Task + +let num_domains = try int_of_string Sys.argv.(1) with _ -> 4 +let num_elems = try int_of_string Sys.argv.(2) with _ -> 1000000 +let ins_ratio = try float_of_string Sys.argv.(3) with _ -> 0.5 + +let state_key = Domain.DLS.new_key Random.State.make_self_init in + +let rand_int () = + let state = Domain.DLS.get state_key in + Random.State.int state 10000 + +let rand_float () = + let state = Domain.DLS.get state_key in + Random.State.float state 1.0 + +let work tree int = + if rand_float () > ins_ratio then + ignore (Ctrie.mem (rand_int ()) tree) + else + ignore (Ctrie.insert (rand_int ()) 0 tree) + +let _ = + let pool = T.setup_pool num_domains in + let tree = Ctrie.empty () in + let work = work tree in + T.parallel_for ~start:0 ~finish:(num_elems - 1) ~body:work pool; + T.teardown_pool pool diff --git a/benchmarks/multicore-lockfree/ctrie_sequential.ml b/benchmarks/multicore-lockfree/ctrie_sequential.ml new file mode 100644 index 0000000000..7d2ee4da99 --- /dev/null +++ b/benchmarks/multicore-lockfree/ctrie_sequential.ml @@ -0,0 +1,148 @@ +module Ctrie = struct + (* Concurrent, hash array mapped trie based on - + Prokopec, A. et al. (2011) + Cache-Aware Lock-Free Concurrent Hash Tries. Technical Report, 2011. *) + + (* configuration parameters *) + let shift = 5 + + (* data definition *) + type node = + | Empty + | Cnode of { map : int ; nodes : (node Atomic.t) array } + | Inode of { key : int ; values : int list ; delete : bool } + + type t = node Atomic.t + + (* helper functions *) + + (* detect flag of key in map *) + let flag k l _map = + let i = + (k lsr (l * shift)) + land + ((1 lsl shift) - 1) in + i + + (* check if flag is set *) + let set i map = + ((1 lsl i) land map) <> 0 + + (* detect position in array *) + let pos flag map = + (Base.Int.popcount (((1 lsl flag) - 1) land map)) + + (* create empty map *) + let empty () = Atomic.make Empty + + (* insert key and value binding into map *) + let rec insert_aux k v l t = + match Atomic.get t with + | Empty -> + let i = flag k l 0 in + let map = 1 lsl i in + let nodes = [| + (Atomic.make (Inode {key = k ; values = [v] ; delete = false})) + |] in + let new_node = Cnode { map ; nodes } in + Atomic.compare_and_set t Empty new_node + | Cnode { map ; nodes } as c -> + let i = flag k l map in + if (set i map) then begin + let p = pos i map in + insert_aux k v (l+1) nodes.(p) + end else begin + let map = (1 lsl i) lor (map) in + let p = pos i map in + let old_len = Array.length nodes in + let new_nodes = Array.init (old_len + 1) (fun i -> + if i < p then nodes.(i) else + if i = p then + Atomic.make (Inode {key = k; values = [v] ; delete = false}) + else + nodes.(i-1)) in + let new_node = Cnode { map ; nodes = new_nodes } in + Atomic.compare_and_set t c new_node + end + | Inode { key ; values ; delete} as inode -> + if key = k then begin + let new_values = v :: values in + let new_node = Inode { key ; values = new_values ; delete } in + Atomic.compare_and_set t inode new_node + end else begin + let i = flag key l 0 in + let ni = flag k l 0 in + let map = (1 lsl i) lor 0 in + let map = (1 lsl ni) lor map in + let nodes = + if (ni > i) then + ([| + Atomic.make (Inode { key ; values ; delete }) ; + Atomic.make (Inode { key = k ; values = [v] ; delete = false }) + |], true) + else if (ni < i) then + ([| + Atomic.make (Inode { key = k ; values = [v] ; delete = false }) ; + Atomic.make (Inode { key ; values ; delete }) + |], true) + else begin + let i = flag key (l+1) 0 in + let nmap = (1 lsl i) lor 0 in + let nnodes = [|Atomic.make (Inode {key ; values; delete})|] in + ([| + Atomic.make (Cnode { map = nmap ; nodes = nnodes }) + |], false) + end in + let (nodes, new_level) = nodes in + let new_node = Cnode { map ; nodes } in + Atomic.compare_and_set t inode new_node && new_level + end + + let rec insert k v t = + if insert_aux k v 0 t then () else insert k v t + + (* check if key in map *) + let rec mem k l t = + match Atomic.get t with + | Empty -> false + | Cnode { map ; nodes } -> + let f = flag k l map in + if (set f map) then begin + let p = pos f map in + mem k (l+1) nodes.(p) + end else begin + false + end + | Inode { key ; _ } -> if key = k then true else false + + let mem k t = mem k 0 t +end + +module T = Domainslib.Task + +let num_domains = try int_of_string Sys.argv.(1) with _ -> 4 +let num_elems = try int_of_string Sys.argv.(2) with _ -> 1000000 +let ins_ratio = try float_of_string Sys.argv.(3) with _ -> 0.5 + +let state_key = Domain.DLS.new_key Random.State.make_self_init in + +let rand_int () = + let state = Domain.DLS.get state_key in + Random.State.int state 10000 + +let rand_float () = + let state = Domain.DLS.get state_key in + Random.State.float state 1.0 + +let work tree int = + if rand_float () > ins_ratio then + ignore (Ctrie.mem (rand_int ()) tree) + else + ignore (Ctrie.insert (rand_int ()) 0 tree) + +let _ = + let pool = T.setup_pool num_domains in + let tree = Ctrie.empty () in + let work = work tree in + T.parallel_for ~start:0 ~finish:(num_elems - 1) ~body:work pool; + T.teardown_pool pool diff --git a/benchmarks/multicore-lockfree/dune b/benchmarks/multicore-lockfree/dune index 3921a731ac..e290ed930d 100644 --- a/benchmarks/multicore-lockfree/dune +++ b/benchmarks/multicore-lockfree/dune @@ -1,6 +1,39 @@ -(include hash-dune.inc) -(include wsqueue-dune.inc) -(include bag-dune.inc) -(include msqueue-dune.inc) -(include list-dune.inc) -(include ctrie-dune.inc) +(executable + (name hash_sequential) + (modules hash_sequential) + (libraries lockfree)) + +(executable + (name hash_parallel) + (modules hash_parallel) + (libraries lockfree)) + +(executable + (name ctrie_sequential) + (modules ctrie_seqeuntial) + (libraries domainslib)) + +(executable + (name ctrie_parallel) + (modules ctrie_parallel) + (libraries domainslib)) + +(executable + (name wsqueue_seqeuntial) + (modules wsqueue_sequential) + (libraries lockfree)) + +(executable + (name wsqueue_parallel) + (modules wsqueue_parallel) + (libraries lockfree)) + +(alias (name multibench_parallel) + (deps hash_parallel.exe + ctrie_parallel.exe + wsqueue_parallel.exe)) + +(alias (name buildbench) + (deps hash_sequential.exe + ctrie_sequential.exe + wsqueue_sequential.exe)) diff --git a/benchmarks/multicore-lockfree/test_hash.ml b/benchmarks/multicore-lockfree/hash_parallel.ml similarity index 100% rename from benchmarks/multicore-lockfree/test_hash.ml rename to benchmarks/multicore-lockfree/hash_parallel.ml diff --git a/benchmarks/multicore-lockfree/hash_sequential.ml b/benchmarks/multicore-lockfree/hash_sequential.ml new file mode 100644 index 0000000000..3ac227926f --- /dev/null +++ b/benchmarks/multicore-lockfree/hash_sequential.ml @@ -0,0 +1,25 @@ +module Hash = Lockfree.Hash + +let threads = int_of_string Sys.argv.(1) +let read_percent = int_of_string Sys.argv.(2) +let num_opers = int_of_string Sys.argv.(3) + +let () = Random.init 42 + +let h = Hash.create() + +let do_stuff_with_hash () = + for _ = 1 to num_opers do + if Random.int 100 > read_percent then + Hash.add h (Random.int 1000) 0 + else + ignore(Hash.find h (Random.int 1000)) + done + +let () = + let rec spawn_thread n = + match n with + | 0 -> [] + | _ -> (Domain.spawn do_stuff_with_hash) :: spawn_thread (n-1) + in + ignore(List.map (fun d -> Domain.join d) (spawn_thread threads)) diff --git a/benchmarks/multicore-lockfree/test_ctrie.ml b/benchmarks/multicore-lockfree/test_ctrie.ml deleted file mode 100644 index cc925e0fc9..0000000000 --- a/benchmarks/multicore-lockfree/test_ctrie.ml +++ /dev/null @@ -1,27 +0,0 @@ -let threads = int_of_string Sys.argv.(1) -let insert_percent = int_of_string Sys.argv.(2) -let num_opers = int_of_string Sys.argv.(3) / threads - -let state_key = Domain.DLS.new_key Random.State.make_self_init - -let tree = Ctrie.empty () - -let work () = - let state = Domain.DLS.get state_key in - let rand_int n = Random.State.int state n in - for _ = 1 to num_opers do - if rand_int 100 > insert_percent then - ignore (Ctrie.mem (rand_int 1000000) tree) - else - Ctrie.insert (rand_int 1000000) 0 tree - done - -let () = - let rec spawn_thread n = - match n with - | 0 -> [] - | _ -> (Domain.spawn work) :: spawn_thread (n-1) - in - let threads = spawn_thread (threads - 1) in - ignore (work ()); - ignore (List.map (fun d -> Domain.join d) threads) diff --git a/benchmarks/multicore-lockfree/test_ctrie_sequential.ml b/benchmarks/multicore-lockfree/test_ctrie_sequential.ml deleted file mode 100644 index b9da64adb1..0000000000 --- a/benchmarks/multicore-lockfree/test_ctrie_sequential.ml +++ /dev/null @@ -1,25 +0,0 @@ -let threads = 1 -let insert_percent = int_of_string Sys.argv.(1) -let num_opers = int_of_string Sys.argv.(2) - -let () = Random.init 42 - -let tree = Ctrie.empty () - -let work () = - for _ = 1 to num_opers do - if Random.int 100 > insert_percent then - ignore (Ctrie.mem (Random.int 1000000) tree) - else - Ctrie.insert (Random.int 1000000) 0 tree - done - -let () = - let rec spawn_thread n = - match n with - | 0 -> [] - | _ -> (Domain.spawn work) :: spawn_thread (n-1) - in - let threads = spawn_thread (threads - 1) in - ignore (work ()); - ignore (List.map (fun d -> Domain.join d) threads) diff --git a/benchmarks/multicore-lockfree/test_wsqueue.ml b/benchmarks/multicore-lockfree/wsqueue_parallel.ml similarity index 100% rename from benchmarks/multicore-lockfree/test_wsqueue.ml rename to benchmarks/multicore-lockfree/wsqueue_parallel.ml diff --git a/benchmarks/multicore-lockfree/wsqueue_sequential.ml b/benchmarks/multicore-lockfree/wsqueue_sequential.ml new file mode 100644 index 0000000000..55d52efd08 --- /dev/null +++ b/benchmarks/multicore-lockfree/wsqueue_sequential.ml @@ -0,0 +1,36 @@ +module WSQueue = Lockfree.WSQueue + +let num_threads = int_of_string Sys.argv.(1) +let num_items = int_of_string Sys.argv.(2) + +let () = Random.init 42 + +let loop_and_drain_queue wsq_array thread_num () = + let rec drain_queue wsq_array thread_num = + let q_num = Random.int num_threads in + let wsq = Array.get wsq_array q_num in + let item = if q_num == thread_num then + WSQueue.pop wsq + else + WSQueue.steal wsq + in match item with + | None when q_num == thread_num -> () + | _ -> drain_queue wsq_array thread_num + in drain_queue wsq_array thread_num + +let make_and_populate_wsq _ = + let q = WSQueue.create () in + for i = 1 to num_items do + WSQueue.push q i + done; q + +let () = + for _ = 1 to 32 do + let wsq_array = Array.init num_threads make_and_populate_wsq in + let rec spawn_thread n = + match n with + | -1 -> [] + | _ -> (Domain.spawn (loop_and_drain_queue wsq_array n)) :: spawn_thread (n-1) + in + ignore(List.map (fun d -> Domain.join d) (spawn_thread (num_threads-1))) + done diff --git a/multicore_parallel_run_config.json b/multicore_parallel_run_config.json index d1ec03bf7f..214d243ee3 100644 --- a/multicore_parallel_run_config.json +++ b/multicore_parallel_run_config.json @@ -475,6 +475,7 @@ ] }, { +<<<<<<< HEAD "executable": "benchmarks/multicore-lockfree/test_wsqueue.exe", "name": "test_wsqueue", "tags": ["lockfree_bench"], @@ -488,6 +489,11 @@ "executable": "benchmarks/multicore-lockfree/test_wsqueue_multicore.exe", "name": "test_wsqueue_multicore", "tags": ["lockfree_bench"], +======= + "executable": "benchmarks/multicore-lockfree/wsqueue_parallel.exe", + "name": "lockfree-wsqueue", + "tags": [], +>>>>>>> updated multicore lockfree "runs": [ { "params": "1 10_000_000", "paramwrapper": "taskset --cpu-list 2-13" @@ -557,6 +563,7 @@ ] }, { +<<<<<<< HEAD "executable": "benchmarks/multicore-lockfree/test_hash.exe", "name": "test_hash", "tags": ["lockfree_bench"], @@ -611,6 +618,11 @@ "executable": "benchmarks/multicore-lockfree/test_bag_multicore.exe", "name": "test_bag_multicore", "tags": ["lockfree_bench"], +======= + "executable": "benchmarks/multicore-lockfree/hash_parallel.exe", + "name": "lockfree-hash", + "tags": [], +>>>>>>> updated multicore lockfree "runs": [ { "params": "1 10_000_000 50", "paramwrapper": "taskset --cpu-list 2-13" @@ -680,25 +692,36 @@ ] }, { - "executable": "benchmarks/multicore-lockfree/test_ctrie_sequential.exe", + "executable": "benchmarks/multicore-lockfree/ctrie_sequential.exe", "name": "lockfree-map", - "ismacrobench": false, + "tags": [], "runs": [ - { "params": "80 1000000", "paramwrapper": "taskset --cpu-list 2-13 chrt -r 1"} + { + "params": "1 10000000 0.5" + } ] }, { - "executable": "benchmarks/multicore-lockfree/test_ctrie.exe", - "name": "lockfree-map_multicore", - "ismacrobench": false, + "executable": "benchmarks/multicore-lockfree/ctrie_parallel.exe", + "name": "lockfree-map_parallel", + "tags": [], "runs": [ - { "params": "2 80 1000000", "paramwrapper": "taskset --cpu-list 2-13 chrt -r 1"}, - { "params": "4 80 1000000", "paramwrapper": "taskset --cpu-list 2-13 chrt -r 1" }, - { "params": "8 80 1000000", "paramwrapper": "taskset --cpu-list 2-13 chrt -r 1" }, - { "params": "12 80 1000000", "paramwrapper": "taskset --cpu-list 2-13 chrt -r 1" }, - { "params": "16 80 1000000", "paramwrapper": "taskset --cpu-list 2-13,16-27 chrt -r 1" }, - { "params": "20 80 1000000", "paramwrapper": "taskset --cpu-list 2-13,16-27 chrt -r 1" }, - { "params": "24 80 1000000", "paramwrapper": "taskset --cpu-list 2-13,16-27 chrt -r 1" } + {"params": "1 1000000 0.5"}, + {"params": "2 1000000 0.5"}, + {"params": "4 1000000 0.5"}, + {"params": "8 1000000 0.5"}, + {"params": "12 1000000 0.5"}, + {"params": "16 1000000 0.5"}, + {"params": "20 1000000 0.5"}, + {"params": "24 1000000 0.5"}, + {"params": "28 1000000 0.5"}, + {"params": "32 1000000 0.5"}, + {"params": "36 1000000 0.5"}, + {"params": "40 1000000 0.5"}, + {"params": "44 1000000 0.5"}, + {"params": "48 1000000 0.5"}, + {"params": "52 1000000 0.5"}, + {"params": "56 1000000 0.5"} ] }, { From 3a9131885d570fdf7873189543cecadb1d52f7cd Mon Sep 17 00:00:00 2001 From: Anmol Sahoo Date: Sun, 23 May 2021 04:09:22 +0530 Subject: [PATCH 5/8] updated lockfree benchmarks and run configs --- benchmarks/multicore-lockfree/bag-dune.inc | 11 --- benchmarks/multicore-lockfree/dune | 82 +++++++++++++------ benchmarks/multicore-lockfree/hash-dune.inc | 11 --- .../multicore-lockfree/hash_sequential.ml | 25 ------ benchmarks/multicore-lockfree/list-dune.inc | 11 --- .../multicore-lockfree/msqueue-dune.inc | 11 --- .../{ctrie_parallel.ml => test_ctrie.ml} | 0 ..._sequential.ml => test_ctrie_multicore.ml} | 0 .../{hash_parallel.ml => test_hash.ml} | 0 .../{wsqueue_parallel.ml => test_wsqueue.ml} | 0 .../multicore-lockfree/wsqueue-dune.inc | 11 --- .../multicore-lockfree/wsqueue_sequential.ml | 36 -------- multicore_parallel_run_config.json | 66 +++++++-------- 13 files changed, 89 insertions(+), 175 deletions(-) delete mode 100644 benchmarks/multicore-lockfree/bag-dune.inc delete mode 100644 benchmarks/multicore-lockfree/hash-dune.inc delete mode 100644 benchmarks/multicore-lockfree/hash_sequential.ml delete mode 100644 benchmarks/multicore-lockfree/list-dune.inc delete mode 100644 benchmarks/multicore-lockfree/msqueue-dune.inc rename benchmarks/multicore-lockfree/{ctrie_parallel.ml => test_ctrie.ml} (100%) rename benchmarks/multicore-lockfree/{ctrie_sequential.ml => test_ctrie_multicore.ml} (100%) rename benchmarks/multicore-lockfree/{hash_parallel.ml => test_hash.ml} (100%) rename benchmarks/multicore-lockfree/{wsqueue_parallel.ml => test_wsqueue.ml} (100%) delete mode 100644 benchmarks/multicore-lockfree/wsqueue-dune.inc delete mode 100644 benchmarks/multicore-lockfree/wsqueue_sequential.ml diff --git a/benchmarks/multicore-lockfree/bag-dune.inc b/benchmarks/multicore-lockfree/bag-dune.inc deleted file mode 100644 index 4d5532fafb..0000000000 --- a/benchmarks/multicore-lockfree/bag-dune.inc +++ /dev/null @@ -1,11 +0,0 @@ -(executable - (name test_bag) - (modules test_bag) - (libraries lockfree)) - -(executable - (name test_bag_multicore) - (modules test_bag_multicore) - (libraries lockfree)) - -(alias (name multibench_parallel) (deps test_bag.exe test_bag_multicore.exe)) \ No newline at end of file diff --git a/benchmarks/multicore-lockfree/dune b/benchmarks/multicore-lockfree/dune index e290ed930d..639ad6c5b1 100644 --- a/benchmarks/multicore-lockfree/dune +++ b/benchmarks/multicore-lockfree/dune @@ -1,39 +1,73 @@ (executable - (name hash_sequential) - (modules hash_sequential) + (name test_bag) + (modules test_bag) (libraries lockfree)) (executable - (name hash_parallel) - (modules hash_parallel) + (name test_bag_multicore) + (modules test_bag_multicore) (libraries lockfree)) (executable - (name ctrie_sequential) - (modules ctrie_seqeuntial) - (libraries domainslib)) + (name test_list) + (modules test_list) + (libraries lockfree)) (executable - (name ctrie_parallel) - (modules ctrie_parallel) - (libraries domainslib)) + (name test_list_multicore) + (modules test_list_multicore) + (libraries lockfree)) + +(executable + (name test_hash) + (modules test_hash) + (libraries lockfree)) + +(executable + (name test_hash_multicore) + (modules test_hash_multicore) + (libraries lockfree)) + +(executable + (name test_msqueue) + (modules test_msqueue) + (libraries lockfree)) + +(executable + (name test_msqueue_multicore) + (modules test_msqueue_multicore) + (libraries lockfree)) + +(executable + (name test_wsqueue) + (modules test_wsqueue) + (libraries lockfree)) + +(executable + (name test_wsqueue_multicore) + (modules test_wsqueue_multicore) + (libraries lockfree)) (executable - (name wsqueue_seqeuntial) - (modules wsqueue_sequential) - (libraries lockfree)) + (name test_ctrie) + (modules test_ctrie) + (libraries domainslib)) (executable - (name wsqueue_parallel) - (modules wsqueue_parallel) - (libraries lockfree)) + (name test_ctrie_multicore) + (modules test_ctrie_multicore) + (libraries domainslib)) (alias (name multibench_parallel) - (deps hash_parallel.exe - ctrie_parallel.exe - wsqueue_parallel.exe)) - -(alias (name buildbench) - (deps hash_sequential.exe - ctrie_sequential.exe - wsqueue_sequential.exe)) + (deps test_bag.exe + test_list.exe + test_hash.exe + test_msqueue.exe + test_wsqueue.exe + test_ctrie.exe + test_bag_multicore.exe + test_list_multicore.exe + test_hash_multicore.exe + test_msqueue_multicore.exe + test_wsqueue_multicore.exe + test_ctrie_multicore.exe)) diff --git a/benchmarks/multicore-lockfree/hash-dune.inc b/benchmarks/multicore-lockfree/hash-dune.inc deleted file mode 100644 index ea1d39764f..0000000000 --- a/benchmarks/multicore-lockfree/hash-dune.inc +++ /dev/null @@ -1,11 +0,0 @@ -(executable - (name test_hash) - (modules test_hash) - (libraries lockfree)) - -(executable - (name test_hash_multicore) - (modules test_hash_multicore) - (libraries lockfree)) - -(alias (name multibench_parallel) (deps test_hash.exe test_hash_multicore.exe)) diff --git a/benchmarks/multicore-lockfree/hash_sequential.ml b/benchmarks/multicore-lockfree/hash_sequential.ml deleted file mode 100644 index 3ac227926f..0000000000 --- a/benchmarks/multicore-lockfree/hash_sequential.ml +++ /dev/null @@ -1,25 +0,0 @@ -module Hash = Lockfree.Hash - -let threads = int_of_string Sys.argv.(1) -let read_percent = int_of_string Sys.argv.(2) -let num_opers = int_of_string Sys.argv.(3) - -let () = Random.init 42 - -let h = Hash.create() - -let do_stuff_with_hash () = - for _ = 1 to num_opers do - if Random.int 100 > read_percent then - Hash.add h (Random.int 1000) 0 - else - ignore(Hash.find h (Random.int 1000)) - done - -let () = - let rec spawn_thread n = - match n with - | 0 -> [] - | _ -> (Domain.spawn do_stuff_with_hash) :: spawn_thread (n-1) - in - ignore(List.map (fun d -> Domain.join d) (spawn_thread threads)) diff --git a/benchmarks/multicore-lockfree/list-dune.inc b/benchmarks/multicore-lockfree/list-dune.inc deleted file mode 100644 index bc2378c8d0..0000000000 --- a/benchmarks/multicore-lockfree/list-dune.inc +++ /dev/null @@ -1,11 +0,0 @@ -(executable - (name test_list) - (modules test_list) - (libraries lockfree)) - -(executable - (name test_list_multicore) - (modules test_list_multicore) - (libraries lockfree)) - -(alias (name multibench_parallel) (deps test_list.exe test_list_multicore.exe)) diff --git a/benchmarks/multicore-lockfree/msqueue-dune.inc b/benchmarks/multicore-lockfree/msqueue-dune.inc deleted file mode 100644 index 738c5694f7..0000000000 --- a/benchmarks/multicore-lockfree/msqueue-dune.inc +++ /dev/null @@ -1,11 +0,0 @@ -(executable - (name test_msqueue) - (modules test_msqueue) - (libraries lockfree)) - -(executable - (name test_msqueue_multicore) - (modules test_msqueue_multicore) - (libraries lockfree)) - -(alias (name multibench_parallel) (deps test_msqueue.exe test_msqueue_multicore.exe)) diff --git a/benchmarks/multicore-lockfree/ctrie_parallel.ml b/benchmarks/multicore-lockfree/test_ctrie.ml similarity index 100% rename from benchmarks/multicore-lockfree/ctrie_parallel.ml rename to benchmarks/multicore-lockfree/test_ctrie.ml diff --git a/benchmarks/multicore-lockfree/ctrie_sequential.ml b/benchmarks/multicore-lockfree/test_ctrie_multicore.ml similarity index 100% rename from benchmarks/multicore-lockfree/ctrie_sequential.ml rename to benchmarks/multicore-lockfree/test_ctrie_multicore.ml diff --git a/benchmarks/multicore-lockfree/hash_parallel.ml b/benchmarks/multicore-lockfree/test_hash.ml similarity index 100% rename from benchmarks/multicore-lockfree/hash_parallel.ml rename to benchmarks/multicore-lockfree/test_hash.ml diff --git a/benchmarks/multicore-lockfree/wsqueue_parallel.ml b/benchmarks/multicore-lockfree/test_wsqueue.ml similarity index 100% rename from benchmarks/multicore-lockfree/wsqueue_parallel.ml rename to benchmarks/multicore-lockfree/test_wsqueue.ml diff --git a/benchmarks/multicore-lockfree/wsqueue-dune.inc b/benchmarks/multicore-lockfree/wsqueue-dune.inc deleted file mode 100644 index 4bef6e7d56..0000000000 --- a/benchmarks/multicore-lockfree/wsqueue-dune.inc +++ /dev/null @@ -1,11 +0,0 @@ -(executable - (name test_wsqueue) - (modules test_wsqueue) - (libraries lockfree)) - -(executable - (name test_wsqueue_multicore) - (modules test_wsqueue_multicore) - (libraries lockfree)) - -(alias (name multibench_parallel) (deps test_wsqueue.exe test_wsqueue_multicore.exe)) diff --git a/benchmarks/multicore-lockfree/wsqueue_sequential.ml b/benchmarks/multicore-lockfree/wsqueue_sequential.ml deleted file mode 100644 index 55d52efd08..0000000000 --- a/benchmarks/multicore-lockfree/wsqueue_sequential.ml +++ /dev/null @@ -1,36 +0,0 @@ -module WSQueue = Lockfree.WSQueue - -let num_threads = int_of_string Sys.argv.(1) -let num_items = int_of_string Sys.argv.(2) - -let () = Random.init 42 - -let loop_and_drain_queue wsq_array thread_num () = - let rec drain_queue wsq_array thread_num = - let q_num = Random.int num_threads in - let wsq = Array.get wsq_array q_num in - let item = if q_num == thread_num then - WSQueue.pop wsq - else - WSQueue.steal wsq - in match item with - | None when q_num == thread_num -> () - | _ -> drain_queue wsq_array thread_num - in drain_queue wsq_array thread_num - -let make_and_populate_wsq _ = - let q = WSQueue.create () in - for i = 1 to num_items do - WSQueue.push q i - done; q - -let () = - for _ = 1 to 32 do - let wsq_array = Array.init num_threads make_and_populate_wsq in - let rec spawn_thread n = - match n with - | -1 -> [] - | _ -> (Domain.spawn (loop_and_drain_queue wsq_array n)) :: spawn_thread (n-1) - in - ignore(List.map (fun d -> Domain.join d) (spawn_thread (num_threads-1))) - done diff --git a/multicore_parallel_run_config.json b/multicore_parallel_run_config.json index 214d243ee3..6ef6768fbd 100644 --- a/multicore_parallel_run_config.json +++ b/multicore_parallel_run_config.json @@ -475,7 +475,6 @@ ] }, { -<<<<<<< HEAD "executable": "benchmarks/multicore-lockfree/test_wsqueue.exe", "name": "test_wsqueue", "tags": ["lockfree_bench"], @@ -489,11 +488,6 @@ "executable": "benchmarks/multicore-lockfree/test_wsqueue_multicore.exe", "name": "test_wsqueue_multicore", "tags": ["lockfree_bench"], -======= - "executable": "benchmarks/multicore-lockfree/wsqueue_parallel.exe", - "name": "lockfree-wsqueue", - "tags": [], ->>>>>>> updated multicore lockfree "runs": [ { "params": "1 10_000_000", "paramwrapper": "taskset --cpu-list 2-13" @@ -563,7 +557,6 @@ ] }, { -<<<<<<< HEAD "executable": "benchmarks/multicore-lockfree/test_hash.exe", "name": "test_hash", "tags": ["lockfree_bench"], @@ -618,11 +611,6 @@ "executable": "benchmarks/multicore-lockfree/test_bag_multicore.exe", "name": "test_bag_multicore", "tags": ["lockfree_bench"], -======= - "executable": "benchmarks/multicore-lockfree/hash_parallel.exe", - "name": "lockfree-hash", - "tags": [], ->>>>>>> updated multicore lockfree "runs": [ { "params": "1 10_000_000 50", "paramwrapper": "taskset --cpu-list 2-13" @@ -692,36 +680,44 @@ ] }, { - "executable": "benchmarks/multicore-lockfree/ctrie_sequential.exe", - "name": "lockfree-map", - "tags": [], + "executable": "benchmarks/multicore-lockfree/test_ctrie.exe", + "name": "test_ctrie", + "tags": ["lockfree_bench"], "runs": [ { - "params": "1 10000000 0.5" + "params": "10_000_000 50" } ] }, { - "executable": "benchmarks/multicore-lockfree/ctrie_parallel.exe", - "name": "lockfree-map_parallel", - "tags": [], + "executable": "benchmarks/multicore-lockfree/test_ctrie_multicore.exe", + "name": "test_ctrie_multicore", + "tags": ["lockfree_bench"], "runs": [ - {"params": "1 1000000 0.5"}, - {"params": "2 1000000 0.5"}, - {"params": "4 1000000 0.5"}, - {"params": "8 1000000 0.5"}, - {"params": "12 1000000 0.5"}, - {"params": "16 1000000 0.5"}, - {"params": "20 1000000 0.5"}, - {"params": "24 1000000 0.5"}, - {"params": "28 1000000 0.5"}, - {"params": "32 1000000 0.5"}, - {"params": "36 1000000 0.5"}, - {"params": "40 1000000 0.5"}, - {"params": "44 1000000 0.5"}, - {"params": "48 1000000 0.5"}, - {"params": "52 1000000 0.5"}, - {"params": "56 1000000 0.5"} + { + "params": "1 10_000_000 50", "paramwrapper": "taskset --cpu-list 2-13" + }, + { + "params": "2 10_000_000 50", "paramwrapper": "taskset --cpu-list 2-13" + }, + { + "params": "4 10_000_000 50", "paramwrapper": "taskset --cpu-list 2-13" + }, + { + "params": "8 10_000_000 50", "paramwrapper": "taskset --cpu-list 2-13" + }, + { + "params": "12 10_000_000 50", "paramwrapper": "taskset --cpu-list 2-13" + }, + { + "params": "16 10_000_000 50", "paramwrapper": "taskset --cpu-list 2-13,16-27" + }, + { + "params": "20 10_000_000 50", "paramwrapper": "taskset --cpu-list 2-13,16-27" + }, + { + "params": "24 10_000_000 50", "paramwrapper": "taskset --cpu-list 2-13,16-27" + } ] }, { From e56c692b10f5f3be509ea1bc6e0c7a38061c2f16 Mon Sep 17 00:00:00 2001 From: Anmol Sahoo Date: Sun, 23 May 2021 04:17:53 +0530 Subject: [PATCH 6/8] updated ctrie benchmark --- benchmarks/multicore-lockfree/dune | 3 +- benchmarks/multicore-lockfree/test_ctrie.ml | 29 +++++++------------ .../test_ctrie_multicore.ml | 20 +++++-------- 3 files changed, 20 insertions(+), 32 deletions(-) diff --git a/benchmarks/multicore-lockfree/dune b/benchmarks/multicore-lockfree/dune index 639ad6c5b1..7de0c247c6 100644 --- a/benchmarks/multicore-lockfree/dune +++ b/benchmarks/multicore-lockfree/dune @@ -50,8 +50,7 @@ (executable (name test_ctrie) - (modules test_ctrie) - (libraries domainslib)) + (modules test_ctrie)) (executable (name test_ctrie_multicore) diff --git a/benchmarks/multicore-lockfree/test_ctrie.ml b/benchmarks/multicore-lockfree/test_ctrie.ml index 7d2ee4da99..2beb5a611b 100644 --- a/benchmarks/multicore-lockfree/test_ctrie.ml +++ b/benchmarks/multicore-lockfree/test_ctrie.ml @@ -118,31 +118,24 @@ module Ctrie = struct let mem k t = mem k 0 t end -module T = Domainslib.Task - -let num_domains = try int_of_string Sys.argv.(1) with _ -> 4 -let num_elems = try int_of_string Sys.argv.(2) with _ -> 1000000 -let ins_ratio = try float_of_string Sys.argv.(3) with _ -> 0.5 +let num_elems = try int_of_string Sys.argv.(1) with _ -> 10_000_000 +let ins_percent = try int_of_string Sys.argv.(2) with _ -> 50 let state_key = Domain.DLS.new_key Random.State.make_self_init in -let rand_int () = - let state = Domain.DLS.get state_key in - Random.State.int state 10000 - -let rand_float () = +let rand_int n = let state = Domain.DLS.get state_key in - Random.State.float state 1.0 + Random.State.int state n -let work tree int = - if rand_float () > ins_ratio then - ignore (Ctrie.mem (rand_int ()) tree) +let work tree _ = + if rand_int 100 >= ins_percent then + ignore (Ctrie.mem (rand_int 10000) tree) else - ignore (Ctrie.insert (rand_int ()) 0 tree) + ignore (Ctrie.insert (rand_int 10000) 0 tree) let _ = - let pool = T.setup_pool num_domains in let tree = Ctrie.empty () in let work = work tree in - T.parallel_for ~start:0 ~finish:(num_elems - 1) ~body:work pool; - T.teardown_pool pool + for i in range 0 to (num_elems - 1) do + work i + done diff --git a/benchmarks/multicore-lockfree/test_ctrie_multicore.ml b/benchmarks/multicore-lockfree/test_ctrie_multicore.ml index 7d2ee4da99..449144f346 100644 --- a/benchmarks/multicore-lockfree/test_ctrie_multicore.ml +++ b/benchmarks/multicore-lockfree/test_ctrie_multicore.ml @@ -120,25 +120,21 @@ end module T = Domainslib.Task -let num_domains = try int_of_string Sys.argv.(1) with _ -> 4 -let num_elems = try int_of_string Sys.argv.(2) with _ -> 1000000 -let ins_ratio = try float_of_string Sys.argv.(3) with _ -> 0.5 +let num_domains = try int_of_string Sys.argv.(1) with _ -> 4 +let num_elems = try int_of_string Sys.argv.(2) with _ -> 10_000_000 +let ins_percent = try int_of_string Sys.argv.(3) with _ -> 50 let state_key = Domain.DLS.new_key Random.State.make_self_init in -let rand_int () = +let rand_int n = let state = Domain.DLS.get state_key in - Random.State.int state 10000 - -let rand_float () = - let state = Domain.DLS.get state_key in - Random.State.float state 1.0 + Random.State.int state n let work tree int = - if rand_float () > ins_ratio then - ignore (Ctrie.mem (rand_int ()) tree) + if rand_int 100 >= ins_percent then + ignore (Ctrie.mem (rand_int 10000) tree) else - ignore (Ctrie.insert (rand_int ()) 0 tree) + ignore (Ctrie.insert (rand_int 10000) 0 tree) let _ = let pool = T.setup_pool num_domains in From 32fff422114a4ad0180fce2af52e1780e627dc9b Mon Sep 17 00:00:00 2001 From: Anmol Sahoo Date: Sun, 23 May 2021 05:01:34 +0530 Subject: [PATCH 7/8] small edit --- benchmarks/multicore-lockfree/test_ctrie.ml | 2 +- benchmarks/multicore-lockfree/test_ctrie_multicore.ml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/benchmarks/multicore-lockfree/test_ctrie.ml b/benchmarks/multicore-lockfree/test_ctrie.ml index 2beb5a611b..0ff9333f25 100644 --- a/benchmarks/multicore-lockfree/test_ctrie.ml +++ b/benchmarks/multicore-lockfree/test_ctrie.ml @@ -121,7 +121,7 @@ end let num_elems = try int_of_string Sys.argv.(1) with _ -> 10_000_000 let ins_percent = try int_of_string Sys.argv.(2) with _ -> 50 -let state_key = Domain.DLS.new_key Random.State.make_self_init in +let state_key = Domain.DLS.new_key Random.State.make_self_init let rand_int n = let state = Domain.DLS.get state_key in diff --git a/benchmarks/multicore-lockfree/test_ctrie_multicore.ml b/benchmarks/multicore-lockfree/test_ctrie_multicore.ml index 449144f346..74f822564b 100644 --- a/benchmarks/multicore-lockfree/test_ctrie_multicore.ml +++ b/benchmarks/multicore-lockfree/test_ctrie_multicore.ml @@ -124,7 +124,7 @@ let num_domains = try int_of_string Sys.argv.(1) with _ -> 4 let num_elems = try int_of_string Sys.argv.(2) with _ -> 10_000_000 let ins_percent = try int_of_string Sys.argv.(3) with _ -> 50 -let state_key = Domain.DLS.new_key Random.State.make_self_init in +let state_key = Domain.DLS.new_key Random.State.make_self_init let rand_int n = let state = Domain.DLS.get state_key in From a739e12c4306f6f73accbb173f7ab653cd6584dd Mon Sep 17 00:00:00 2001 From: Anmol Sahoo Date: Sun, 23 May 2021 05:03:25 +0530 Subject: [PATCH 8/8] minor edit --- benchmarks/multicore-lockfree/dune | 5 +++-- benchmarks/multicore-lockfree/test_ctrie.ml | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/benchmarks/multicore-lockfree/dune b/benchmarks/multicore-lockfree/dune index 7de0c247c6..3932cf00a4 100644 --- a/benchmarks/multicore-lockfree/dune +++ b/benchmarks/multicore-lockfree/dune @@ -50,12 +50,13 @@ (executable (name test_ctrie) - (modules test_ctrie)) + (modules test_ctrie) + (libraries base)) (executable (name test_ctrie_multicore) (modules test_ctrie_multicore) - (libraries domainslib)) + (libraries base domainslib)) (alias (name multibench_parallel) (deps test_bag.exe diff --git a/benchmarks/multicore-lockfree/test_ctrie.ml b/benchmarks/multicore-lockfree/test_ctrie.ml index 0ff9333f25..1935c133bb 100644 --- a/benchmarks/multicore-lockfree/test_ctrie.ml +++ b/benchmarks/multicore-lockfree/test_ctrie.ml @@ -136,6 +136,6 @@ let work tree _ = let _ = let tree = Ctrie.empty () in let work = work tree in - for i in range 0 to (num_elems - 1) do + for i = 0 to (num_elems - 1) do work i done