Parallel computations based on a Fork-join model.

See dunaj.concurrent.parallel for parallel computations based on thread pools. See pipeline! if you want to work with channels.

Primary

ForkJoinPool

Available since version 1.0 (view source)

not referred automatically

TYPE

A forkjoin pool type.

See also: ForkJoinTask, invoke

ForkJoinTask

Available since version 1.0 (view source)

not referred automatically

TYPE

A forkjoin task type.

adapt

Available since version 1.0 (view source)

not referred automatically

Usage:
  • (adapt f)

Type signature:
  • (Function) → ForkJoinTask

Returns forkjoin task adapted from a function f.

See also: fork, join, invoke

fork

Available since version 1.0 (view source)

not referred automatically

Usage:
  • (fork t)

Type signature:
  • ((U ForkJoinTask Function)) → ForkJoinTask

Arranges to asynchronously execute t, it being a function or a forkjoin task. Returns forked task.

While not enforced or checked, the idiomatic use is to always call this function from inside the forkjoin pool (i.e. when running in another forkjoin task).

See also: adapt, join, invoke

inside-forkjoin?

Available since version 1.0 (view source)

not referred automatically

Usage:
  • (inside-forkjoin?)

Type signature:
  • () → Boolean+

Returns true if the current thread is executing as a ForkJoinPool computation, otherwise returns false.

invoke

Available since version 1.0 (view source)

not referred automatically

Usage:
  • (invoke pool f)

Type signature:
  • (ForkJoinPool ⨯ Function) → Any

Invokes f on the given pool, returning the result of the computation. Blocks until computation is finished. If the current thread is already in a fork join pool, invokes computation in the current thread.

join

Available since version 1.0 (view source)

not referred automatically

Usage:
  • (join t)

Type signature:
  • (ForkJoinTask) → Any

Returns the result of the computation task t when it is done.

JVM host specific: Throws RuntimeException or Error, not ExecutionException, if task has finished abnormally. Moreover, interrupts of the calling thread do not cause the method to abruptly return by throwing InterruptedException.

See also: fork, adapt, invoke

Folds

Additional helper functions for folds can be found at dunaj.coll.helper.

default-fold-pool

Available since version 1.0 (view source)

not referred automatically

VAR of type clojure.lang.Var

A dynamic var holding a default forkjoin pool.

default-fold-size

Available since version 1.0 (view source)

not referred automatically

VAR of type clojure.lang.Var

A dynamic var holding a default fold size.

See also: fold, transfold

fold

Available since version 1.0 (view source)

Usage:
  • (fold reducef coll)

  • (fold combinef reducef coll)

  • (fold n combinef reducef coll)

Type signatures:
  • (AnyFn ⨯ []) → Any

  • (AnyFn ⨯ AnyFn ⨯ []) → Any

  • (Integer+ ⨯ AnyFn ⨯ AnyFn ⨯ []) → Any

Returns the reduction of coll with reducef and with (combinef) as a starting value. Uses a potentially parallel reduce-combine strategy. The collection is partitioned into groups of approximately n (default to default-fold-size), each of which is reduced with reducef (with a seed value obtained by calling (combinef) with no arguments). The results of these reductions are then reduced with combinef (default reducef). Uses default-fold-pool as a forkjoin pool.

combinef must be associative, and, when called with no arguments, (combinef) must produce its identity element. These operations may be performed in parallel, but the results will preserve order.

fold-augmented

Available since version 1.0 (view source)

Usage:
  • (fold-augmented r coll)

  • (fold-augmented n r coll)

Type signatures:
  • (IReducing ⨯ []) → Any

  • (Integer+ ⨯ IReducing ⨯ []) → Any

Returns the result of folding of coll with augmented reducing function r. Uses a potentially parallel reduce-combine strategy. The collection is partitioned into groups of approximately n (default to default-fold-size). Uses default-fold-pool as a forkjoin pool.

folding

Available since version 1.0 (view source)

Usage:
  • (folding reducef)

  • (folding combinef reducef)

Type signatures:
  • (AnyFn) → IReducing

  • (AnyFn ⨯ AnyFn) → IReducing

Returns an augmented reducing function which uses reducef for reducing steps and combinef for initial value and for combining. Uses reducef for everything if combinef is not given.

transfold

Available since version 1.0 (view source)

Usage:
  • (transfold xform reducef coll)

  • (transfold xform combinef reducef coll)

Type signatures:
  • (AnyFn ⨯ AnyFn ⨯ []) → Any

  • (AnyFn ⨯ AnyFn ⨯ AnyFn ⨯ []) → Any

Returns the result of the folding of coll with the classic reducing function reducef, combining function combinef (uses reducef if not given), and transducer xform. Uses default-fold-pool as a forkjoin pool.