Check OpenMP Version Supported by gcc or g++ Compiler

Check OpenMP Version Supported by gcc or g++ Compiler

When compiling C or C++ applications with OpenMP, it could be useful to determine which OpenMP version is supported by the installed compiler. This information helps identify which parallel programming features, directives, and runtime capabilities are available before using them in a project. This tutorial demonstrates how to check the OpenMP version supported by gcc or g++ compiler.

The _OPENMP macro is defined only when OpenMP support is enabled with the -fopenmp compiler option. Its numeric value represents the OpenMP specification date in YYYYMM format.

The following commands print the value of the _OPENMP macro:

gcc -fopenmp -dM -E - < /dev/null | grep -Po '_OPENMP \K[0-9]+$'
  • -fopenmp - enables OpenMP support and defines the _OPENMP macro.
  • -dM - outputs all predefined macros after preprocessing.
  • -E - executes only the preprocessing stage without compiling or linking.
  • - - instructs the compiler to read source code from standard input (stdin) instead of a file. This is used in combination with the next part.
  • < /dev/null - supplies an empty input stream, allowing only the compiler built-in macros to be processed.
  • grep -Po '_OPENMP \K[0-9]+$' - extracts only the numeric value assigned to the _OPENMP macro.

Example output:

201511

The value 201511 indicates support for the OpenMP 4.5 specification. Different compiler versions may produce other values depending on the highest OpenMP specification they implement.

The same options can also be used with g++ to check the supported OpenMP version for C++ applications. When gcc and g++ belong to the same compiler version and are built with the same features, they report the same OpenMP support level.

Leave a Comment

Cancel reply

Your email address will not be published.