c - 在 #define 中使用 openmp pragma

标签 c macros openmp c-preprocessor pragma

Possible Duplicates:
C/C++ pragma in define macro
Conditional “pragma omp”

如何在宏定义中使用 OpenMP 编译指示?例如

#define A() { \
 ...a lot of code... \
 #pragma omp for     \
 for(..)             \
  ..do_for..         \
 ...another a lot of code \
 }

最佳答案

正如这里的回答Conditional "pragma omp"

C99 has the _Pragma keyword that allows you to place what otherwise would be #pragma inside macros. Something like

  #define OMP_PARA_INTERNAL _Pragma("omp parallel for")

所以,

#define OMP_PARA_FOR _Pragma("omp for")
#define A() { \
 ...a lot of code... \
 OMP_PARA_FOR     \
 for(..)             \
  ..do_for..         \
 ...another a lot of code \
 }

多个_Pragma可以组合为一元运算符,例如:

_Pragma("first pragma") _Pragma("Second pragma")

关于c - 在 #define 中使用 openmp pragma,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6627462/

相关文章:

macros - 使用 dbt_utils.union_relations 错误但不知道如何/为什么?

c++ - 平行狄克斯特拉

c - 具有不同 ID 的结构体中的相同 ArrayName

c++ - 提取扫描文档的一部分(个人 ID)——选择哪个库和方法?

c - socket.h (_uid32_t) 错误

c++ - OpenMP 和 NUMA 的关系?

java - 如何在 Java 代码中使用 OpenMP?

c++ - 从哪里获得简单的开源 adpcm C\C++ 编码器库?

c - 使用宏进行类型检查

macros - 为什么在这个宏定义中需要@符号?