The Path from Multicore to Manycore: Listing 2.

Parallel implementation of Fibonacci code.

int fib (int n) {
  if (n <= 2)
    return n;
  else {
    int x,y;
    x = cilk_spawn fib(n-1);
    y = fib(n-2);
    cilk_sync;
    return x+y;
  }
}
comments powered by Disqus

Featured

Subscribe on YouTube