Software Archive
Read-only legacy content
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.
17060 Discussions

next Cilk functions

newport_j
Beginner
686 Views


In a previous thread here (which I am now unable to now locate) I asked if it was okay to nest cilk_spawn functions. The reply was yes.

The next questions then is it okay to nest a cilk_spawn function call; with a cilk_for call. In other words cilk_spawn calls a function and in that function there is cilk_for?

I know that it is not a good idea to put cilk_spawn calls inside of a for or cilk_for function.


Newport_j
0 Kudos
3 Replies
Barry_T_Intel
Employee
686 Views
Yes, thisshould fine.

cilk_for is implemented in the compiler by lifting the cilk_for body into a lambda function, and passing that function into the Cilk runtime along with the grainsize and number of entries in your loop. The Cilk runtime then does a recursive divide-and-conquer; splitting the entries in (roughly) half, and spawning half and calling half, until the number of entries is less than the grainsize, at which point the lambda function is called to actually do the work.

You can nest cilk_for and cilk_spawn as much as you want and everything will work correctly. The limitation is imposed by the fact that a cilk_spawn has more overhead than a simple call. Not much; a cilk_spawn is about 4x the cost of a call. But still more. If you nest too deeply, you'll have excessive cilk_spawn overhead which will hurt performance.

As always, it's a matter of balance. The Cilkview Scalability Analyzer should be able to help you with this.

- Barry
0 Kudos
Daniel_Faken
Beginner
686 Views
Barry Tannenbaum wrote:
| The Cilkview Scalability Analyzer should be able to help you with this.

Has this been released somewhere? I don't see mention of it in the docs.

thanks,
Daniel
0 Kudos
Barry_T_Intel
Employee
686 Views
Oops. My bad. Wrong forum.

The Cilkscreen Race Detector and Cilkscreen Scalability Analyzer are shipped as part of the Cilk++ compiler available as a WhatIf package. The Cilk tools arenot yet available for Intel Cilk Plus.

- Barry
0 Kudos
Reply