Tuesday, February 17, 2009

toy language

For a mini-assignment, we were supposed to pick a few problem types and sketch a language to run them in parallel. I picked unstructured grid, pipes, and events. The idea is to step down from FRP a bit to be more Esterel-like, and to add an explicit spawn call for events.

Some fun snippets:

Warmup:


var mypipe = <||> //a new pipe!
var mypipe2 = <mypipe + 1> //returns a new pipe
<mypipe> ! 20 //inject an event into the pipeline, updating mypipe and mypipe2
ticks(1) ||| \_. assert(mypipe + 1 == mypipe2)
assert(mypipe2 == 21)
assertException(\_.<mypipe> + 1)
assert(<mypipe> != <mypipe2>)


Bounded parallelism:


//input: var source =

var batches =
<source>.foldE(\(v,acc). if acc.length == 100: [v]
else: acc.push(v)
acc,
[])
.filterE(\a. a.length == 100)
function decrypt (v) v
var workers = [ batches ||| spawn()
||| map(\arr. decrypt(arr[x]))
for x in range(100) ]
workers.merge()


Data partitioning:

var graph = {v: <|1|>,
owner: root,
neighbors: [root,
{v: <|2|>, neighbors: [], owner: root},
{v: <|3|>, neighbors: [], owner: root}]}
partition p;
for n in graph:
var r = n.owner.neighbors.foldi(
\(val,i,acc). acc ? acc : (val == n ? i : acc))
n.__region = n.neighbors.__region = p[r]
for n in graph:
n.v’ = <|average(spawn(n.__partition)(
n.neighbors.map(\n. n.v)))|>
ticks(999) ||| \_. for n in root: <n.v> ! n.v’

No comments: