#pragma inside macro

Hi,

I want to define,

#define PRAGMA_ACC_KERNELS #pragma acc kernels

But that is not working. Is it supported in OpenACC?

Hi hyuzuguzel,

This isn’t a legal C macro definition. Instead, you need to use the C99 “_Pragma” operator to define a pragma as part of a macro.

Try:

#define PRAGMA_ACC_KERNELS _Pragma("acc kernels")

Hope this helps,
Mat

Hi,

I’ve already tried your suggestion but the project did not compile. It gives the following error:

error: identifier “_Pragma” is undefined
PRAGMA_ACC_KERNELS

I also tried __pragma(“acc kernels”). With this the project compiles but it doesn’t recognizes the pragma and thus doesn’t create the kernel.

Best regards,
H.

Can you please provide more details such as compiler version and OS, as well as a reproducing example?

Given the error message, it seems you’re using C++? PGI’s C++ compiler will recognize the C99 _Pragma operator.

% cat testPragma.cpp
#include <iostream>
#define PRAGMA_ACC_KERNELS _Pragma("acc kernels loop")
#define N 1024

int main() {
  int A[N];
  int i;
  PRAGMA_ACC_KERNELS
  for (i=0; i<N; ++i) {
     A[i]=i;
  }
  std::cout << "A[1]=" << A[1] << std::endl;
  return 0;
}

% pgc++ testPragma.cpp -acc -Minfo=accel
main:
      9, Loop is parallelizable
         Accelerator kernel generated
          9, #pragma acc loop gang, vector(128) /* blockIdx.x threadIdx.x */
      9, Generating copyout(A[:])
         Generating Tesla code

I am using Windows 7 and “pgcpp 14.10-0 64-bit target on x86-64 Windows -tp haswell The Portland Group - PGI Compilers and Tools” compiler. I also tried the testpragma.cpp but I again get the same error. I compile with ->

pgcpp testPragma.cpp -acc -Minfo=accel

Ah, in that case you need to add the “–c++0x” flag to get the appropriate language support.

PGI$ pgcpp testpragma.cpp  -acc -Minfo=accel --c++0x
main:
     10, Loop is parallelizable
         Accelerator kernel generated
         10, #pragma acc loop gang, vector(128) /* blockIdx.x threadIdx.x */
         Generating present_or_copyout(A[:])
         Generating Tesla code

Alternatively you can use the MSVC++ “__pragma” operator.

#define PRAGMA_ACC_KERNELS __pragma(acc kernels loop)

Thanks, now it works.