-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathparallelism-demo.m2
53 lines (53 loc) · 1.06 KB
/
parallelism-demo.m2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
allowableThreads
allowableThreads = 4
f = name -> (
<< "starting " << name << endl;
for i to 2000000 do 0;
<< "ending " << name << endl;
name | " result");
t = createTask (f, "t")
isReady t
schedule t,isReady t
t
isReady t
taskResult t
t
taskResult t
u = apply("a" .. "p", i -> createTask(f,i))
isReady \ u
schedule \ u;
cancelTask \ u;
isReady \ u
taskResult \ u
p = createTask(f,"p")
q = createTask(f,"q")
r = createTask(f,"r")
addStartTask(p,r)
addStartTask(q,r)
schedule \ {p,q}
p,q,r
taskResult\{p,q,r}
p = createTask(f,"p")
q = createTask(f,"q")
addCancelTask(p,q)
addCancelTask(q,p)
schedule\{p,q}
p,q
taskResult\{p,q}
p = createTask(f,"p")
q = createTask(f,"q")
r = createTask(f,"r")
addDependencyTask(r,p)
addDependencyTask(r,q)
schedule p
p,q,r
schedule q
p,q,r
applyParallel = (L, f) ->(
collect := createTask identity;
tasks := for l in L list createTask(f,l);
for t in tasks do addDependencyTask (collect, t);
scan(tasks,schedule);
while not isReady collect do sleep 1;
taskResult \ tasks)
applyParallel({"a","b","c","d"},f)