| United States-English |
|
|
|
![]() |
Parallel Programming Guide for HP-UX Systems > Chapter 6 Data
privatizationPrivatizing region variables |
|
Regional privatization is manually specified using the parallel_private directive or pragma. parallel_private is provided to declare a list of variables and/or arrays private to the immediately following parallel region. It serves the same purpose for parallel regions as task_private does for tasks, and loop_private does for loops. The parallel_private directive must immediately precede, or appear on the same line as, its corresponding parallel directive. Using parallel_private asserts that there are no dependences in the parallel region. Do not use parallel_private if there are dependences. Each parallel thread of execution receives a private copy of the parallel_private data object for the duration of the region. No starting or ending values are assumed for the data. If a parallel_private data object is referenced within a region, it must have been previously assigned a value in the region. The form of this directive and pragma is shown in Table 6-5 “Form of parallel_private directive and pragma”. Table 6-5 Form of parallel_private directive and pragma
where
parallel_private privatizes regions:
This example checks for a certain number of threads and divides up the work among those threads. The example additionally introduces the parallel_private variable AWORK. Each thread initializes its private copy of AWORK to the values contained in a dimension of the array A at the beginning of the parallel region. This allows the threads to reference AWORK without regard to thread ID. This is because no thread can access any other thread’s copy of AWORK. Because AWORK cannot carry values into or out of the region, it must be initialized within the region. All induction variables contained in a parallel region must be privatized. Code contained in the region runs on all available threads. Failing to privatize an induction variable would allow each thread to update the same shared variable, creating indeterminate loop counts on every thread. In the previous example, in the J loop, after AWORK is initialized, AWORK is effectively used in a reduction on A; at this point its contents are identical to the MYTID dimension of A. After A is modified and used in the K and L loops, each thread restores a dimension of A’s original values from its private copy of AWORK. This carries the appropriate dimension through the region unaltered. |
||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||