What preprocessor define does -fopenmp provide?

1.2k views Asked by At

I've got some code that can run with (or without) OpenMP - it depends on how the user sets up the makefile. If they want to run with OpenMP, then they just add -fopenmp to CFLAGS and CXXFLAGS.

I'm trying to determine what preprocessor macro I can use to tell when -fopenmp is in effect. The omp.h header does not look very interesting:

$ cat /usr/lib/gcc/x86_64-linux-gnu/4.8/include/omp.h | grep define
#define OMP_H 1
#define _LIBGOMP_OMP_LOCK_DEFINED 1
# define __GOMP_NOTHROW throw ()
# define __GOMP_NOTHROW __attribute__((__nothrow__))

And I can't get the preprocessor to offer up anything useful:

$ cpp -dM -fopenmp </dev/null | grep -i omp
#define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_1 1
#define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_2 1
#define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4 1
#define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_8 1
#define __STDC_IEC_559_COMPLEX__ 1

$ cpp -dM -fopenmp </dev/null | grep -i version
#define __GXX_ABI_VERSION 1002
#define __VERSION__ "4.8.2"

What preprocessor define does -fopenmp provide?


This is similar to How to tell if OpenMP is working? But I'm interested in compile time, and not post-build or runtime.

Note: this project does not use Boost, does not use Autotools, and does not use Cmake. It just uses a makefile.

1

There are 1 answers

5
mtijanic On BEST ANSWER

Your grep was overly specific, you should have looked for "openmp".

Or rather, diffing cpp -dM -fopenmp </dev/null and cpp -dM </dev/null produces a single diff:

#define _OPENMP 201107

Which should be exactly what you are looking for.