cilk_spawn inside cilk_for

cilk_spawn inside cilk_for


For some reason, whenever I have a spawn and sync inside a cilk_for it seems as though the spawn does not get recognized.  I end up getting a compile time error of Expected _Cilk_spawn before _Cilk_sync.  As an example consider the following (overly simple) program:

void foo(){
    cout << "foo";

void bar(){
    cout << "bar";

void baz(){
    cout << "baz";

int main(){
    cilk_for(int i-0; i<10; i++){
        cilk_spawn foo();


If I try to compile this I get the above mentioned error.  Does anyone have any idea as to why this might be happening and/or how I can solve it.  (If I move the spawn and sync into a separate helper method it solves the problem, but unfortunately in my real use case it would mean passing a lot of variables by pointer.)  I am using g++ 4.8.1 with cilkplus.


  - Meir

3 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

It's a bug in the gcc implementation. icc compiled it without complaint (after I fixed the "int i-0" typo and added the obvious includes/using).  I'll try to get this reported to the code maintainer.

Yes, this looks like a bug in GCC's Cilkplus branch. Unfortunately there are no plans to support separate branches anymnore since now we are integrating Cilk_for support into the GCC trunk (it will be version 5.0) thus all Cilk+ features will be there together. Of course, we will make sure that given test works in the trunk after we finish integration

Leave a Comment

Please sign in to add a comment. Not a member? Join today