PROTOTYPE
ParT is a parallel collection designed to coordinate complex workflows including but not limited to pipeline and speculative parallelism (based on the Encore Parallel combinators paper).
Asynchronous computations and values are lifted to the ParT abstraction, which can be controlled via the ParT combinators.
This library provides a function to spawn
asynchronus computations and these can be lifted into the ParT abstraction
via the liftf
combinator.
A task is an asynchronous computation that happens
in other working thread but synchronous computations can be added to the
parallel collection as well via the liftv
combinator. A spawned task
returns a CompletableFuture
value.
The following example spawns a task and returns a parallel collection:
(defn computation
[x]
(let [t (spawn (inc x))]
(liftf t))
Combinators provide high-level constructs for low-level management of the elements in the parallel collection:
||
(read par), creates a new parallel collection given a bunch of parallel collections:
(let [x1 (liftv (inc 1))
x2 (liftv (dec 23))]
(|| x1 x2))
>>
(read sequence), applies a function to each element in the collection asynchronously.
(defn par-example
[p]
(p >> inc >> inc))
extract
, combinator that moves a parallel collection to the sequential world, blocking until all the elements in the collection have finished their computation and returning an array.
(defn extract-example
[]
(let [x1 (liftv (inc 1))
x2 (liftv (dec 100))
p (| x1 x2)]
(extract p)))
TODO: Examples
Basic implementation of ParT with combinators:extract
,||
,liftf
,liftv
,>>
- Runtime optimisations with automatic scheduling decisions for maximal throughput
- Memoize frequently used functions that are free of side-effects
- Add
<<
combinator, which tracks down and safely stops speculative parallelism - Add more complex combinators
- Java 8
Copyright © 2015 Kiko Fernandez Reyes
Distributed under the MIT License.