Parallel_kernelSourcet is the type of implementations of parallelism. Operations that produce parallel subtasks take a t that provides an implementation of parallelism for them to use.
A trivial implementation of parallelism that runs all subtasks sequentially.
sync t is an Await.Sync.t that may be used to acquire locks inside parallel functions. To do nested parallelism while holding a lock, use Parallel.Capsule.
fork_join t fs runs the functions in the heterogenous list f as parallel subtasks and returns their results. If any subtask raises, this operation will reraise the leftmost exception after all subtasks have completed or raised.
val fork_join2 :
t @ local ->
(t @ local -> 'a) @ local once shareable forkable ->
(t @ local -> 'b) @ once shareable ->
#('a * 'b) @@ portablefork_join2 t f g runs f and g as parallel subtasks and returns their results. If either subtask raises, this operation will reraise the leftmost exception after both subtasks have completed or raised.
f and g are shareable, so can capture both shared and uncontended references. This allows the subtasks to read (but not mutate) state from the environment. f is also forkable, so cannot capture capsule passwords.
val fork_join3 :
t @ local ->
(t @ local -> 'a) @ local once shareable forkable ->
(t @ local -> 'b) @ once shareable ->
(t @ local -> 'c) @ once shareable ->
#('a * 'b * 'c) @@ portableSee fork_join2
val fork_join4 :
t @ local ->
(t @ local -> 'a) @ local once shareable forkable ->
(t @ local -> 'b) @ once shareable ->
(t @ local -> 'c) @ once shareable ->
(t @ local -> 'd) @ once shareable ->
#('a * 'b * 'c * 'd) @@ portableSee fork_join2
val fork_join5 :
t @ local ->
(t @ local -> 'a) @ local once shareable forkable ->
(t @ local -> 'b) @ once shareable ->
(t @ local -> 'c) @ once shareable ->
(t @ local -> 'd) @ once shareable ->
(t @ local -> 'e) @ once shareable ->
#('a * 'b * 'c * 'd * 'e) @@ portableSee fork_join2
val for_ :
t @ local ->
start:Base.int ->
stop:Base.int ->
f:(t @ local -> Base.int -> Base.unit) @ shareable ->
Base.unit @@ portablefor_ t ~start ~stop ~f runs f t i as a parallel subtask for each i in the range start..stop-1.
If any invocation of f raises, this operation will reraise the leftmost exception. If an exception occurs at index i, f may or may not be invoked for any j > i.
val fold :
('acc : value_or_null) ('seq : value_or_null mod shareable shared).
t @ local ->
init:(Base.unit -> 'acc) @ portable ->
state:'seq ->
next:
(t @ local ->
'acc ->
'seq ->
#('acc * 'seq)
Unboxed_datatypes.Option_u.t__'value_or_null_value_or_null') @ shareable ->
stop:(t @ local -> 'acc -> 'ret) @ shareable ->
fork:
(t @ local ->
'seq ->
#('seq * 'seq)
Unboxed_datatypes.Option_u.t__'value_or_null_value_or_null') @ shareable ->
join:(t @ local -> 'ret -> 'ret -> 'ret) @ shareable ->
'ret @@ portablefold t ~init ~state ~next ~stop ~fork ~join folds an accumulator over a sequence of states generated by next. The initial accumulator is init () and the initial state is state. At each step, next t state acc is applied to get the next accumulator and state. When next returns None, the current accumulator is passed to stop and then returned as the result of fold.
init, stop, fork, and join allow the scheduler to split states into parts that may be folded in parallel, then recombined with join. Given a state s, fork s returns two states s0, s1 such that:
stop (fold acc s) = join (stop (fold acc s0)) (stop (fold (init ()) s1))
The operation implemented by the callbacks must be associative, and init must return a neutral element. If this is not the case, results will be non-deterministic.
heartbeat t ~n allows n subtasks to be promoted to tasks. If there are fewer than n subtasks in the current queue, the remaining count will be used to eagerly promote new subtasks. If n < 0, the next n promotions will be skipped.