Orna Agmon Ben-Yehuda
Mon, 24 Sep 2007 11:58:47 -0700
On Mon, 24 Sep 2007, Oleg Goldshmidt wrote:
Date: Mon, 24 Sep 2007 19:35:57 +0200 From: Oleg Goldshmidt <[EMAIL PROTECTED]> Reply-To: linux-il@cs.huji.ac.il To: Orna Agmon Ben-Yehuda <[EMAIL PROTECTED]> Cc: linux-il@cs.huji.ac.il Subject: Re: With and Without gcc OMP Orna Agmon Ben-Yehuda <[EMAIL PROTECTED]> writes:Hi All, I am trying to compile the same code using gcc 4.2, which has gomp (gnu open mp - a library for automatic thread paralelization) already in it. I want the code to still compile cleanly (using -Werror) without openMP at all, because it is said that there is a performance penalty to compiling with openMP, even if not using it (that is, defining the number of threads at runtime to be 1). I would also like to be able to still compile the code cleanly on prior versions of gcc, specifically on 3.4.* which I currently use. The problem is that in order to use OMP I need to insert pragmas such as #pragma omp for And both gcc 3.4.4 and gcc 4.2 without the -fopenmp flag complain about ignoring a pragma for each such line. I tried hiding the pragma using a construct such as #ifdef HAVE_OMP #define MYOMP(C) C #else #define MYOMP(C) #endifHi Orna, Have you tried #ifdef _OPENMP #pragma omp for #endif ? According to the OpenMP spec (http://www.openmp.org) v2.5 _OPENMP must be defined when the compiler implementation supports preprocessing and OpenMP. It seems to work for me with gcc 4.1.1 (yes, with -W -Wall -Werror :) on CentOS 5. If you also need to base your preprocessing logic on the gcc version use __GNUC__, __GNUC_MINOR__, and __GNUC_PREREQ() - see features.h. However, if you don't need that then I think that _OPENMP is the cleanest solution. Enjoy,
Hi Guys, Thank you for all your suggestions.Oleg - I did not try your specific solution, but a similar thing, and as Shachar mentioned, indeed #if did the trick where #ifdef did not.
So my current (ugly) solution is: #if (HAVE_OMP) #prgama omp for #endifI define HAVE_OMP=1 according to the compiler's abilities in the configure.in (yes, I do use it, Omer) and change it to HAVE_OMP=0 if the current target is not an openmp target. If _OPENMP is not defined when -fopenmp is not used, than I can use it to replace my overcomplicated makefile bit. But it seems to me that it is intended to hide c code, and not pragmas. The whole point of pragmas is that the code can compile even if they are not defined.
It is ugly because omp applies to the next code block, which is visually intuitive using a one-liner, but currently looks like a mess. It also means that the more code I import, the more changes I need to make to it.
Omer - when I considered writing a CPPP (C pre pre processor) I also considered the poor people who will have to live with the compilation system I maintain. I already support *.[fdijh] *.[df]90 *.com *.inc *.c++ and various others, with two preprocessors one over the other (fortran's built in, different in each fortran compiler, and CPP). "Getting out of the box" would make the package unfit to get into any reasonable luggage compartment.
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]