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

cilk_for and array notation with gcc

leifblaese
Beginner
484 Views

Hi,

I have a question regarding the use of a cilk_for-loop and array-notation together, when using the gcc.

Imagine having a program, where you want to add two arrays of integers A,  B. One could do that, for example, either by using a cilk_for-loop, or by using array notation (e.g. A[0:size] + B[0:size]). Now, if i want to use array notation inside the cilk_for-loop, i run into a problem, because i have to specify the start and the length for the section-operator to work (because i am using gcc not an Intel compiler). I don't know how big the sections are that are created by the cilk_for-loop. Sure, i can specify a grainsize, but that is only an approximate measure, which means i could not guarantee to process the whole array A or B.

Still, the cilk_for-loop must have some variable that tells where to start and how long to run. My question is: Is there a way to access these information? If not, is it planned in a later version of cilk? I think that would be a neat feature because it would simplify the code a lot.

0 Kudos
2 Replies
jimdempseyatthecove
Honored Contributor III
484 Views
Conceptually you would do something like this: const int nSlices = 8; cilk_for(int i = 0; i < nSlices; ++i) { int iSize = ARRAY_SIZE / nSlices; int iBegin = iSize * i; if(i == (nSlices - 1)) iSize = ARRAY_SIZE - (iSize * (nSlices - 1)); A[iBegin:iSize] = B[iBegin:iSize] + C[iBegin:iSize]; } However, you would want to create a partitioner class as a helper Jim Dempsey
0 Kudos
leifblaese
Beginner
484 Views
Yes, that would work. However, it seems kind of redundant: The cilk_for-loop is already partitioning my array, thus it must have some partitioner class built in - if i could use that, i would not have to create one myself. I could rely on the cilk_for-loop to partition my array correctly, still have the grainsize as a measure of how many chunks of my array are created, have a simpler code, etc.
0 Kudos
Reply