3

How can I make static variables and functions (from a templatised class) private in OpenMP to have different values in each thread?

1 Answer 1

3

Depending on the scenario, you should be able to use:

#pragma omp threadprivate(theVariable) 

For details, see this article on using Thread-local Storage in OpenMP.

Sign up to request clarification or add additional context in comments.

6 Comments

As a matter of fact I tried that already. But I got an error. error: 'SysBase<double>::_dt' declared 'threadprivate' after first use
@SamerAfach You typically can't use a static variable as both static + thread local. You have to make a new thread local, then update the static (which is shared) afterwards.
Note also that threadprivate local static variables are only supported since OpenMP 3.0, which means no support in Visual C++ (if you develop on Windows or intend to port to later)
@HristoIliev How can I know the version of OpenMP I'm using? I use Ubuntu actually with g++ for my programs. Should I give some extra directive to use OpenMP 3.0?
From the GCC Wiki: "As of GCC 4.2, the compiler implements version 2.5 of the OpenMP standard and as of 4.4 it implements version 3.0 of the OpenMP standard. The OpenMP 3.1 is supported since GCC 4.7." Standards are (kind of) backwards compatible and there is no way to force conformance to specific OMP version in GCC (and also in the other compilers that I use).
|

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.