A THREADPRIVATE variable is used in a parallel region without having been properly initialized by a COPYIN clause.
The THREADPRIVATE directive specifies that variables are replicated, with each thread having its own copy. On entry to a parallel region, the contents of a THREADPRIVATE variable is usually indeterminate, because there is no way to predict which threads will be enlisted to form the team that executes the region. Therefore, the variable needs to be initialized before use. Previous assignments that occurred outside the parallel region are usually (but not always) insufficient to provide predictable initial values.
The most common way to initialize THREADPRIVATE variables on entry to a parallel region is by using the COPYIN clause. This copied the value in the master thread's copy of the THREADPRIVATE variable to the copies in all the other threads in the team.
OpenMP* only guarantees that the values of data in THREADPRIVATE variables of non-initial threads will persist between two parallel regions under very narrow circumstances. In particular, the same number of thread must execute both parallel regions, neither region can be (dynamically) nested within an explicit parallel region, and the regions must execute sequentially. In addition, the dyn-var internal control variable must be false on entry to both parallel regions. If all these conditions hold, then a threadprivate variable with the same thread number in their respective regions will access the same copy of that variable. In all other cases, THREADPRIVATE variables must be considered to be uninitialized on entry to a parallel region.
ID |
Observation |
Description |
---|---|---|
1 |
OpenMP usage error |
The use of the THREADPRIVATE variable |
2 |
Memory write |
The last assignment |
3 |
OpenMP declaration |
The region containing the use |
#include <stdio.h> #include <omp.h> int a[1000]; #pragma omp threadprivate (a) int main(int argc, char **argv) { int i; int sum = 0; for (i = 0; i < 1000; i++) { a[i] = i; } #pragma omp parallel for reduction (+:sum) // copyin is needed for (i = 0; i < 1000; i++) { sum = sum + a[i]; } printf("%d\n", sum); return 0; }
Copyright © 2010, Intel Corporation. All rights reserved.