How to check the version of OpenMP on Linux

LinuxGccVersionOpenmp

Linux Problem Overview


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

I don't know where it is installed either.

Linux Solutions


Solution 1 - Linux

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 - Linux

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 - Linux

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 - Linux

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 - Linux

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.

Solution 6 - Linux

This is a bit safer version of an answer by user2023370 above. Ancient OpenMP versions are omitted for brevity:

#include <map>
#include <fmt/format.h>
using namespace std;
...
fmt::print("OpenMP v{}\n", map<int, string>{{200805, "3.0"},{201107, "3.1"}, {201307, "4.0"}, {201511, "4.5"}, {201811, "5.0"}}[_OPENMP]);

If a new version number or corrupted one is encountered, this statement will not throw exception as opposed to using at() function member.

Version numbers are from https://github.com/jeffhammond/HPCInfo/blob/master/docs/Preprocessor-Macros.md.

Solution 7 - Linux

Actually, I think you can not get the version of openmp directly, but compiler will use a predefined macro _OPENMP to represent the release date of openmp, and you should specify the -fopenmp option to use this macro.

You can get the release date of openmp first using shell command like this

echo _OPENMP | gcc -fopenmp -E -x c - | tail -1

As for my gcc, it is

201511

Then you can check the openmp release history (https://www.openmp.org/news/press-releases/) to get the version. Of 201511, it means Nov 2015, and the version is openmp 4.5 .

The release history is below:

Date		Version
----------------------
Nov 2021	OpenMP 5.2
Nov 2020	OpenMP 5.1
Nov 2018	OpenMP 5.0
Nov 2015	OpenMP 4.5
Jul 2013	OpenMP 4.0
Jul 2011	OpenMP 3.1
May 2008	OpenMP 3.0
May 2005	OpenMP 2.5
Mar 2002	C/C++ 2.0
Nov 2000	Fortran 2.0
Nov 1999	Fortran 1.1
Oct 1998	C/C++ 1.0
Oct 1997	Fortran 1.0

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionTimView Question on Stackoverflow
Solution 1 - LinuxBrent BradburnView Answer on Stackoverflow
Solution 2 - Linuxuser2023370View Answer on Stackoverflow
Solution 3 - LinuxnbroView Answer on Stackoverflow
Solution 4 - LinuxAdamView Answer on Stackoverflow
Solution 5 - LinuxHari Krishna NallaView Answer on Stackoverflow
Solution 6 - LinuxPaul JurczakView Answer on Stackoverflow
Solution 7 - LinuxAnthony LiView Answer on Stackoverflow