Skip to content

add create_int_array #7

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

Closed
wants to merge 1 commit into from
Closed
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
3 changes: 3 additions & 0 deletions lib/task.ml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ type pool =
{domains : unit Domain.t array;
task_chan : task_msg Chan.t}

let create_int_array : int -> int array = fun n ->
Obj.magic (Array.create_float n)

let do_task f p =
try
let res = f () in
Expand Down
4 changes: 4 additions & 0 deletions lib/task.mli
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ type 'a promise
type pool
(** Type of task pool *)

val create_int_array : int -> int array
(** [create_int_array n] returns an uninitialised array of size n. The
* uninitialized array can be further initialised in parallel.*)

val setup_pool : num_domains:int -> pool
(** Sets up a task execution pool with [num_domains]. *)

Expand Down
6 changes: 6 additions & 0 deletions test/dune
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,9 @@
(libraries domainslib unix)
(modules prefix_sum)
(modes native))

(test
(name par_init)
(libraries domainslib)
(modules par_init)
(modes native))
13 changes: 13 additions & 0 deletions test/par_init.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module T = Domainslib.Task

let num_domains = try int_of_string Sys.argv.(1) with _ -> 4
let n = try int_of_string Sys.argv.(2) with _ -> 10000

let _ =
let arr = T.create_int_array n in
let pool = T.setup_pool ~num_domains:(num_domains - 1) in
T.parallel_for pool ~chunk_size:(n/num_domains) ~start:0 ~finish:(pred n) ~body:(fun i ->
Array.unsafe_set arr i i
);
Printf.printf "%d\n" (Array.length arr);
T.teardown_pool