This is a simple test code:
#include <stdlib.h>
__thread int a = 0;
int main() {
#pragma omp parallel default(none)
{
a = 1;
}
return 0;
}
gcc compiles this without any problems with -fopenmp, but icc (ICC) 12.0.2 20110112 with -openmp complains with
test.c(7): error: "a" must be specified in a variable list at enclosing OpenMP parallel pragma #pragma omp parallel default(none)
I have no clue which paradigm (i.e. shared, private, threadprivate) applies to this type of variables. Which one is the correct one to use?
I get the expected behaviour when calling a function that accesses that thread local variable, but I have trouble accessing it from within an explicit parallel section.
Edit:
My best solution so far is to return a pointer to the variable through a function
static inline int * get_a() { return &a; }
threadprivateis probably the closest. Since__threadis a compiler extension, you will probably not find much of documentation that links this and OpenMP. - Jens Gustedtaan explicit data-sharing class, even whendefault(none)is specified. - Hristo Ilievicc12.0.2. And you are right that this seems to be an issue withicc.gccaccepts this. - Sergey L.#pragma omp threadprivate(a)on the next line after the declaration ofa. It is a bit of tautology since to a great extent both do the same (with some exceptional cases concerning C++ objects). - Hristo Iliev__threadspecifier and putting#pragma omp threadprivateinstead even makes my code compatible with Mach-O since__threadis unsupported in Mach-O executables. If you post this as an answer then I will happily give you credit. - Sergey L.