Module Parallel_kernel

module Hlist : sig ... end
type t

t is the type of implementations of parallelism. Operations that produce parallel tasks take a t that provides an implementation of parallelism for them to use.

val sequential : t @@ portable

A trivial implementation of parallelism that runs all tasks sequentially.

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

fork_join t fs runs the functions in the heterogenous list f as parallel tasks and returns their results. If any task raises, this operation will reraise the leftmost exception after all tasks have completed or raised.

Child tasks must not block on each other or the parent task, but they may take locks.

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

fork_join2 t f g runs f and g as parallel tasks and returns their results. If either task raises, this operation will reraise the leftmost exception after both tasks have completed or raised. Child tasks must not block on each other or the parent task, but they may take locks.

f and g are shareable, so can capture both shared and uncontended references. This allows the tasks 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 -> ((t @ local -> 'b) @ once shareable -> ((t @ local -> 'c) @ once shareable -> #('a * 'b * 'c)) @ local once) @ local once) @ local @@ portable
val fork_join4 : t @ local -> ((t @ local -> 'a) @ local once shareable -> ((t @ local -> 'b) @ once shareable -> ((t @ local -> 'c) @ once shareable -> ((t @ local -> 'd) @ once shareable -> #('a * 'b * 'c * 'd)) @ local once) @ local once) @ local once) @ local @@ portable
val fork_join5 : t @ local -> ((t @ local -> 'a) @ local once shareable -> ((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)) @ local once) @ local once) @ local once) @ local once) @ local @@ portable
module Biased : sig ... end
val for_ : t @ local -> (start:Base.int -> (stop:Base.int -> (f:(t @ local -> (Base.int -> Base.unit) @ local) @ shareable -> Base.unit) @ local) @ local) @ local @@ portable

for_ t ~start ~stop ~f runs f t i as a parallel task 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 'seq. 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') @ local) @ local) @ shareable -> (stop:(t @ local -> ('acc -> 'ret) @ local) @ shareable -> (fork: (t @ local -> ('seq -> #('seq * 'seq) Unboxed_datatypes.Option_u.t__'value_or_null_value_or_null') @ local) @ shareable -> (join:(t @ local -> ('ret -> ('ret -> 'ret) @ local) @ local) @ shareable -> 'ret) @ local) @ local) @ local) @ local) @ local) @ local @@ 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.

module Scheduler : sig ... end
module For_scheduler : sig ... end
module For_testing : sig ... end