The usage pattern of a PRIVATE variable may lead to different behavior in sequential and parallel modes.
This diagnostic flags the use of a variable used outside a parallel region that was last assigned inside a parallel region where that variable was marked as PRIVATE. Variables marked as PRIVATE have indeterminate value upon exit from a parallel region, so this usage pattern is equivalent to reading from an uninitialized variable.
In parallel mode, a variable marked as PRIVATE is replaced by a per-thread temporary within that region. The value of the outer variable is not copied into the per-thread temporaries and the values assigned to the per-thread private are not copied out to the outer variable. If you wish to have the outer value copied in, use FIRSTPRIVATE instead of PRIVATE. If you wish to have the value copied out, use LASTPRIVATE instead of PRIVATE. LASTPRIVATE updates the outer value from the thread that executes the last iteration of a parallel loop or the lexically last SECTION construct in a SECTIONS construct.
ID |
Observation |
Description |
---|---|---|
1 |
OpenMP usage error |
The place the private was specified |
#include <stdio.h> #include <omp.h> int b; void do_work() { int i; #pragma omp parallel private (b) { #pragma omp for ordered for (i = 0; i < 6; i++) { b = i; #pragma omp ordered printf("itt = %d thr = %d b=%d\n", i, omp_get_thread_num (), b); } } printf("b=%d\n", b); // error: use value assigned in region } int main(int argc, char **argv) { b = 100; omp_set_num_threads(3); do_work(); return 0; }
Copyright © 2010, Intel Corporation. All rights reserved.