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.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…