1

In my code I define the lower and upper bounds of different computational regions by using a structure,

typedef struct RBox_{
  int ibeg; 
  int iend; 
  int jbeg; 
  int jend; 
  int kbeg;
  int kend;
} RBox;

I have then introduced the following macro,

#define BOX_LOOP(box, k,j,i)    for (k = (box)->kbeg; k <= (box)->kend; k++) \
                                for (j = (box)->jbeg; j <= (box)->jend; j++) \
                                for (i = (box)->ibeg; i <= (box)->iend; i++)

(where box is a pointer to a RBox structure) to perform loops as follows:

#pragma acc parallel loop collapse(3) present(box, data)
BOX_LOOP(&box, k,j,i){
    A[k][j][i] = ...  
}

My question is: Is employing the macro totally equivalent to writing the loop explicitly as below ?

ibeg =  box->ibeg; iend = box->iend; 
jbeg =  box->jbeg; jend = box->jend; 
kbeg =  box->kbeg; kend = box->kend; 

#pragma acc parallel loop collapse(3) present(box, data)
for (k = kbeg; k <= kend; k++){
for (j = jbeg; j <= jend; j++){
for (i = ibeg; i <= iend; i++){
  A[k][j][i] = ...
}}}

Furthermore, are macros portable to different versions of the nvc compiler?

Steve
  • 89
  • 1
  • 6

2 Answers2

0

Since the macro is expanded by the pre-processor, which runs before the OpenACC directives are interpreted, I would expect that this will work exactly how you hope. What are you hoping to accomplish here by not writing these loops in a function rather than a macro?

jefflarkin
  • 1,279
  • 6
  • 14
0

Preprocessor directives and user defined macros are part of the C99 language standard, which nvc (as well as it's predecessor "pgcc"), has supported for quite sometime (~20 years). So, yes would be portable to all versions of nvc.

The preprocessing step occurs very early in the compilation process. Only after the macros are applied, does the compiler process the OpenACC pragmas. So, yes, using the macro above would be equivalent to explicitly writing out the loops.

Mat Colgrove
  • 5,441
  • 1
  • 10
  • 11