Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

A.18 Nested for Directives

The following example of for directive nesting (Section 2.9 on page 33) is compliant because the inner and outer for directives bind to different parallel regions:

#pragma omp parallel default(shared)
{
    #pragma omp for
        for (i=0; i<n; i++) 
        {
            #pragma omp parallel shared(i, n)
            {
                #pragma omp for
                    for (j=0; j<n; j++)
                        work(i, j);
            }
        }
}

A following variation of the preceding example is also compliant:

#pragma omp parallel default(shared)
{
    #pragma omp for
        for (i=0; i<n; i++)
            work1(i, n);
}

void work1(int i, int n)
{
    int j;
    #pragma omp parallel default(shared)
    {
        #pragma omp for
            for (j=0; j<n; j++)
                work2(i, j);
    }
    return;
}
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.