linux-il  

Re: With and Without gcc OMP

Orna Agmon Ben-Yehuda
Thu, 27 Sep 2007 12:49:31 -0700

On Tue, 25 Sep 2007, Oleg Goldshmidt wrote:

Date: Tue, 25 Sep 2007 12:07:51 +0200
From: Oleg Goldshmidt <[EMAIL PROTECTED]>
Reply-To: linux-il@cs.huji.ac.il
To: linux-il@cs.huji.ac.il
Subject: Re: With and Without gcc OMP

"Nadav Har'El" <[EMAIL PROTECTED]> writes:

On Mon, Sep 24, 2007, Oleg Goldshmidt wrote about "Re: With and Without gcc 
OMP":
A #pragma is C code just as any other line in your program, so the

This is what I thought too, so there's something that puzzles me in Orna's
original description. She said that she tried something like:

#ifdef _OPENMP
#define OPENMP(line) line
#else
#define OPENMP(line) /* nothing */
#endif

...

OPENMP(#pragma ...)

But it didn't work for her. Do you have any idea why?

Yes. Being a preprocessor directive, #pragma cannot be produced as a
result of a macro expanion. To handle that, C99 introduces the _Pragma
operator, cf. http://tigcc.ticalc.org/doc/cpp.html#SEC46.

Indeed, but I think Orna's question was how to make this the least
ugly as possible. And having half a dozen lines of "#" lines before
every function is certainly quite ugly, if there was a possibility
to have only one.

Well, #pragmas are inherently ugly. One can argue whether OpenMP could
engineer a better way to tell compilers what to do, but the spec is
there. It specifies #pragmas, and each #pragma needs at least 3 lines
of preprocessor code.

Orna can try and use the _Pragma operator, e.g.,

#if _OPENMP
#define OMP(x) _Pragma(omp #x)
#else
#undef OMP(x)
#endif

or something of the kind, but this will have to be conditioned on a
conforming implementation of C99, and therefore may be unacceptable.



Thanks guys! I verified that indeed _OPENMP does exactly what HAVE_OMP (which I slaved on...) does, and the _Pragma concept is just what I was missing in order to still have an elegant one liner in the code.

About a year ago I stopped supporting gcc 2.96 (At last!) and
Alpha machines, so I believe C99 should not be a problem.

One of the annoying things in this problem, BTW, was that when I tried debugging the problems the double # was causing, I ran gcc -E into a file, and tried compiling it to see where the problems were coming from, and then of course (due to the double CPP parsing) I saw no problem at all.

Another solution which was offered to me in private was using -Wno-unknown-pragmas. One should note, of course, not to use it alongside -fopenmp, or important warnings will be missed. Also, it is order dependent, since it overrides -Wall:

[EMAIL PROTECTED] ~/c]$ gcc -Wall -Wno-unknown-pragmas pragmas.c
[EMAIL PROTECTED] ~/c]$ gcc -Wno-unknown-pragmas -Wall pragmas.c
pragmas.c: In function 'main':
pragmas.c:10: warning: ignoring #pragma blah

Thanks and Hag Sameah,
Orna.
--
Orna Agmon Ben-Yehuda http://ladypine.org/
ICQ: 348759096


=================================================================
To unsubscribe, send mail to [EMAIL PROTECTED] with
the word "unsubscribe" in the message body, e.g., run the command
echo unsubscribe | mail [EMAIL PROTECTED]