Module Parallel_kernelSource

Sourcemodule Hlist : sig ... end
type t : value mod contended non_float portable

t 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.

Sourceval sequential : t @@ portable

A trivial implementation of parallelism that runs all subtasks sequentially.

Sourceval sync : t @ local -> Await.Sync.t @ local @@ portable

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.

Sourcemodule Thunk : sig ... end
Sourceval fork_join : t @ local -> 'l Hlist.Gen(Thunk).t @ once shareable -> 'l Hlist.t @@ portable

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.

Sourceval fork_join2 : t @ local -> (t @ local -> 'a) @ local once shareable forkable -> (t @ local -> 'b) @ once shareable -> #('a * 'b) @@ portable

fork_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.

Sourceval fork_join3 : t @ local -> (t @ local -> 'a) @ local once shareable forkable -> (t @ local -> 'b) @ once shareable -> (t @ local -> 'c) @ once shareable -> #('a * 'b * 'c) @@ portable
Sourceval 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) @@ portable
Sourceval 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) @@ portable
Sourcemodule Biased : sig ... end
Sourceval for_ : t @ local -> start:Base.int -> stop:Base.int -> f:(t @ local -> Base.int -> Base.unit) @ shareable -> Base.unit @@ portable

for_ 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.

Sourceval 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 @@ portable

fold 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.

Sourceval heartbeat : t @ local -> n:Base.int -> Base.unit @@ portable

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.

Sourcemodule Lazy : sig ... end

A deferred computation.

Sourcemodule For_scheduler : sig ... end
Sourcemodule For_testing : sig ... end