From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 3561 invoked by alias); 30 Mar 2009 18:23:58 -0000 Received: (qmail 2278 invoked by uid 48); 30 Mar 2009 18:23:35 -0000 Date: Mon, 30 Mar 2009 18:23:00 -0000 Subject: [Bug other/39591] New: GOMP_loop_end illegally optmized into GOMP_loop_end_nowait X-Bugzilla-Reason: CC Message-ID: Reply-To: gcc-bugzilla@gcc.gnu.org To: gcc-bugs@gcc.gnu.org From: "brian dot e dot bliss at intel dot com" Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2009-03/txt/msg02237.txt.bz2 As the following example shows, this optimization cannot be performed legally if the parallel loop spawns tasks which reference vars local to the parallel region. Without the optimization, all tasks would be executed at the implicit barrier at the end of the loop (where "array" is still intact) rather than the barrier at the end of the parallel region (thread 0's stack has been popped and "array" deallocated). % gcc -v Using built-in specs. Target: i686-pc-linux-gnu Configured with: /net/gnu-13/export/gnu/src/gcc/gcc/configure --enable clocale=gnu --with-system-zlib --enable-checking=assert --with-demangler-in-ld --enable-shared --enable-threads=posix --enable-haifa --prefix=/usr/gcc4.4 --with-local-prefix=/usr/local Thread model: posix gcc version 4.4.0 20090311 (experimental) [trunk revision 144788] (GCC) % cat test.c #include #include #include int flag = 0; int foo(int *array) { int i; printf("array = %p\n", array); for (i = 0; i < 10; i++) { printf("i: %d 0x%x\n", i, array[i]); } } int main(int argc, char *argv[]) { #pragma omp parallel shared(argc) { int array[10]; int i; for (i = 0; i < 10; i++) { array[i] = 0x55555555; } #pragma omp for schedule(dynamic) for (i = 0; i < argc; i++) #pragma omp task default(shared) firstprivate(i) { if (omp_get_thread_num() == 0) { if (! flag) { #pragma omp critical(cs) foo(array); flag = 1; } } else { sleep(1); } #pragma omp critical(cs) printf("i = %d\n", i); } } } % % gcc -fopenmp test.c % a.out x x x array = 0xf75bf380 i: 0 0x55555555 i: 1 0x55555555 i: 2 0x55555555 i: 3 0x1312d00 i: 4 0x55555555 i: 5 0x55555555 i: 6 0x55555555 i: 7 0xf7ffc908 i: 8 0xffffffcc i: 9 0x804872c i = 3 i = 2 i = 1 i = 0 % nm a.out | grep GOMP_loop U GOMP_loop_dynamic_next@@GOMP_1.0 U GOMP_loop_dynamic_start@@GOMP_1.0 U GOMP_loop_end_nowait@@GOMP_1.0 % -- Summary: GOMP_loop_end illegally optmized into GOMP_loop_end_nowait Product: gcc Version: 4.4.0 Status: UNCONFIRMED Severity: major Priority: P3 Component: other AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: brian dot e dot bliss at intel dot com http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39591