What preprocessor define does -fopenmp provide?

若如初见. 提交于 2019-12-13 12:31:26

问题


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:


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.



来源:https://stackoverflow.com/questions/30803126/what-preprocessor-define-does-fopenmp-provide

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!