1

It appears that OpenMP implementation in Visual Studio 2010 has a serious bug that does not allow to have external variables as threadprivate. The the following code would not compile:

file.c


#include <omp.h>

/* Declaration of external variable. */

extern int My_Var;

#pragma omp threadprivate (My_Var) 

void MyFunc(void) { My_Var = 1;}

The error message is:

error C3053:
'My_Var' : 'threadprivate' is only valid for global or static data tems.

Clearly the compiler is confused about linkage attribute of the variable.

It is most common to refer global variables in multiple files. So this problem makes threadprivate directive unusable in any realistic program.

I wonder if there are tricks to handle this bug. Unfortunately in my case this problem prevents me to use OMP completely.

Thank you,

Alex

1
  • have you tried compiling with /openmp /LD ?
    – cprogcr
    Sep 24, 2012 at 18:38

1 Answer 1

3

This seems to be a (yet another) violation of the OpenMP standard in the VC++ compiler. Fortunately the threadprivate clause in VC++ is implemented directly as the application of the thread __declspec attribute and you can simply replace:

extern int My_Var;

#pragma omp threadprivate (My_Var)

with

extern __declspec(thread) int My_Var;

Still you have to provide the same __declspec(thread) attribute (or #pragma omp threadprivate pragma) to My_Var in all translation units where it is declared (as is also required per the OpenMP specification - Section 2.7.1 of the "OpenMP 2.0" specs).

1
  • 1
    I just used extern __declspec(thread) int My_Var; as suggest and it all compiled fine.
    – Alex
    Sep 24, 2012 at 9:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.