This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
In OpenMP: bug (?) when using task and shared together
- From: "Tal, Ido" <ital at mail dot ucsd dot edu>
- To: "gcc-help at gcc dot gnu dot org" <gcc-help at gcc dot gnu dot org>
- Date: Tue, 28 Sep 2010 13:31:34 -0700
- Subject: In OpenMP: bug (?) when using task and shared together
Hi all,
I'm trying to use the OpenMP "task" construct with shared variables. However, what seems to be happening is that the shared variables are set to garbage inside the task segment. I'd like to check that this is not an error on my part before filing a bug.
Consider the following c program. It works fine if we change both occurrences of
#pragma omp task shared(levelsToGo)
to
#pragma omp task
(if I understand correctly, that makes levelsToGo firstprivate). However, running the original program gives a segmentation fault. To see why, we uncomment
printf("Levels to go: %d\n", levelsToGo);
and get the following printout:
Levels to go: 32583
Levels to go: 3
Levels to go: 0
Levels to go: 0
Levels to go: 0
Levels to go: 0
Levels to go: 0
...
I'm using 64-bit Ubuntu 10.04, gcc -v gives gcc version 4.4.3 (Ubuntu 4.4.3-4ubuntu5)
I apologize in advance if this is some silly mistake on my part.
Thank you,
Ido
--- start c code ---
// compiling: gcc ompbug.c -fopenmp
#include <stdio.h>
#include <omp.h>
void recurse(int levelsToGo)
{
if ( levelsToGo == 0 )
{
printf("*");
}
else
{
#pragma omp task shared(levelsToGo)
{
recurse(levelsToGo-1);
}
#pragma omp task shared(levelsToGo)
{
//printf("Levels to go: %d\n", levelsToGo);
recurse(levelsToGo-1);
}
}
}
int main(int argc, char **argv)
{
#pragma omp parallel
{
#pragma omp single nowait
{
recurse(4);
}
}
printf("\n");
}
--- end c code ---