I am very new to Cilk++ and I have read the manual a few times. So far I have not hadproblemsconverting C++ code into Cilk++ or compiling them into executable files. However I have not been able to achieve anyparallelism yet. So I must be doing something wrong.If anyone could kindly provide any advice, I would really appreciate it.
The work below was done exclusively ina 64-bit Unix workstation. The workstation is equipped with two quad-core CPUs (AMD Opteron Processor 2354) and 64Gb memory. Cilk++ was installed in the path /usr/local and therefore to call the compiler, I use/usr/local/cilk/bin/cilk++; to use the header file, I call /usr/local/cilk/include/cilk++/cilk.h.
hcui@cos:~$ pwd
/home/hcui
hcui@cos:~$ cat helloworld.race.cilk
#include
#include "/usr/local/cilk/include/cilk++/cilk.h"
using namespace std;
int n = 10; // declare a variable that is visible to three functions
void output() { cout << "n = " << n << endl; }
void strand1() { n = 1; }
void strand2() { n = 2; }
int cilk_main()
{
output(); // output current n value
cilk_spawn strand1(); // modify n value
strand2(); // modify n value again
cilk_sync;
output(); // output modified n value
}
hcui@cos:~$ /usr/local/cilk/bin/cilk++ helloworld.race.cilk -o helloworld.race.cilk.exe -O2
hcui@cos:~$ ./helloworld.race.cilk.exe
n = 10
n = 2
This is practically the same as the data race example from pp87-88 in the Cilk++ manual. I am expecting data race here. That means I want to see in the second line of the resultn = 2 or n = 1 depending on whether strand2() or strand1() wins the race. However theresult above stays the same after many runs and compilations. The result from cilkscreen though indicates data race.
I also wrotea program inCilk++ to createFibnacci numbers and, oddly Cilk++ running time was slower then the C++ code. However, when I checked with cilkview it does show the speedup. I guess it's also because I have not been able to achieve parallelism in that cilk code either.
I am not sure what went wrong and will really appreciate any directions and advice.
Regards,
Hailong



