Reputation: 85
I downloaded Intel Parallel Studio and then went to the command and entered:
source /opt/intel/bin/compilervars.sh intel64
followed by: icpc file.cpp
to run a Cilk plus file.
The file.cpp is a simplified version of an original example used in cilkplus.org so it should work but it produces a segmentation fault
here's the file I'm trying to run using cilk plus compiler:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int fib(int n)
{
if (n < 2)
return n;
int x = cilk_spawn fib(n-1);
int y = fib(n-2);
cilk_sync;
return x + y;
}
int main(int argc, char *argv[])
{
int n = 39;
clock_t start = clock();
int result = fib(n);
clock_t end = clock();
double duration = (double)(end - start) / CLOCKS_PER_SEC;
printf("Calculated in %.3f seconds using %d workers.\n", duration, __cilkrts_get_nworkers());
return 0;
}
Upvotes: 0
Views: 170
Reputation: 343
I think the problem is 39.
The code looks right to me. While I have never worked with cilk, yet from what I get the code seems right considering you did copy it.
My guess would be 39 is a number too big. Try smaller or bigger numbers.
If it works, remove all the duration nonsense and try a loop for fib(i) for first 40 cases. Use the simpler version before you mess it up.
Upvotes: 1