cilk_for and array notation with gcc

cilk_for and array notation with gcc


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.

3 posts / novo 0
Último post
Para obter mais informações sobre otimizações de compiladores, consulte Aviso sobre otimizações.

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

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.

Deixar um comentário

Faça login para adicionar um comentário. Não é membro? Inscreva-se hoje mesmo!