// from cilkplus.org
//
// compile with (gcc 4.9 plus; tested with 5.3.1)
// gcc -fcilkplus -lcilkrts -o parfib parfib.c
#include <cilk/cilk.h>
#include <cilk/cilk_api.h>
#include <stdio.h>
#include <stdlib.h>
long int fib(int n)
{
if (n < 2)
return n;
long int x = cilk_spawn fib(n-1);
long int y = fib(n-2);
cilk_sync;
return x + y;
}
int main(int argc, char **argv){
int n = atoi(argv[1]);
char *workerstr = argv[2];
if (workerstr)
__cilkrts_set_param("nworkers",workerstr);
printf("fib(%d) = %d\n", n, fib(n));
}