linux-il  

Re: With and Without gcc OMP

Oleg Goldshmidt
Tue, 25 Sep 2007 03:04:29 -0700

"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.

-- 
Oleg Goldshmidt | [EMAIL PROTECTED] | http://www.goldshmidt.org

=================================================================
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]