PGI User Forum
 SearchSearch   MemberlistMemberlist     RegisterRegister   ProfileProfile    Log inLog in 

Free OpenACC Webinar

Pragmas and #defines

 
Post new topic   Reply to topic    PGI User Forum Forum Index -> Programming and Compiling
View previous topic :: View next topic  
Author Message
tttttttttt



Joined: 08 May 2012
Posts: 3

PostPosted: Wed May 09, 2012 2:53 am    Post subject: Pragmas and #defines Reply with quote

I'm generating many identical functions with small differences using C #defines. Inside these I use pragmas. This doesn't work with old C #pragma directive, but should work using standard C99 _Pragma. The following example, for example, works with GCC:

Code:
#define MKFUN(X, OP) \
   void X(double *dst, double *src, size_t n) \
   { \
       _Pragma("omp parallel for") \
       for(size_t i=0; i<n i++){ \
           dst[i]=OP(src[i]); \
       } \
   }

MKFUN(multiexp,  exp)


It fails with PGCC, which complains

PGC-S-0036-Syntax error: Recovery attempted by inserting ';' before '{'

Looking at the output of the preprocessor (pgcc -E), it seems to replace _Pragma with #pragma during the preprocessing, which makes the compiler fail, because the whole expansion MKFUN(multiexp, exp) is on a single line.

I think is a bug in PGCC, not conforming to C99. In the meanwhile, does anyone know a simple workaround, which does not involve a custom preprocessor hack for function generation?
Back to top
View user's profile
mkcolg



Joined: 30 Jun 2004
Posts: 6218
Location: The Portland Group Inc.

PostPosted: Wed May 09, 2012 4:07 pm    Post subject: Reply with quote

Hi tttttttttt,

In looking that the generated post-processed files, the only difference between the PGI pre-processed file and the CPP/GCC pre-processed file is new line after the generated "#pragma". In reading Section 6.10.9 of the C99 standard, "Pragma operator", both compilers are correctly generating the "#pragma" but the standard is unclear if a new line should be generated. I'll need to talk with our compiler architect to better understand what the correct behaviour should be.

- Mat

Code:
% gcc -E test2.c
# 1 "test2.c"
# 1 "<built>"
# 1 "<command>"
# 1 "test2.c"
# 10 "test2.c"
void multiexp(double *dst, double *src, size_t n) {
# 10 "test2.c"
#pragma omp parallel for
# 10 "test2.c"
 for(size_t i=0; i<n i++){ dst[i]=exp(src[i]); } }
% pgcc -E test2.c
# 1 "test2.c"
# 10 "test2.c"
void multiexp ( double * dst , double * src , size_t n ) {
# 10 "test2.c"
#pragma omp parallel for for ( size_t i = 0 ; i < n i ++ ) { dst [ i ] = exp ( src [ i ] ) ; } }
Back to top
View user's profile
Display posts from previous:   
Post new topic   Reply to topic    PGI User Forum Forum Index -> Programming and Compiling All times are GMT - 7 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © phpBB Group