How to check the version of OpenMP on Linux
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.