srecord noeq StupidFib_collab(ICollab collab, int n) { double timeout = 10.0; // if n <= parallelizationThreshold, we calculate serially gettable int parallelizationThreshold = 8; settable int delay = 0; // millisecond delay per add selfType parallelizationThreshold(int x) { parallelizationThreshold = max(3, x); this; } record noeq Step(int n, LongConsumer continuation) extends LongPairCollector is Runnable { void complete(long a, long b) { continuation.accept(add(a, b)); } run { // fallback to serial case if (n < parallelizationThreshold) ret with continuation.accept(serialComputation(n)); collab.addWork(new Step(n-1, setterForA())); collab.addWork(new Step(n-2, setterForB())); } } long serialComputation(int n) { ret stupidFib(n); } long get() { // serial or parallel? if (collab.coresToUse() == 1) ret serialComputation(n); else ret collab_computeLong(receiver -> new Step(n, receiver)); } long add(long a, long b) { if (delay > 0) sleep(delay); ret a+b; } }