| 1 | In general the structure of an OMP Parallel statement looks like this:
|
|---|
| 2 |
|
|---|
| 3 | #pragma omp parallel
|
|---|
| 4 | {
|
|---|
| 5 | S1
|
|---|
| 6 | #pragma omp ...
|
|---|
| 7 | S2
|
|---|
| 8 | S3
|
|---|
| 9 | }
|
|---|
| 10 |
|
|---|
| 11 | Where the parallel contains regions of C code, e.g., S1, S3, that
|
|---|
| 12 | are executed by each thread, and OMP statements, e.g., S2, which
|
|---|
| 13 | control how threads are executed by threads. OMP worksharing and
|
|---|
| 14 | synchronization statements have different semantics from parallel
|
|---|
| 15 | (and enclosing workshares), but the principle is the same.
|
|---|
| 16 |
|
|---|
| 17 | To perform an independence analysis each region of the program which
|
|---|
| 18 | may execute in parallel must be subjected to analysis.
|
|---|
| 19 |
|
|---|
| 20 | This requires that the barrier semantics of OMP constructs be
|
|---|
| 21 | made explicit and that an analysis collects all sets of potentially
|
|---|
| 22 | parallel regions. See a summary of implicit barriers and other
|
|---|
| 23 | thread-ordering related OMP statements below.
|
|---|
| 24 |
|
|---|
| 25 | An interesting challenge arises due to the nesting of OMP statements
|
|---|
| 26 | within control flow constructs and the "shape" of the regions that
|
|---|
| 27 | may arise. For example:
|
|---|
| 28 |
|
|---|
| 29 | #pragma omp parallel
|
|---|
| 30 | if (c)
|
|---|
| 31 | #pragma omp for
|
|---|
| 32 | S1
|
|---|
| 33 | else
|
|---|
| 34 | S2
|
|---|
| 35 |
|
|---|
| 36 |
|
|---|
| 37 | Independence comes down to whether two potentially parallel regions
|
|---|
| 38 | may exhibit a read-write dependence. These dependences arise from
|
|---|
| 39 | accesses to shared variables including shared arrays where the index
|
|---|
| 40 | expressions cannot be determined to be disjoint.
|
|---|
| 41 |
|
|---|
| 42 | --------------------------------------------------
|
|---|
| 43 | Barrier semantics for OMP statements:
|
|---|
| 44 |
|
|---|
| 45 | parallel
|
|---|
| 46 | end barrier
|
|---|
| 47 |
|
|---|
| 48 | critical
|
|---|
| 49 | no barrier, but special semantics should be considered to improve
|
|---|
| 50 | precision of independence analysis
|
|---|
| 51 |
|
|---|
| 52 | region within critical will never be executed in multiple threads
|
|---|
| 53 |
|
|---|
| 54 | barrier
|
|---|
| 55 | end barrier
|
|---|
| 56 |
|
|---|
| 57 | atomic
|
|---|
| 58 | no barrier, but special semantics should be considered to improve
|
|---|
| 59 | precision of independence analysis
|
|---|
| 60 |
|
|---|
| 61 | ordered
|
|---|
| 62 | no barrier, but special semantics should be considered to improve
|
|---|
| 63 | precision of independence analysis
|
|---|
| 64 |
|
|---|
| 65 | for
|
|---|
| 66 | end barrier
|
|---|
| 67 |
|
|---|
| 68 | for nowait
|
|---|
| 69 |
|
|---|
| 70 | sections
|
|---|
| 71 | end barrier
|
|---|
| 72 |
|
|---|
| 73 | sections nowait
|
|---|
| 74 |
|
|---|
| 75 | section
|
|---|
| 76 |
|
|---|
| 77 | single
|
|---|
| 78 | end barrier
|
|---|
| 79 |
|
|---|
| 80 | single nowait
|
|---|
| 81 |
|
|---|
| 82 |
|
|---|