Nested For loops

Nested For loops

I underdstand that cilk_spawn and cilk_for can be nested. What I would like to know is what do you do about nested for loops? It seems that it might be okay to make the outer loop cilk_for, but oneshould not make the inner loop cilk_for.

Also, I have some legacy code that has some loops other than for, such as do while. Is the anything I can do about them? Is there some instruction for rewriting these loopsto for loops?

Newport_j

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

> I underdstand that cilk_spawn and cilk_for can be nested. What I would like to know is what do you
>do about nested for loops? It seems that it might be okay to make the outer loop cilk_for, but one
>should not make the inner loop cilk_for.

Nested cilk_for loops are no different from nesting cilk_for and cilk_spawn. Again, it's a balance thing. If you've got too little work in your spawned code, you'll have too much overhead. For example, in the loop

for (int x = 0; x I'd probably only make the outer loop a cilk_for loop, assuming that xmax was big enough, and there weren't race conditions introduced by parallelizing the outermost loop. The matrix-multiple sample gives an example of this.

> Also, I have some legacy code that has some loops other than for, such as do while. Is the anything
>I can do about them? Is there some instruction for rewriting these loops to for loops?

I've seen examples that gathers data in "chunks" together in a do/while loop, and then uses a cilk_for to parallelize the chunk. Something like:

while (! done)
{
    data a[256];
    int i = 0;

    while ((! done) && (i 

Deixar um comentário

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