#include #include #include #include #include int fib(int n) { // std::cout << "This is thread " << std::this_thread::get_id() // << std::endl; if(n<2) return(1); else { #ifdef WITHCILK int f1 = _Cilk_spawn fib(n-1); int f2 = _Cilk_spawn fib(n-2); _Cilk_sync; return (f1 + f2); #else return(fib(n-1) + fib(n-2)); #endif } } int main(int argc, char * argv []) { int n = atoi(argv[1]); std::vector v; std::chrono::time_point start, stop; start = std::chrono::system_clock::now(); for(int i=0; i<=n; i++) v.push_back(fib(i)); stop = std::chrono::system_clock::now(); std::chrono::duration elapsed_seconds = stop-start; for(int i=0; i<=n; i++) std::cout << "fib(" << i << ")=" << fib(i) << " "; std::cout << std::endl; std::cout << "Computed in " << elapsed_seconds.count() << " secs " << std::endl; return(0); }