问题
Possible Duplicates:
C/C++ pragma in define macro
Conditional “pragma omp”
How can I use an OpenMP pragmas inside a macro definition? E.g.
#define A() { \
 ...a lot of code... \
 #pragma omp for     \
 for(..)             \
  ..do_for..         \
 ...another a lot of code \
 }
    回答1:
As it was answered here Conditional "pragma omp"
C99 has the
_Pragmakeyword that allows you to place what otherwise would be#pragmainside macros. Something like
  #define OMP_PARA_INTERNAL _Pragma("omp parallel for")
So,
#define OMP_PARA_FOR _Pragma("omp for")
#define A() { \
 ...a lot of code... \
 OMP_PARA_FOR     \
 for(..)             \
  ..do_for..         \
 ...another a lot of code \
 }
several _Pragmas can be combined as unary operator, e.g.:
_Pragma("first pragma") _Pragma("Second pragma")
    回答2:
On Visual Studio you can use the __pragma keyword instead of #pragma. Unfortunately, this is non-standard so you'll have to figure out whether your compiler supports something similar, if you're using another compiler.
回答3:
You can't because # inside a macro has another meaning (to add quotes (#somevar) or concat variables (onevar ## anothervar)).
If you've got more complex code you'd like to include in-place instead of a function call, use a local function and add the inline keyword so it's inlined just as a macro would be inlined. You just have to ensure you pass variables used inside as parameters (as pointers or references). As an alternative you could use #include to include a code file containing your macro code only.
来源:https://stackoverflow.com/questions/6627462/using-an-openmp-pragma-inside-define