extern void abort (void); int main (void) { int i = 6, n = 0; omp_set_dynamic (0); omp_set_nested (1); #pragma omp parallel shared (i) num_threads (3) { if (omp_get_num_threads () != 3) #pragma omp atomic n += 1; #pragma omp parallel shared (i) num_threads (4) { if (omp_get_num_threads () != 4) #pragma omp atomic n += 1; #pragma omp critical i += 1; } } if (n == 0 && i != 6 + 3 * 4) abort (); return 0; }
is miscompiled. While we can use copy-in/out for the outer parallel's shared(i), it can't be used for the inner parallel's shared(i), as multiple threads would have their own copied copies of the shared var, rendering the variable effectively not shared. -- Summary: Invalid use of copy-in/out for shared vars in nested parallels Product: gcc Version: 4.3.0 Status: UNCONFIRMED Keywords: openmp Severity: normal Priority: P3 Component: middle-end AssignedTo: jakub at gcc dot gnu dot org ReportedBy: jakub at gcc dot gnu dot org http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35549