OpenMP local storage id and stream with icc

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 about

test.c (7): error: "a" should be indicated in the list of variables when closing OpenMP parallel pragma #pragma omp parallel default (none)

I do not know which paradigm (i.e., shared , private , threadprivate ) is applicable to this type of variable. Which one is correct?

I get the expected behavior when calling a function that accesses this local thread variable, but it's hard for me to access it from an explicit parallel section.

Edit:

My best solution so far is to return a pointer to a variable through a function

 static inline int * get_a() { return &a; } 
+2
source share
1 answer

__thread about the same as the threadprivate OpenMP directive. To a large extent (read when no C ++ objects are involved), both are often implemented using the same main compiler mechanism and are therefore compatible, but this is not guaranteed to always work. Of course, the real world is far from ideal, and we sometimes have to sacrifice portability for the fact that you have things that work within certain developmental constraints.

threadprivate is a directive, not a suggestion, so you need to do something like:

 #include "header_providing_a.h" #pragma omp threadprivate(a) void parallel_using_a() { #pragma omp parallel default(none) ... ... use 'a' here } 

GCC (at least version 4.7.1) treats __thread as an implicit threadprivate declaration, and you don't need to do anything.

+3
source

All Articles