From b798a961c8f6746b2becad9649ef2153c956df02 Mon Sep 17 00:00:00 2001 From: abhash Date: Sat, 21 Oct 2023 19:33:56 +0530 Subject: [PATCH 1/3] Adds parallel_iter and parallel_iteri for arrays. --- lib/array_iter.ml | 10 ++++++++++ lib/array_iter.mli | 9 +++++++++ 2 files changed, 19 insertions(+) create mode 100644 lib/array_iter.ml create mode 100644 lib/array_iter.mli diff --git a/lib/array_iter.ml b/lib/array_iter.ml new file mode 100644 index 0000000..566813e --- /dev/null +++ b/lib/array_iter.ml @@ -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)) diff --git a/lib/array_iter.mli b/lib/array_iter.mli new file mode 100644 index 0000000..b9a68e6 --- /dev/null +++ b/lib/array_iter.mli @@ -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 *) \ No newline at end of file From 1f38972bdb9fe7f03f6d71d14c19a37fae518a8a Mon Sep 17 00:00:00 2001 From: abhash Date: Sat, 21 Oct 2023 19:57:11 +0530 Subject: [PATCH 2/3] Updated doc comments --- lib/array_iter.mli | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/array_iter.mli b/lib/array_iter.mli index b9a68e6..b4d785e 100644 --- a/lib/array_iter.mli +++ b/lib/array_iter.mli @@ -1,6 +1,7 @@ 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 +(** [parallel_iter f a pool] applies function [f] in turn to all the elements of [a] + [pool] is the Task Pool It does Stdlib.Array.iter in parallel *) val parallel_iteri : (int -> 'a -> unit) -> 'a array -> Task.pool -> unit From 088b3a074d4d0d4c20f25a98076bde0212daf9d7 Mon Sep 17 00:00:00 2001 From: abhash Date: Sat, 21 Oct 2023 19:59:35 +0530 Subject: [PATCH 3/3] Modified comment docs --- lib/array_iter.mli | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/array_iter.mli b/lib/array_iter.mli index b4d785e..6ef89fd 100644 --- a/lib/array_iter.mli +++ b/lib/array_iter.mli @@ -1,7 +1,6 @@ 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] - [pool] is the Task Pool It does Stdlib.Array.iter in parallel *) val parallel_iteri : (int -> 'a -> unit) -> 'a array -> Task.pool -> unit