Skip to content
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

Array iters #120

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
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
10 changes: 10 additions & 0 deletions lib/array_iter.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

let parallel_iter (f:'a->unit) arr cur_pool =
let arr_len = Array.length arr in
Task.parallel_for cur_pool ~start:0 ~finish:(arr_len - 1) ~body:(fun i->
f arr.(i))

let parallel_iteri (f:int->'a->unit) arr cur_pool =
let arr_len = Array.length arr in
Task.parallel_for cur_pool ~start:0 ~finish:(arr_len - 1) ~body:(fun i->
f i arr.(i))
9 changes: 9 additions & 0 deletions lib/array_iter.mli
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

val parallel_iter : ('a -> unit) -> 'a array -> Task.pool -> unit
(** [parallel_iter f a pool] applies function [f] in turn to all the elements of [a]
It does Stdlib.Array.iter in parallel *)

val parallel_iteri : (int -> 'a -> unit) -> 'a array -> Task.pool -> unit
(** Same as {!parallel_iter}, but the function is applied to the index of the element as first
argument, and the element itself as second argument
It performs Stdlib.Array.iteri in parallel *)
Loading