Nested for loops and two costly loops

Nested for loops and two costly loops

by Dave Bhullar -
Number of replies: 1

Hi Dr. van Zon,

Suppose we identify the loop that is the costly loop as being a nested for loop in one of the function files. Would a nested loop 

    for (size_t i = 1; i <= param.ngrid-2; i++) {

        for (size_t j = 1; j <= param.ngrid-2; j++) {

technically count as two costly loops? So say we parallelize this nested for loop with collapse(2), would that count for the requirement of parallelizing the two most costly loops? Or do we have to identify another costly loop apart from this nested for loop and parallelize that too to satisfy the requirement? Please let me know if you can.

Thank you.

In reply to Dave Bhullar

Re: Nested for loops and two costly loops

by Ramses van Zon -

No, the idea is that this nested loop counts as one loop.  Here, we're looping over a grid, and doing the same thing for each grid point; the only reason that there are two "for" statements is because it is a 2d grid. So you should find a second loop.