Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions benchmarks/multicore-numerical/count_change_iter.ml
Original file line number Diff line number Diff line change
@@ -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 =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tuple here could be replaced with a record such as:

type coin = { denom : int; num : int; }

This would make it easier to read what's stored in the tuple.

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)
84 changes: 84 additions & 0 deletions benchmarks/multicore-numerical/count_change_iter_multicore.ml
Original file line number Diff line number Diff line change
@@ -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
29 changes: 20 additions & 9 deletions benchmarks/multicore-numerical/dune
Original file line number Diff line number Diff line change
Expand Up @@ -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))
23 changes: 23 additions & 0 deletions multicore_parallel_run_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
13 changes: 13 additions & 0 deletions run_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
9 changes: 9 additions & 0 deletions run_config_byte.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down