- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
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
Link Copied
1 Reply
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page