The following examples show how to use several OpenMP* features.
This example shows a simple parallel loop where the amount of work in each iteration is different. Dynamic scheduling is used to improve load balancing.
The END DO directive has a NOWAIT clause because there is an implicit barrier at the end of the parallel region. Therefore it is not necessary to also have a barrier at the end of the DO region.
Example |
---|
|
This example uses two parallel loops fused to reduce fork/join overhead. The first END DO directive has a NOWAIT clause because all the data used in the second loop is different than all the data used in the first loop.
Example |
---|
|
This example demonstrates the use of the SECTIONS directive. The logic is identical to the preceding DO directive example, but uses a SECTIONS directive instead of a DO directive. Here the speedup is limited to two because there are only two units of work whereas in the example above there are (n-1) + (m-1) units of work.
Example |
---|
|
This example demonstrates how to use a SINGLE construct to update an element of the shared array a. The optional NOWAIT clause after the first loop is omitted because it is necessary to wait at the end of the loop before proceeding into the SINGLE construct to avoid a race condition.
Example |
---|
|