-
Notifications
You must be signed in to change notification settings - Fork 26
Tasks in Encore
Here is a tentative fibonacci number calculation in Encore using a strawman task library design:
class Fib
def fib(n:int) : int
if n < 2 then n else
let
x = 0
y = 0
in {
finish {
async { fib(n - 1) }
async { fib(n - 2) }
}
x + y
}
This uses X10 style async
and finish
which becomes less
elegant with the way we handle local variables. In any case, I am
proposing to push async
and finish
primitives. Here is how we
could write the program in a better way using a let
-like finish
construct:
class Fib
def fib(n:int) : int
if n < 2 then n else
finish
x = async fib(n - 1)
y = async fib(n - n)
in
x + y
One important question is how to integrate with the actor-driven parallelism of PonyRT. The following is a strawman proposal for this:
My feeling was that the task lib was something that went on under the hood, as the target of (some) running closures and the party types.
The core above code could be expressed something like, assuming that reduce
exists:
or, synchronising first, then calling sequential foldl
:
foldl (+) (sync (fib (n - 1) | fib n))