wierd behaviour of cilk_for keyword

wierd behaviour of cilk_for keyword

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.

7 posts / 0 nouveau(x)
Dernière contribution
Reportez-vous à notre Notice d'optimisation pour plus d'informations sur les choix et l'optimisation des performances dans les produits logiciels Intel.

Hello Aman,
Exception support is not fully implemented in CIlk Plus GCC.

Thanks,

Balaji V. Iyer.

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...) :

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.

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

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!!

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

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

www.quickthreadprogramming.com

Laisser un commentaire

Veuillez ouvrir une session pour ajouter un commentaire. Pas encore membre ? Rejoignez-nous dès aujourd’hui