|
Future<String> aFuture = future(()->{
return "A"; }); Future<String> bFuture = future(await(aFuture), ()->{ String a = aFuture.get(); return a + "B"; }); Future<String> cFuture = future(await(aFuture), ()->{ String a = aFuture.get(); return a + "C"; }); Future<String> dFuture = future(await(bFuture), ()->{ String b = bFuture.get(); return b + "D"; }); Future<String> eFuture = future(await(bFuture, cFuture), ()->{ String b = bFuture.get(); String c = cFuture.get(); return b + c + "E"; }); Future<String> fFuture = future(await(cFuture), ()->{ String c = cFuture.get(); return c + "F"; }); Future<String> gFuture = future(await(eFuture, fFuture), ()->{ String e = eFuture.get(); String f = fFuture.get(); return e + f + "G"; }); //H async(await(dFuture, gFuture), ()->{ String d = dFuture.get(); String g = gFuture.get(); System.out.println(d + g + "H"); }); |
Draw the dataflow graph: |
|
Phaser
phaser
=
new
Phaser(); s1 can run in parallel with: _________________ s2 can run in parallel with: _________________ s3 can run in parallel with: _________________ s4 can run in parallel with: _________________ s5 can run in parallel with: _________________ s6 can run in parallel with: _________________ |
Draw the computation graph: |
| read(0) W=1 | |||
| read(1) W=1 | compress(0) W=4 | ||
| read(2) W=1 | compress(1) W=4 | encrypt(0) W=2 | |
| read(3) W=1 | compress(2) W=4 | encrypt(1) W=2 | write(0) W=3 |
| read(4) W=1 | compress(3) W=4 | encrypt(2) W=2 | write(1) W=3 |
| read(5) W=1 | compress(4) W=4 | encrypt(3) W=2 | write(2) W=3 |
| read(6) W=1 | compress(5) W=4 | encrypt(4) W=2 | write(3) W=3 |
| read(7) W=1 | compress(6) W=4 | encrypt(5) W=2 | write(4) W=3 |
| read(8) W=1 | compress(7) W=4 | encrypt(6) W=2 | write(5) W=3 |
| read(9) W=1 | compress(8) W=4 | encrypt(7) W=2 | write(6) W=3 |
| compress(9) W=4 | encrypt(8) W=2 | write(7) W=3 | |
| encrypt(9) W=2 | write(8) W=3 | ||
| write(9) W=3 |