Module ParallelArray

module ParallelArray: sig .. end
Parallel operations over arrays.

Most operations have the same signature as their original counterparts, but fold operations need an additional function in order to be able to "merge" the computations done on sub arrays.

Operations doing computations in parallel can be passed two optional parameters to set thread pool, and chunk size. It is possible to get rid of these optional parameters through the use of the Make functor.

If any parallel operation is used with a given pool, it is necessary to shutdown the pool. This applies in particular to default_pool, that can be shutdown through the shutdown_now function.



Thread pool

val default_pool : ThreadPoolExecutor.t
The default pool used for parallel computations, initialized with a size of Runtime.available_processors.
val shutdown_now : unit -> unit
Shutdowns default_pool.

Synonyms for sequential operations

val length : 'a array -> int
Synonym for Array.length.
val get : 'a array -> int -> 'a
Synonym for Array.get.
val set : 'a array -> int -> 'a -> unit
Synonym for Array.set.
val make : int -> 'a -> 'a array
Synonym for Array.make.
val create : int -> 'a -> 'a array
Synonym for Array.create.
val init : int -> (int -> 'a) -> 'a array
Synonym for Array.init.
val make_matrix : int -> int -> 'a -> 'a array array
Synonym for Array.make_matrix.
val create_matrix : int -> int -> 'a -> 'a array array
Synonym for Array.create_matrix.
val append : 'a array -> 'a array -> 'a array
Synonym for Array.append.
val concat : 'a array list -> 'a array
Synonym for Array.concat.
val sub : 'a array -> int -> int -> 'a array
Synonym for Array.sub.
val copy : 'a array -> 'a array
Synonym for Array.copy.
val fill : 'a array -> int -> int -> 'a -> unit
Synonym for Array.fill.
val blit : 'a array -> int -> 'a array -> int -> int -> unit
Synonym for Array.blit.
val to_list : 'a array -> 'a list
Synonym for Array.to_list.
val of_list : 'a list -> 'a array
Synonym for Array.of_list.

Parallel operations

val iter : ?pool:ThreadPoolExecutor.t ->
?chunk_size:int -> ('a -> unit) -> 'a array -> unit
Similar to Array.iter, except that computations are done in parallel; pool indicates the thread pool to use (defaulting to default_pool), while chunk_size indicates the size of each chunk to be allocated to a thread.
val map : ?pool:ThreadPoolExecutor.t ->
?chunk_size:int -> ('a -> 'b) -> 'a array -> 'b array
Similar to Array.map, except that computations are done in parallel; pool indicates the thread pool to use (defaulting to default_pool), while chunk_size indicates the size of each chunk to be allocated to a thread.
val iteri : ?pool:ThreadPoolExecutor.t ->
?chunk_size:int -> (int -> 'a -> unit) -> 'a array -> unit
Similar to Array.iteri, except that computations are done in parallel; pool indicates the thread pool to use (defaulting to default_pool), while chunk_size indicates the size of each chunk to be allocated to a thread.
val mapi : ?pool:ThreadPoolExecutor.t ->
?chunk_size:int -> (int -> 'a -> 'b) -> 'a array -> 'b array
Similar to Array.mapi, except that computations are done in parallel; pool indicates the thread pool to use (defaulting to default_pool), while chunk_size indicates the size of each chunk to be allocated to a thread.
val fold_left : ?pool:ThreadPoolExecutor.t ->
?chunk_size:int ->
('a -> 'b -> 'a) -> ('a -> 'a -> 'a) -> 'a -> 'b array -> 'a
Similar to Array.fold_left, except that computations are done in parallel; pool indicates the thread pool to use (defaulting to default_pool), while chunk_size indicates the size of each chunk to be allocated to a thread.

This version uses an additional function in order to be able to "merge" the computations done on sub arrrays.

val fold_right : ?pool:ThreadPoolExecutor.t ->
?chunk_size:int ->
('b -> 'a -> 'a) -> ('a -> 'a -> 'a) -> 'b array -> 'a -> 'a
Similar to Array.fold_right, except that computations are done in parallel; pool indicates the thread pool to use (defaulting to default_pool), while chunk_size indicates the size of each chunk to be allocated to a thread.

This version uses an additional function in order to be able to "merge" the computations done on sub arrrays.

val sort : ?pool:ThreadPoolExecutor.t ->
?chunk_size:int -> ('a -> 'a -> int) -> 'a array -> unit
Similar to Array.sort, except that computations are done in parallel; pool indicates the thread pool to use (defaulting to default_pool), while chunk_size indicates the size of each chunk to be allocated to a thread.

The current implementation has a O(n) space complexity.

val stable_sort : ?pool:ThreadPoolExecutor.t ->
?chunk_size:int -> ('a -> 'a -> int) -> 'a array -> unit
Synonym for ParallelArray.sort.
val fast_sort : ?pool:ThreadPoolExecutor.t ->
?chunk_size:int -> ('a -> 'a -> int) -> 'a array -> unit
Synonym for ParallelArray.sort.

Functor

module type OptionalParameters = sig .. end
Signature of ParallelArray.Make parameter.
module type S = sig .. end
Similar to module type of Array, except for fold operations.
module Make: 
functor (OP : OptionalParameters) -> S
Functor building an implementation with no optional parameter, thus compatible with the Array module (except for fold operations).