module ParallelArray:sig
..end
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.
val default_pool : ThreadPoolExecutor.t
Runtime.available_processors
.val shutdown_now : unit -> unit
default_pool
.val length : 'a array -> int
Array.length
.val get : 'a array -> int -> 'a
Array.get
.val set : 'a array -> int -> 'a -> unit
Array.set
.val make : int -> 'a -> 'a array
Array.make
.val create : int -> 'a -> 'a array
Array.create
.val make_matrix : int -> int -> 'a -> 'a array array
Array.make_matrix
.val create_matrix : int -> int -> 'a -> 'a array array
Array.create_matrix
.val append : 'a array -> 'a array -> 'a array
Array.append
.val concat : 'a array list -> 'a array
Array.concat
.val sub : 'a array -> int -> int -> 'a array
Array.sub
.val copy : 'a array -> 'a array
Array.copy
.val fill : 'a array -> int -> int -> 'a -> unit
Array.fill
.val blit : 'a array -> int -> 'a array -> int -> int -> unit
Array.blit
.val to_list : 'a array -> 'a list
Array.to_list
.val of_list : 'a list -> 'a array
Array.of_list
.val init : ?pool:ThreadPoolExecutor.t ->
?chunk_size:int -> int -> (int -> 'a) -> 'a array
Array.init
, 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.
Raise Invalid_argument
if passed size is negative or above
Sys.max_array_length
.
Raises Runtime.Raised
if the passed function raises an exception.
val iter : ?pool:ThreadPoolExecutor.t ->
?chunk_size:int -> ('a -> unit) -> 'a array -> unit
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.
Raises Runtime.Raised
if the passed function raises an exception.
val map : ?pool:ThreadPoolExecutor.t ->
?chunk_size:int -> ('a -> 'b) -> 'a array -> 'b array
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.
Raises Runtime.Raised
if the passed function raises an exception.
val iteri : ?pool:ThreadPoolExecutor.t ->
?chunk_size:int -> (int -> 'a -> unit) -> 'a array -> unit
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.
Raises Runtime.Raised
if the passed function raises an exception.
val mapi : ?pool:ThreadPoolExecutor.t ->
?chunk_size:int -> (int -> 'a -> 'b) -> 'a array -> 'b array
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.
Raises Runtime.Raised
if the passed function raises an exception.
val fold_left : ?pool:ThreadPoolExecutor.t ->
?chunk_size:int ->
('a -> 'b -> 'a) -> ('a -> 'a -> 'a) -> 'a -> 'b array -> 'a
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.
Raises Runtime.Raised
if any of the passed functions raises an exception.
val fold_right : ?pool:ThreadPoolExecutor.t ->
?chunk_size:int ->
('b -> 'a -> 'a) -> ('a -> 'a -> 'a) -> 'b array -> 'a -> 'a
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.
Raises Runtime.Raised
if any of the passed functions raises an exception.
val sort : ?pool:ThreadPoolExecutor.t ->
?chunk_size:int -> ('a -> 'a -> int) -> 'a array -> unit
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.
Raises Runtime.Raised
if the passed function raises an exception.
val stable_sort : ?pool:ThreadPoolExecutor.t ->
?chunk_size:int -> ('a -> 'a -> int) -> 'a array -> unit
ParallelArray.sort
.val fast_sort : ?pool:ThreadPoolExecutor.t ->
?chunk_size:int -> ('a -> 'a -> int) -> 'a array -> unit
ParallelArray.sort
.val mem : ?pool:ThreadPoolExecutor.t -> ?chunk_size:int -> 'a -> 'a array -> bool
mem ~pool ~chunk_size x a
returns true
iff there is an element
e
of a
such that e = x
. 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 memq : ?pool:ThreadPoolExecutor.t -> ?chunk_size:int -> 'a -> 'a array -> bool
memq ~pool ~chunk_size x a
returns true
iff there is an element
e
of a
such that e == x
. 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 exists : ?pool:ThreadPoolExecutor.t ->
?chunk_size:int -> ('a -> bool) -> 'a array -> bool
exists ~pool ~chunk_size f a
returns true
iff there is an element
e
of a
such that f e = true
. 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 for_all : ?pool:ThreadPoolExecutor.t ->
?chunk_size:int -> ('a -> bool) -> 'a array -> bool
for_all ~pool ~chunk_size f a
returns true
iff there is no element
e
of a
such that f e = false
. 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 find : ?pool:ThreadPoolExecutor.t ->
?chunk_size:int -> ('a -> bool) -> 'a array -> 'a
find ~pool ~chunk_size f a
returns an element e
of a
such that
f e = true
, raising Not_found
if there is no such element in a
.
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.
Returns any element matching the condition, not guaranteeing that
the one with the lowest index is returned.
val find_index : ?pool:ThreadPoolExecutor.t ->
?chunk_size:int -> ('a -> bool) -> 'a array -> int
find
, except that the index is returned.val find_all : ?pool:ThreadPoolExecutor.t ->
?chunk_size:int -> ('a -> bool) -> 'a array -> 'a list
find_all ~pool ~chunk_size f a
returns all the elements of a
that
return true
when applied to f
, preserving the order of the
elements in a
.module type OptionalParameters =sig
..end
ParallelArray.Make
parameter.
module type S =sig
..end
module type of Array
, except for fold operations.
module Make:
Array
module (except for fold
operations).