Download HP UPC Unified Parallel C (UPC) Programmer`s Guide
Transcript
Language Features 2.12 Statements upc_wait Waits for all other threads to reach the upc_notify statement. The programmer is allowed to specify execution of statements not involving any references to shared data between the execution of the upc_notify and upc_wait statements. upc_barrier Performs the combined functions of a upc_notify and a upc_wait. The upc_barrier statement is used when there is no need to do any additional local-only work between the notification and the wait. There is an implicit upc_fence before a upc_notify and after a upc_wait. Example 2–4 Barrier Statements upc_barrier; upc_notify 2; ... upc_wait 2; // Notify+wait, default tag of 0 // Notify thread has reached point 2 // Do some additional local-only work // Waits for other threads to get here Example 2–5 Value Matching for Barrier Statements Thread 0 upc_barrier 1; upc_barrier; upc_barrier 3; Thread 1 barrier 1; // Values match barrier 2; // Null value matches value barrier 4; // Values do not match, error There must always be a upc_wait following (at some point) a upc_notify with the same tag value. There cannot be a upc_wait with a different tag value, nor another upc_notify statement, following the upc_notify. Similarly, any upc_wait statement must be preceded by a upc_notify with the same tag value; two upc_wait statements, or a upc_barrier followed by a upc_wait statement, are not allowed. UPC does not provide a mechanism for forcing a subset of threads to synchronize at a barrier. All threads must perform the synchronization. 2.12.3 Nested upc_forall Loops To ensure coverage of all iterations of a nested series of loops, only one affinity expression will be honored at a time. This rule affects nested upc_forall loops, including those reached by function calls from within other upc_forall loops. If such a loop is entered while another one is active, the affinity expression will not be evaluated, and the body of the loop will be executed without further conditions. If a upc_forall loop is physically inside another upc_forall loop, and both have non-null affinity expressions, the affinity expression for the inner loop is meaningless, since all iterations would be executed anyway due to the presence of the outer loop. The compiler will detect this case and ignore the inner loop’s affinity expression. Language Features 2–19