Skip to content

num_domains to num_additional_domains #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 9, 2021
Merged
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
22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,17 +177,17 @@ this on `utop`.
```ocaml
# open Domainslib

# let pool = Task.setup_pool ~num_domains:3
# let pool = Task.setup_pool ~num_additional_domains:3
val pool : Task.pool = <abstr>
```
We have created a new task pool with three new domains. The parent domain is
also part of this pool, thus making it a pool of four domains. After the pool
is setup, we can use this pool to execute all tasks we want to run in parallel.
The `setup_pool` function requires us to specify the number of new domains to
be spawned in the task pool. The ideal number of domains to initiate a task
pool with is equal to the number of cores available. Since the parent domain
also takes part in the pool, the `num_domains` parameter should be one less
than the number of available cores.
also part of this pool, thus making it a pool of four domains. After the pool is
setup, we can use this pool to execute all tasks we want to run in parallel. The
`setup_pool` function requires us to specify the number of new domains to be
spawned in the task pool. The ideal number of domains to initiate a task pool
with is equal to the number of cores available. Since the parent domain also
takes part in the pool, the `num_additional_domains` parameter should be one
less than the number of available cores.

Closing the task pool after execution of all tasks, though not strictly
necessary, is highly recommended. This can be done as
Expand Down Expand Up @@ -704,7 +704,7 @@ let n = try int_of_string Sys.argv.(2) with _ -> 100000
let a = Array.create_float n

let _ =
let pool = Task.setup_pool ~num_domains:(num_domains - 1) in
let pool = Task.setup_pool ~num_additional_domains:(num_domains - 1) in
Task.parallel_for pool ~start:0
~finish:(n - 1) ~body:(fun i -> Array.set a i (Random.float 1000.));
Task.teardown_pool pool
Expand Down Expand Up @@ -751,7 +751,7 @@ let num_domains = try int_of_string Sys.argv.(1) with _ -> 4
let arr = Array.create_float n

let _ =
let domains = T.setup_pool ~num_domains:(num_domains - 1) in
let domains = T.setup_pool ~num_additional_domains:(num_domains - 1) in
let states = Array.init num_domains (fun _ -> Random.State.make_self_init()) in
T.parallel_for domains ~start:0 ~finish:(n-1)
~body:(fun i ->
Expand Down Expand Up @@ -813,7 +813,7 @@ let init_part s e arr =
done

let _ =
let domains = T.setup_pool ~num_domains:(num_domains - 1) in
let domains = T.setup_pool ~num_additional_domains:(num_domains - 1) in
T.parallel_for domains ~chunk_size:1 ~start:0 ~finish:(num_domains - 1)
~body:(fun i -> init_part (i * n / num_domains) ((i+1) * n / num_domains - 1) arr);
T.teardown_pool domains
Expand Down
2 changes: 1 addition & 1 deletion code/profiling/float_init_par.ml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ let n = try int_of_string Sys.argv.(2) with _ -> 100000
let a = Array.create_float n

let _ =
let pool = Task.setup_pool ~num_domains:(num_domains-1) in
let pool = Task.setup_pool ~num_additional_domains:(num_domains-1) in
Task.parallel_for pool ~chunk_size:(n/num_domains) ~start:0
~finish:(n - 1) ~body:(fun i -> Array.set a i (Random.float 1000.));
Task.teardown_pool pool
2 changes: 1 addition & 1 deletion code/profiling/float_init_par2.ml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ let num_domains = try int_of_string Sys.argv.(1) with _ -> 4
let arr = Array.create_float n

let _ =
let domains = T.setup_pool ~num_domains:(num_domains - 1) in
let domains = T.setup_pool ~num_additional_domains:(num_domains - 1) in
let states = Array.init num_domains (fun _ -> Random.State.make_self_init()) in
T.parallel_for domains ~chunk_size:(n/num_domains) ~start:0 ~finish:(n-1)
~body:(fun i ->
Expand Down
2 changes: 1 addition & 1 deletion code/profiling/float_init_par3.ml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ let init_part s e arr =
done

let _ =
let domains = T.setup_pool ~num_domains:(num_domains - 1) in
let domains = T.setup_pool ~num_additional_domains:(num_domains - 1) in
T.parallel_for domains ~chunk_size:1 ~start:0 ~finish:(num_domains - 1)
~body:(fun i -> init_part (i * n / num_domains) ((i+1) * n / num_domains - 1) arr);
T.teardown_pool domains
2 changes: 1 addition & 1 deletion code/task/fibonacci_multicore.ml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ let rec fib_par pool n =
Task.await pool a + Task.await pool b

let main =
let pool = Task.setup_pool ~num_domains:(num_domains - 1) in
let pool = Task.setup_pool ~num_additional_domains:(num_domains - 1) in
let res = fib_par pool n in
Task.teardown_pool pool;
Printf.printf "fib(%d) = %d\n" n res
2 changes: 1 addition & 1 deletion code/task/matrix_multiplication_multicore.ml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ let print_matrix m =
done

let _ =
let pool = Task.setup_pool ~num_domains:(num_domains - 1) in
let pool = Task.setup_pool ~num_additional_domains:(num_domains - 1) in
let m1 = Array.init n (fun _ -> Array.init n (fun _ -> Random.int 100)) in
let m2 = Array.init n (fun _ -> Array.init n (fun _ -> Random.int 100)) in
(* print_matrix m1;
Expand Down
2 changes: 1 addition & 1 deletion code/task/three_matrix_multiplication.ml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ let print_matrix m =
done

let _ =
let pool = Task.setup_pool ~num_domains:(num_domains - 1) in
let pool = Task.setup_pool ~num_additional_domains:(num_domains - 1) in
let m1 = Array.init n (fun _ -> Array.init n (fun _ -> Random.int 100)) in
let m2 = Array.init n (fun _ -> Array.init n (fun _ -> Random.int 100)) in
let m3 = Array.init n (fun _ -> Array.init n (fun _ -> Random.int 100)) in
Expand Down