Software Archive
Read-only legacy content
17061 Discussions

wierd behaviour of cilk_for keyword

amandeepgautam
Beginner
909 Views
I am writting code in C90 and using cilkplus. I use a library which define TRY, CATCH macros to simulate the try catch behaviour similar to C++. Now the following piece of code compiles and runs as expected:

int j ;
for ( j=0; j<some_constant; ++j)
{
TRY {
//some code which throws exception
} CATCH(SQLException) {
//some action.
}
END_TRY;
}


but when the same code is run wth cilk_for keword, I get compile error
The code:

int j ;
cilk_for ( j=0; j<some_constant; ++j)
{
TRY {
//some code which throws exception
} CATCH(SQLException) {
//some action.
}
END_TRY;
}


Error:

main.c: In function __cilk_for_001:
main.c:459:4: error: Can not spawn call to function that returns twice


line 459 is the end of scope for cilk_for loop.

I know that we are allowed to use try catch in C++ code so I even tried C++ but therre also the compiler gave the same error message.

Any help appriciated!!
Thanks.

Additional information:

The macros are defined in databse connection pooling library libzdb written in c.
0 Kudos
6 Replies
Balaji_I_Intel
Employee
909 Views
Hello Aman,
Exception support is not fully implemented in CIlk Plus GCC.

Thanks,

Balaji V. Iyer.
0 Kudos
amandeepgautam
Beginner
909 Views
The following is an excerpt from cilk pluss manual (http://www.google.com/url?sa=t&rct=j&q=try%20catch%20cilk_for&source=web&cd=3&ved=0CFgQFjAC&url=http%3A%2F%2Fsoftware.intel.com%2Ffile%2F28680&ei=hUIPUIjVKoreqAGF94DwDw&usg=AFQjCNG7y2OGBpiRK4b-dcyU4WIK1OOKNA&cad=rja) :

If an exception is thrown from within a
cilk_for loop body (and not handled within the same
iteration), then some of the loop iterations may not run. Unlike a serial execution, it is not
completely predictable which iterations will run and which will not. No iteration (other than the one
throwing the exception) is aborted in the middle.

In the same manual there are examples which show implementation using of try catch block. Can you suggest some work around this The error itself is pretty unexplanatory.
0 Kudos
Barry_T_Intel
Employee
909 Views
The easiest thing to try would be to take your try/catch block and put it into it's own function, and invoke that in your loop.

- Barry
0 Kudos
amandeepgautam
Beginner
909 Views
Would you please explain what do you mean by writting your own try catch block. I could not get what you mean, I am new to these situation, but if you can give me some reference (or an example) on what you suggested I can make my way through. Thanks!!
0 Kudos
Barry_T_Intel
Employee
909 Views

What I told you to do was to put the try/catch block in it's own function. Here's the code you posted:

int j ;
cilk_for ( j=0; j

Modify the code by putting the try/catch block in it's own function. Something like:

void do_try_catch_block()
{
    TRY {
          //some code which throws exception
     } CATCH(SQLException) {
          //some action.
     }
     END_TRY;
}

int j ;
cilk_for ( j=0; j

Of course you'll have to pass a bunch of parameters into the function, but this should isolate the exception handling from the lambda function the compiler will make out of the cilk_for loop body.

- Barry

0 Kudos
jimdempseyatthecove
Honored Contributor III
909 Views
Try something like this:

int unhandledCatch = 0;
int j ;
cilk_for ( j=0; j<some_constant; ++j)
{
TRY {
//some code which throws exception
} CATCH(SQLException) {
//some action.
} CATCH(...) {
// unhandled catch to avoid implicit throw return
unhandledCatch = 1;// or your choice
}
END_TRY;
}
if(unhandledCatch)
... // do something here

Jim Dempsey
0 Kudos
Reply