cil_spawn ing a function

cil_spawn ing a function

How does one cilk_spawn the function:

isprime when it is called like this:

if (isprime(i)) {printf (%d ", i) };

it is embbeded in a if statements. i do not think thta

if(cilk_spawn (isprimei)) will work.

Any help appreciated.


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

You are correct in saying that if(cilk_spawn is_prime(i)) { printf("%d", i) } won't work.

On a syntactic level, "cilk_spawn is_prime(i)" is a statement, not an expression, so that code would not compile. One way toget a code that compiles is to declare a temporary to store the return value:

int is_prime_ans = cilk_spawn is_prime(i);
if (is_prime_ans) { printf("%d", i); }

On the other hand, since you need toreach a cilk_sync before you can read the value computed by "is_prime()", it is not useful to have the cilk_spawn unless there is some other code that can be executed before the cilk_sync.

Does that help for your actual code?



Leave a Comment

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