In OpenMP: bug (?) when using task and shared together

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 ---



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux