How to check the version of OpenMP on Linux

69,369

Solution 1

It appears that the C/C++ specification for OpenMP provides no direct way of doing this programmatically. So you have to check the docs for your compiler version.

gcc --version ## get compiler version

For GCC, this is a good resource (does not mention newest versions of GCC): http://gcc.gnu.org/wiki/openmp:

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.


Edit

After trying a bit harder, I got the following to work. It at least gives an indication of the OpenMP version -- although it still requires you to look something up.

$ echo |cpp -fopenmp -dM |grep -i open
#define _OPENMP 200805

You can go here (http://www.openmp.org/specifications/) to discover the mapping between the date provided and the actual OpenMP version number.

In implementations that support a preprocessor, the _OPENMP macro name is defined to have the decimal value yyyymm where yyyy and mm are the year and month designations of the version of the OpenMP API that the implementation supports.

Solution 2

Here's a short C++11 program to display your OpenMP version; it also covers version 5.1 which was released in November 2020.

#include <unordered_map>
#include <iostream>
#include <omp.h>

int main(int argc, char *argv[])
{
  std::unordered_map<unsigned,std::string> map{
    {200505,"2.5"},{200805,"3.0"},{201107,"3.1"},{201307,"4.0"},{201511,"4.5"},{201811,"5.0"},{202011,"5.1"}};
  std::cout << "We have OpenMP " << map.at(_OPENMP) << ".\n";
  return 0;
}

and compile it with:

g++ -std=c++11 -fopenmp foobar.cpp

Solution 3

You need to check your gcc version using

gcc --version

and then see the (incomplete) table below (whose info is gathered from this Wiki article and from this webpage from the OpenMP official website):

| gcc version | OpenMP version |    Languages    | Offloading |
|-------------|----------------|-----------------|------------|
|    4.2.0    |       2.5      |        C        |            |
|    4.4.0    |       3.0      |        C        |            |
|    4.7.0    |       3.1      |        C        |            |
|    4.9.0    |       4.0      |      C, C++     |            |
|    4.9.1    |       4.0      | C, C++, Fortran |            |
|      5      |                |                 |     Yes    |
|     6.1     |       4.5      |      C, C++     |            |

The blank entries are there because I didn't find the corresponding info.

Solution 4

First set environment variable OMP_DISPLAY_ENV: in bash:

export  OMP_DISPLAY_ENV="TRUE" 

or in csh-like shell:

setenv OMP_DISPLAY_ENV TRUE

Then compile and run your OpenMP program:

./a.out

There will be additional info, like :

OPENMP DISPLAY ENVIRONMENT BEGIN
  _OPENMP = '201511'
  OMP_DYNAMIC = 'FALSE'
  OMP_NESTED = 'FALSE'
  OMP_NUM_THREADS = '8'
  OMP_SCHEDULE = 'DYNAMIC'
  OMP_PROC_BIND = 'FALSE'
  OMP_PLACES = ''
  OMP_STACKSIZE = '0'
  OMP_WAIT_POLICY = 'PASSIVE'
  OMP_THREAD_LIMIT = '4294967295'
  OMP_MAX_ACTIVE_LEVELS = '2147483647'
  OMP_CANCELLATION = 'FALSE'
  OMP_DEFAULT_DEVICE = '0'
  OMP_MAX_TASK_PRIORITY = '0'
OPENMP DISPLAY ENVIRONMENT END

where _OPENMP have the 8 decimal value yyyymm where yyyy and mm are the year and month designations of the version of the OpenMP API that the implementation supports.

Solution 5

OpenMP documentation improved a lot. You can find more information about supported OpenMP versions corresponding compilers from this link.

Coming to your question, as mentioned above first find the gcc compiler version and then refer the above link to know the corresponding OpenMP version.

Above link also has the supported OpenMP versions in the different compliers.

Share:
69,369
Tim
Author by

Tim

Elitists are oppressive, anti-intellectual, ultra-conservative, and cancerous to the society, environment, and humanity. Please help make Stack Exchange a better place. Expose elite supremacy, elitist brutality, and moderation injustice to https://stackoverflow.com/contact (complicit community managers), in comments, to meta, outside Stack Exchange, and by legal actions. Push back and don't let them normalize their behaviors. Changes always happen from the bottom up. Thank you very much! Just a curious self learner. Almost always upvote replies. Thanks for enlightenment! Meanwhile, Corruption and abuses have been rampantly coming from elitists. Supportive comments have been removed and attacks are kept to control the direction of discourse. Outright vicious comments have been removed only to conceal atrocities. Systematic discrimination has been made into policies. Countless users have been harassed, persecuted, and suffocated. Q&amp;A sites are for everyone to learn and grow, not for elitists to indulge abusive oppression, and cover up for each other. https://softwareengineering.stackexchange.com/posts/419086/revisions https://math.meta.stackexchange.com/q/32539/ (https://i.stack.imgur.com/4knYh.png) and https://math.meta.stackexchange.com/q/32548/ (https://i.stack.imgur.com/9gaZ2.png) https://meta.stackexchange.com/posts/353417/timeline (The moderators defended continuous harassment comments showing no reading and understanding of my post) https://cs.stackexchange.com/posts/125651/timeline (a PLT academic had trouble with the books I am reading and disparaged my self learning posts, and a moderator with long abusive history added more insults.) https://stackoverflow.com/posts/61679659/revisions (homework libels) Much more that have happened.

Updated on July 09, 2022

Comments

  • Tim
    Tim almost 2 years

    I wonder how to check the version of OpenMP on a Linux remote machine?

    I don't know where it is installed either.

  • Brent Bradburn
    Brent Bradburn over 11 years
    Funny story: I spent a while trying to figure out how to find the OpenMP version programmatically before giving up and posting this answer. Then I noticed that it is irrelevant for my purposes because the specific feature that I wanted (taskyield) is not actually supported in any version of gcc (as indicated in the wiki referenced above).
  • Trevor Boyd Smith
    Trevor Boyd Smith about 9 years
    For quick reference (copied from openmp.org/wp/openmp-specifications), the mapping of #define _OPENMP to the OPENMP API version is {200505:'2.5',200805:'3.0',201107:'3.1',201307:'4.0'} where each pair is 'value of _OPENMP : OpenMP API Version'.
  • tim18
    tim18 about 8 years
    for ICL 16.0.3 which claims 4.5 support it still reports 4.0
  • tim18
    tim18 about 8 years
    For VS2015.2 it produces no output. It's mostly OpenMP 2.5 but doesn't define _OPENMP.
  • tim18
    tim18 about 8 years
    g++ 7.0 reports 4.5, 5.3 reports 4.0.
  • astroboylrx
    astroboylrx almost 6 years
    One more version for _OPENMP is {201511: '4.5'}.
  • jww
    jww almost 5 years
    "It appears that the C/C++ specification for OpenMP provides no direct way of doing this programmatically...." - Incorrect. The value is set in the macro _OPENMP.
  • Brent Bradburn
    Brent Bradburn almost 5 years
    @jww: I covered that in the edited answer. My interpretation was that this returns a reference date, which is an indirect representation of the version, and not the version itself. You still have to apply a translation if you want to get the commonly used version number.
  • Brent Bradburn
    Brent Bradburn over 4 years
    There's an automated mapping for CMake at Kitware/CMake/master/Modules/FindOpenMP.cmake, which may be related to FineOpenMP.
  • Paul Jurczak
    Paul Jurczak over 3 years
  • Rhubarb
    Rhubarb over 3 years
    by far the simplest answer here!
  • Pavel Peřina
    Pavel Peřina over 2 years
    {200203, "2.0"} for Visual Studio 2019 (yes, really)