OpenMP clauses 的用法

1. private / firstprivate / lastprivate / threadprivate

2. nowait

3. task



2.   nowait 的使用 

OpenMP clauses 的用法_第1张图片

nowait & schedule(static) 

In the following example, static scheduling distributes the same logical iteration numbers to the threads that execute the three loop regions. This allows the nowait clause to be used, even though there is a data dependence between the loops. The dependence is satisfied as long the same thread executes the same logical iteration numbers in each loop.

Note that the iteration count of the loops must be the same. The example satisfies this requirement, since the iteration space of the first two loops is from 0 to n-1 (from 1 to N in the Fortran version), while the iteration space of the last loop is from 1 to n (2 to N+1 in the Fortran version).




2. 以及 collapse 的使用 

OpenMP clauses 的用法_第2张图片

 chedule(static,3)

The next example illustrates the interaction of the collapse and ordered clauses.

In the example, the loop construct has both a collapse clause and an ordered clause. Thecollapse clause causes the iterations of the k and j loops to be collapsed into one loop with a larger iteration space, and that loop is divided among the threads in the current team. An orderedclause is added to the loop construct, because an ordered region binds to the loop region arising from the loop construct.

According to Section 2.12.8 of the OpenMP 4.0 specification, a thread must not execute more than one ordered region that binds to the same loop region. So the collapse clause is required for the example to be conforming. With the collapse clause, the iterations of the k and j loops are collapsed into one loop, and therefore only one ordered region will bind to the collapsed k and jloop. Without the collapse clause, there would be two ordered regions that bind to each iteration of the k loop (one arising from the first iteration of the j loop, and the other arising from the second iteration of the j loop).

The code prints

011 

012 

021 

122 

131 

132

你可能感兴趣的:(OpenMP clauses 的用法)