clang-omp / clang

clang with OpenMP 3.1 and some elements of OpenMP 4.0 support
clang-omp.github.com
Other
91 stars 15 forks source link

clang-omp does not alway honor the threadprivate directive #54

Closed mihailpopov closed 9 years ago

mihailpopov commented 9 years ago

With the following code,

test.h

#include <omp.h>

extern int test;
#pragma omp threadprivate(test)

extern void fct();

main.c

#include <omp.h>
#include <stdio.h>
#include "test.h"

int test;

int main() 
{
    fct();
    printf("\n");
    #pragma omp parallel 
    {       
        test = omp_get_thread_num();
        #pragma omp barrier 
        printf("test = %d, by thread %d\n",test,omp_get_thread_num());
    }
}

test.c

#include <omp.h>
#include <stdio.h>
#include "test.h"

void fct() 
{
     #pragma omp parallel 
    {   
        test = omp_get_thread_num();
        #pragma omp barrier 
        printf("test = %d, by thread %d\n",test,omp_get_thread_num());
    }
}

gcc and icc, make t private in both main.c and fct.c translation units. But clang-omp makes t private in fct but shared in main.

I think this is a bug because OpenMP 4.0 specification explains in chapter 2.14.2, threadprivate Directive, page 153, that if a variable is specified in a threadprivate directive in one translation unit, it must be specified in a threadprivate directive in every other translation unit in which it is declared.

It appears that defining the variable after using the threadprivate removes the private state. This can be observed in the following smaller example:

#include <omp.h>
#include <stdio.h>

extern int test;
#pragma omp threadprivate(test)
int test;

int main() 
{
    #pragma omp parallel 
    {       
        test = omp_get_thread_num();
        #pragma omp barrier 
        printf("test = %d, by thread %d\n",test,omp_get_thread_num());
    }
}

in gcc 4.7.2 and icc 12.1.0 each printf shows a different thread num (private), whereas in clang-omp a single thread num is printed (shared).

Thanks,

alexey-bataev commented 9 years ago

Hi, again thanks for the report. The bug is fixed.

Best regards,

Alexey Bataev

Software Engineer Intel Compiler Team Intel Corp.

27.11.2014 18:54, Mihail Popov пишет:

With the following code,

/test.h/

include

extern int test;

pragma omp threadprivate(test)

extern void fct();

/main.c/

include

include

include "test.h"

int test;

int main() { fct(); printf("\n");

pragma omp parallel

 {
     test =omp_get_thread_num();
     #pragma  omp barrier
     printf("test =%d, by thread%d\n",test,omp_get_thread_num());
 }

}

/test.c/

include

include

include "test.h"

void fct() {

pragma omp parallel

 {
     test =omp_get_thread_num();
     #pragma  omp barrier
     printf("test =%d, by thread%d\n",test,omp_get_thread_num());
 }

}

gcc and icc, make t private in both main.c and fct.c translation units. But clang-omp makes t private in fct but shared in main.

I think this is a bug because OpenMP 4.0 specification explains in chapter 2.14.2, threadprivate Directive, page 153, that if a variable is specified in a threadprivate directive in one translation unit, it must be specified in a threadprivate directive in every other translation unit in which it is declared.

It appears that defining the variable after using the threadprivate removes the private state. This can be observed in the following smaller example:

include

include

extern int test;

pragma omp threadprivate(test)

int test;

int main() {

pragma omp parallel

 {
     test =omp_get_thread_num();
     #pragma  omp barrier
     printf("test =%d, by thread%d\n",test,omp_get_thread_num());
 }

}

in gcc 4.7.2 and icc 12.1.0 each printf shows a different thread num (private), whereas in clang-omp a single thread num is printed (shared).

Thanks,

— Reply to this email directly or view it on GitHub https://github.com/clang-omp/clang/issues/54.