cil_spawn ing a function

cil_spawn ing a function

Ritratto di newport_j

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.

newport_j

2 post / 0 new
Ultimo contenuto
Per informazioni complete sulle ottimizzazioni del compilatore, consultare l'Avviso sull'ottimizzazione
Ritratto di Jim Sukha (Intel)

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);
cilk_sync;
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?

Cheers,

Jim

Accedere per lasciare un commento.