我有一些可以运行(或不运行)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
提供了哪些预处理器定义?
这类似于How to tell if OpenMP is working?但我对编译时感兴趣,而不是后期构建或运行时。
注意 :此项目不使用Boost,不使用Autotools,也不使用Cmake。它只使用一个makefile。
答案 0 :(得分:6)
你的grep过于具体,你应该寻找&#34; openmp&#34;。
或者说,差异cpp -dM -fopenmp </dev/null
和cpp -dM </dev/null
会产生一个差异:
#define _OPENMP 201107
这应该是你正在寻找的。 p>