-fopenmp提供了什么预处理器定义?
我有一些可以运行(或不运行)OpenMP的代码 – 它取决于用户如何设置makefile。 如果他们想要使用OpenMP运行,那么他们只需将-fopenmp
添加到CFLAGS
和CXXFLAGS
。
我正在尝试确定在-fopenmp
生效时我可以用什么预处理器宏来判断。 omp.h
标头看起来不是很有趣:
$ 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__))
我无法让预处理器提供任何有用的东西:
$ 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"
-fopenmp
提供了什么预处理器定义?
我试图解决的问题只是记录:
#if defined() cout << "Compiled and linked with OpenMP" << endl; #endif
我需要知道#include
的定义,因为它取决于用户添加(或省略) -fopenmp
。
这类似于如何判断OpenMP是否正常工作? 但我对编译时感兴趣,而不是后期构建或运行时。
注意 :此项目不使用Boost,不使用Autotools,也不使用Cmake。 它只使用一个makefile。
你的grep过于具体,你应该寻找“openmp”。
或者更确切地说, cpp -dM -fopenmp 和
cpp -dM 会产生一个差异:
#define _OPENMP 201107
这应该是你正在寻找的。