I wonder how to check the version of OpenMP on a Linux remote machine?
I don\'t know where it is installed either.
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.
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.
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.
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.
Here's a short C++11 program to display your OpenMP version; it also covers version 5.0 which was released in November 2018.
#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
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.
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.