- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
[cpp]#include
#include
#include
cilk::reducer_opor
for (int i = 0; i < 2; i++) {
for (int j = 0; j < 2; j++) {
continueThis = cilk_spawn doStuff(i, j);
}
}
cilk_sync;
bool continue = continueThis.get_value();[/cpp]
[bash]MyCode.cpp(766): error: no operator "=" matches these operands
operand types are: cilk::reducer_opor
continueThis = cilk_spawn doStuff(i, j);
^[/bash]
The examples in the documentation use reducers of type
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You are correct. Assignment is not supported for reducer_opor. However, you can use set_value():
#includeint main(int argc, char **argv) { cilk::reducer_opor mine(true); mine.set_value(true); if (mine.get_value()) return 0; else return 1; }
- Barry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The limitation is on the reducer. If you added an assignment operator for reducer_opor, it should work.
Using a cilk_spawn in a loop is generally a bad idea. What you're saying is that the continuation of the loop hasto be stolen for everyiteration. In Cilk, spawns are(relatively) cheap. Steals are expensive. If your doStuff() routine doesn't do much, you're going to have a lot of overhead.
In contrast, cilk_foruses a hueristic to break the range into approximately 8*P "chunks" (P is the number of processors you've got). If your range is large, this means thateach chunk is a reasonable amount of work.
Itis tempting to recode your example as:
But thiswill run into false-sharing issues. Each read/modify/write cycle willinvalidate the cacheline containing continueThis on all other CPUs, resulting in delays.
- Barry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
continueThis[1] = cilk_spawn doStuff(0,1);
continueThis[2] = cilk_spawn doStuff(1,0);
continueThis[3] = cilk_spawn doStuff(1,1);
cilk_sync;
...[/bash] I'm not too worried about cache lines at this level---there is much more work in many of the subordinate functions.

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