diff --git a/benchmarks/multicore-numerical/count_change_iter.ml b/benchmarks/multicore-numerical/count_change_iter.ml new file mode 100644 index 0000000000..ea9ae328be --- /dev/null +++ b/benchmarks/multicore-numerical/count_change_iter.ml @@ -0,0 +1,41 @@ +let n = try int_of_string @@ Sys.argv.(1) with _ -> 120 + +module L = List + +type coins = (int * int) list + +type frame = { amt : int; coins : coins; current_enum : int list } + +let top = L.hd + +let rest = L.tl + +let rec run_cc (acc: int list list) (f : frame) (stack : frame list) : (int list list) = + match f.amt, f.coins, stack with + | 0, _, [] -> acc + | 0, _, _ -> run_cc (f.current_enum::acc) (top stack) (rest stack) + | _, [], [] -> acc + | _, [], _ -> run_cc acc (top stack) (rest stack) + | _, (den,qty)::rst ,_ -> + if den > f.amt then + let new_f = { amt = f.amt; coins = (rest f.coins); current_enum = f.current_enum } in + run_cc acc new_f stack + else + let new_coins = if qty == 1 then + rst + else (den, qty-1)::rst in + let left = { amt = (f.amt-den); coins = new_coins; current_enum = (den :: f.current_enum) } in + let right = { amt = f.amt; coins = rst; current_enum = f.current_enum } in + run_cc acc left (right::stack) + +let cc amt (coins : (int * int) list) = + run_cc [] { amt = amt; coins = coins; current_enum = [] } [] + +let coins_input : (int * int) list = + let den = [500 ; 250 ; 150; 100 ; 75 ; 50 ; 25 ; 20 ; 10 ; 5 ; 2 ; 1] in + let qty = [22; 55 ; 88 ; 88 ; 99 ; 99 ; 122; 122; 122 ; 122; 177; 177] in + L.combine den qty + +let () = + let x = cc n coins_input in + Printf.printf "possibilities = %d\n" (L.length x) diff --git a/benchmarks/multicore-numerical/count_change_iter_multicore.ml b/benchmarks/multicore-numerical/count_change_iter_multicore.ml new file mode 100644 index 0000000000..84f63fc87c --- /dev/null +++ b/benchmarks/multicore-numerical/count_change_iter_multicore.ml @@ -0,0 +1,84 @@ +let n = try int_of_string @@ Sys.argv.(1) with _ -> 120 +let num_domains = try int_of_string @@ Sys.argv.(1) with _ -> 1 + +module A = Array +module L = List +module T = Domainslib.Task + +type coins = (int * int) list + +type frame = { amt : int; coins : coins; current_enum : int list } + +let top = L.hd + +let rest = L.tl + +let rec run_cc first_call (acc: int list list) (f : frame) (stack : frame list) : (int list list) = + match f.amt, f.coins, stack with + | 0, _, [] -> acc + | 0, _, _ -> run_cc false (f.current_enum::acc) (top stack) (rest stack) + | _, [], [] -> acc + | _, [], _ -> run_cc false acc (top stack) (rest stack) + | _, (den,qty)::rst ,_ -> + if den > f.amt then + let new_f = { amt = f.amt; coins = (rest f.coins); current_enum = f.current_enum } in + run_cc false acc new_f stack + else + let new_coins = if qty == 1 then + rst + else (den, qty-1)::rst in + let left = { amt = (f.amt-den); coins = new_coins; current_enum = (den :: f.current_enum) } in + let right = { amt = f.amt; coins = rst; current_enum = f.current_enum } in + if not first_call then run_cc false acc left (right::stack) + else + run_cc false acc left stack + +let cc amt (coins : (int * int) list) = + run_cc true [] { amt = amt; coins = coins; current_enum = [] } [] + +let rec get_deductibles amt coins = + let den = fst @@ L.hd coins in + match (den > amt) with + | false -> coins + | true -> get_deductibles amt (L.tl coins) + +let setup_frames amt coins = + let coins = get_deductibles amt coins in + let clen = L.length coins in + let a = Array.make clen { amt = 0; coins = []; current_enum = [] } in + let rec aux count coins = + match count = clen with + | true -> a + | false -> begin + let f = { + amt = amt; + coins = coins; + current_enum = [] + } in + a.(count) <- f; + aux (count+1) (L.tl coins) + end + in + aux 0 coins + +let sum_lengths arr = A.fold_left (+) 0 (A.map L.length arr) + +let cc_par pool amt (coins : ((int * int) list)) = + let stacks = setup_frames amt coins in + let arr = A.init (A.length stacks) (fun _ -> []) in + let len = A.length arr in + T.parallel_for pool ~start:0 ~finish:(len-1) ~body:(fun i -> + let f = stacks.(i) in + arr.(i) <- cc f.amt f.coins + ); + Printf.printf "possibilites = %d\n" (sum_lengths arr) + +let coins_input : (int * int) list = + let den = [500 ; 250 ; 150; 100 ; 75 ; 50 ; 25 ; 20 ; 10 ; 5 ; 2 ; 1] in + let qty = [22; 55 ; 88 ; 88 ; 99 ; 99 ; 122; 122; 122 ; 122; 177; 177] in + L.combine den qty + +let _ = + let pool = T.setup_pool ~num_additional_domains:(num_domains - 1) () in + T.run pool (fun () -> cc_par pool n coins_input); + T.teardown_pool pool diff --git a/benchmarks/multicore-numerical/dune b/benchmarks/multicore-numerical/dune index 6439d77296..90bcfbc78c 100644 --- a/benchmarks/multicore-numerical/dune +++ b/benchmarks/multicore-numerical/dune @@ -113,26 +113,37 @@ (modules evolutionary_algorithm_multicore) (libraries domainslib)) +(executable + (name count_change_iter) + (modes native byte) + (modules count_change_iter)) + +(executable + (name count_change_iter_multicore) + (modules count_change_iter_multicore) + (libraries domainslib)) + (alias (name multibench_parallel) (deps mandelbrot6_multicore.exe spectralnorm2_multicore.exe quicksort.exe quicksort_multicore.exe binarytrees5_multicore.exe - game_of_life.exe game_of_life_multicore.exe - matrix_multiplication.exe matrix_multiplication_multicore.exe - matrix_multiplication_tiling_multicore.exe nbody.exe - nbody_multicore.exe nqueens_multicore.exe mergesort.exe mergesort_multicore.exe - floyd_warshall.exe floyd_warshall_multicore.exe - LU_decomposition.exe LU_decomposition_multicore.exe - evolutionary_algorithm_multicore.exe evolutionary_algorithm.exe nqueens.exe)) + game_of_life.exe game_of_life_multicore.exe + matrix_multiplication.exe matrix_multiplication_multicore.exe + matrix_multiplication_tiling_multicore.exe nbody.exe + nbody_multicore.exe nqueens_multicore.exe mergesort.exe mergesort_multicore.exe + floyd_warshall.exe floyd_warshall_multicore.exe + LU_decomposition.exe LU_decomposition_multicore.exe + evolutionary_algorithm_multicore.exe evolutionary_algorithm.exe nqueens.exe + count_change_iter_multicore.exe count_change_iter.exe)) (alias (name buildbench) (deps game_of_life.exe matrix_multiplication.exe quicksort.exe mergesort.exe floyd_warshall.exe LU_decomposition.exe - evolutionary_algorithm.exe nqueens.exe)) + evolutionary_algorithm.exe nqueens.exe count_change_iter.exe)) (alias (name bytebench) (deps game_of_life.bc matrix_multiplication.bc quicksort.bc mergesort.bc floyd_warshall.bc evolutionary_algorithm.bc - LU_decomposition.bc nbody.bc mergesort.bc nqueens.bc)) + LU_decomposition.bc nbody.bc mergesort.bc nqueens.bc count_change_iter.bc)) diff --git a/multicore_parallel_run_config.json b/multicore_parallel_run_config.json index 447742578b..a4ddc3c229 100644 --- a/multicore_parallel_run_config.json +++ b/multicore_parallel_run_config.json @@ -194,6 +194,29 @@ { "params": "24 15", "paramwrapper": "taskset --cpu-list 2-13,16-27" } ] }, + { + "executable": "benchmarks/multicore-numerical/count_change_iter.exe", + "name": "count_change_iter", + "tags": ["10s_100s", "macro_bench"], + "runs": [ + { "params": "400", "paramwrapper": "taskset --cpu-list 2-13" } + ] + }, + { + "executable": "benchmarks/multicore-numerical/count_change_iter_multicore.exe", + "name": "count_change_iter_multicore", + "tags": ["macro_bench","10s_100s"], + "runs": [ + { "params": "1 400", "paramwrapper": "taskset --cpu-list 2-13"}, + { "params": "2 400", "paramwrapper": "taskset --cpu-list 2-13" }, + { "params": "4 400", "paramwrapper": "taskset --cpu-list 2-13" }, + { "params": "8 400", "paramwrapper": "taskset --cpu-list 2-13" }, + { "params": "12 400", "paramwrapper": "taskset --cpu-list 2-13" }, + { "params": "16 400", "paramwrapper": "taskset --cpu-list 2-13,16-27" }, + { "params": "20 400", "paramwrapper": "taskset --cpu-list 2-13,16-27" }, + { "params": "24 400", "paramwrapper": "taskset --cpu-list 2-13,16-27" } + ] + }, { "executable": "benchmarks/multicore-numerical/mergesort.exe", diff --git a/run_config.json b/run_config.json index 0bd395d143..c94812a3fe 100644 --- a/run_config.json +++ b/run_config.json @@ -289,6 +289,19 @@ } ] }, + { + "executable": "benchmarks/multicore-numerical/count_change_iter.exe", + "name": "count_change_iter", + "tags": [ + "10s_100s", + "macro_bench" + ], + "runs": [ + { + "params": "400" + } + ] + }, { "executable": "benchmarks/multicore-numerical/mergersort.exe", "name": "mergesort", diff --git a/run_config_byte.json b/run_config_byte.json index bdc5c2a4d4..d4180c1eab 100644 --- a/run_config_byte.json +++ b/run_config_byte.json @@ -217,6 +217,15 @@ } ] }, + { + "executable": "benchmarks/multicore-numerical/count_change_iter.bc", + "name": "count_change_iter.bc", + "runs": [ + { + "params": "400" + } + ] + }, { "executable": "benchmarks/valet/test_lwt.bc", "name": "test_lwt.bc",