autoconf-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

detection and support of OpenMP


From: Bruno Haible
Subject: detection and support of OpenMP
Date: Thu, 17 May 2007 12:30:31 +0200
User-agent: KMail/1.5.4

Hi,

gcc 4.2.0 supports the OpenMP standard. OpenMP is an extension of the C and
C++ language through a set of pragmas. It is likely to be more and more used
over the next years, because
  - CPUs nowadays get more powerful by aggregation of multiple "cores" in
    one chip, not by increased frequency,
  - OpenMP is easy to use.

Features of the C compiler - like 'inline' or 'restrict' - are typically used
by developers only if they have an autoconf macro to detect its support. (Like
glibc functionality often is used only if there are LGPLed replacements, such
as gnulib, libintl, libiconv...)

Therefore here is an autoconf addition that makes it easier for a developer
to use OpenMP.

The macro has been tested for a long time in GNU gettext.

In the macro, it would have been simpler to blindly test for the first
supported option in a list "-fopenmp -xopenmp -openmp -mp -omp -qsmp=omp",
but many compilers accept several of these options and do something unrelated -
like to create an output file called 'penmp' or to warn about an unsupported
compiler option. The code therefore applies each option only to the brand of
compiler that is known to be likely to support it.

In the doc, I'm not sure whether one should write "The @code{AC_C_OPENMP} macro"
or "The macro @code{AC_C_OPENMP}". Please correct if needed.


2007-05-17  Bruno Haible  <address@hidden>

        * lib/autoconf/c.m4 (AC_C_OPENMP): New macro.
        * doc/autoconf.texi (C Compiler): Document AC_C_OPENMP.

*** doc/autoconf.texi   14 May 2007 16:54:55 -0000      1.1154
--- doc/autoconf.texi   17 May 2007 10:14:53 -0000
***************
*** 6593,6598 ****
--- 6593,6618 ----
  if it accepts one of those, otherwise define @code{inline} to be empty.
  @end defmac
  
+ @defmac AC_C_OPENMP
+ @acindex{C_OPENMP}
+ @cvindex _OPENMP
+ OpenMP (@url{http://www.openmp.org/}) is an extension of the C language
+ that makes it possible to optimize programs for Shared Multiprocessing
+ architectures, such as multi-core CPUs, with very small effort.
+ 
+ The @code{AC_C_OPENMP} macro sets the @code{OPENMP_CFLAGS} to the C compiler
+ flags needed for supporting OpenMP.  If the compiler already supports
+ OpenMP or if it has no way to activate OpenMP support, @code{OPENMP_CFLAGS}
+ is set to empty.  The @code{OPENMP_CFLAGS} need to be used when compiling
+ programs and when linking programs, like the @code{CFLAGS}.  The presence
+ of OpenMP support at compile time is revealed by the @code{_OPENMP}
+ preprocessor macro.
+ 
+ Linking a program with @code{OPENMP_CFLAGS} typically adds one more shared
+ library to the program's dependencies, therefore its use is recommended only
+ on programs that actually use code conditional on @code{#ifdef _OPENMP}.
+ @end defmac
+ 
  @defmac AC_C_CHAR_UNSIGNED
  @acindex{C_CHAR_UNSIGNED}
  @cvindex __CHAR_UNSIGNED__
*** lib/autoconf/c.m4   14 May 2007 16:54:55 -0000      1.247
--- lib/autoconf/c.m4   17 May 2007 10:14:53 -0000
***************
*** 1841,1843 ****
--- 1841,1998 ----
      fi
    fi
  ])
+ 
+ 
+ # AC_C_OPENMP
+ # -----------
+ # Check which options need to be passed to the C compiler to support OpenMP.
+ # Set the OPENMP_CFLAGS variable to these options.
+ # The options are necessary at compile time (so the #pragmas are understood)
+ # and at link time (so the appropriate library is linked with).
+ # This macro takes care to not produce redundant options if $CC $CFLAGS 
already
+ # supports OpenMP. It also is careful to not pass options to compilers that
+ # misinterpret them; for example, most compilers accept "-openmp" and create
+ # an output file called 'penmp' rather than activating OpenMP support.
+ AC_DEFUN([AC_C_OPENMP],
+ [
+   AC_MSG_CHECKING([whether to use OpenMP])
+   AC_ARG_ENABLE(openmp,
+     [  --disable-openmp        do not use OpenMP],
+     [ac_openmp_choice="$enableval"],
+     [ac_openmp_choice=yes])
+   AC_MSG_RESULT([$ac_openmp_choice])
+   OPENMP_CFLAGS=
+   if test "$ac_openmp_choice" = yes; then
+     AC_MSG_CHECKING([for $CC option to support OpenMP])
+     AC_CACHE_VAL([ac_cv_prog_cc_openmp], [
+       ac_cv_prog_cc_openmp=no
+       AC_COMPILE_IFELSE([
+ #ifndef _OPENMP
+  Unlucky
+ #endif
+         ], [ac_cv_prog_cc_openmp=none])
+       if test "$ac_cv_prog_cc_openmp" = no; then
+         dnl Try these flags:
+         dnl   GCC >= 4.2           -fopenmp
+         dnl   SunPRO C             -xopenmp
+         dnl   Intel C              -openmp
+         dnl   SGI C, PGI C         -mp
+         dnl   Tru64 Compaq C       -omp
+         dnl   AIX IBM C            -qsmp=omp
+         if test "$GCC" = yes; then
+           dnl --- Test for GCC.
+           gt_save_CFLAGS="$CFLAGS"
+           CFLAGS="$CFLAGS -fopenmp"
+           AC_COMPILE_IFELSE([
+ #ifndef _OPENMP
+  Unlucky
+ #endif
+             ], [ac_cv_prog_cc_openmp="-fopenmp"])
+           CFLAGS="$gt_save_CFLAGS"
+         else
+           dnl --- Test for SunPRO C.
+           AC_EGREP_CPP([Brand], [
+ #if defined __SUNPRO_C || defined __SUNPRO_CC
+  Brand
+ #endif
+             ], ac_openmp_result=yes, ac_openmp_result=no)
+           if test $ac_openmp_result = yes; then
+             gt_save_CFLAGS="$CFLAGS"
+             CFLAGS="$CFLAGS -xopenmp"
+             AC_COMPILE_IFELSE([
+ #ifndef _OPENMP
+  Unlucky
+ #endif
+               ], [ac_cv_prog_cc_openmp="-xopenmp"])
+             CFLAGS="$gt_save_CFLAGS"
+           else
+             dnl --- Test for Intel C.
+             AC_EGREP_CPP([Brand], [
+ #if defined __INTEL_COMPILER
+  Brand
+ #endif
+               ], ac_openmp_result=yes, ac_openmp_result=no)
+             if test $ac_openmp_result = yes; then
+               gt_save_CFLAGS="$CFLAGS"
+               CFLAGS="$CFLAGS -openmp"
+               AC_COMPILE_IFELSE([
+ #ifndef _OPENMP
+  Unlucky
+ #endif
+                 ], [ac_cv_prog_cc_openmp="-openmp"])
+               CFLAGS="$gt_save_CFLAGS"
+             else
+               dnl --- Test for SGI C, PGI C.
+               AC_EGREP_CPP([Brand], [
+ #if defined __sgi || defined __PGI || defined __PGIC__
+  Brand
+ #endif
+                 ], ac_openmp_result=yes, ac_openmp_result=no)
+               if test $ac_openmp_result = yes; then
+                 gt_save_CFLAGS="$CFLAGS"
+                 CFLAGS="$CFLAGS -mp"
+                 AC_COMPILE_IFELSE([
+ #ifndef _OPENMP
+  Unlucky
+ #endif
+                   ], [ac_cv_prog_cc_openmp="-mp"])
+                 CFLAGS="$gt_save_CFLAGS"
+               else
+                 dnl --- Test for Compaq C.
+                 AC_EGREP_CPP([Brand], [
+ #if defined __DECC || defined __DECCXX
+  Brand
+ #endif
+                   ], ac_openmp_result=yes, ac_openmp_result=no)
+                 if test $ac_openmp_result = yes; then
+                   gt_save_CFLAGS="$CFLAGS"
+                   CFLAGS="$CFLAGS -omp"
+                   AC_COMPILE_IFELSE([
+ #ifndef _OPENMP
+  Unlucky
+ #endif
+                     ], [ac_cv_prog_cc_openmp="-omp"])
+                   CFLAGS="$gt_save_CFLAGS"
+                 else
+                   dnl --- Test for AIX IBM C.
+                   AC_EGREP_CPP([Brand], [
+ #if defined _AIX
+  Brand
+ #endif
+                     ], ac_openmp_result=yes, ac_openmp_result=no)
+                   if test $ac_openmp_result = yes; then
+                     gt_save_CFLAGS="$CFLAGS"
+                     CFLAGS="$CFLAGS -qsmp=omp"
+                     AC_COMPILE_IFELSE([
+ #ifndef _OPENMP
+  Unlucky
+ #endif
+                       ], [ac_cv_prog_cc_openmp="-qsmp=omp"])
+                     CFLAGS="$gt_save_CFLAGS"
+                   else
+                     :
+                   fi
+                 fi
+               fi
+             fi
+           fi
+         fi
+       fi
+       ])
+     case $ac_cv_prog_cc_openmp in
+       none)
+         AC_MSG_RESULT([none needed]) ;;
+       no)
+         AC_MSG_RESULT([unsupported]) ;;
+       *)
+         AC_MSG_RESULT([$ac_cv_prog_cc_openmp]) ;;
+     esac
+     case $ac_cv_prog_cc_openmp in
+       none | no)
+         OPENMP_CFLAGS= ;;
+       *)
+         OPENMP_CFLAGS=$ac_cv_prog_cc_openmp ;;
+     esac
+   fi
+   AC_SUBST([OPENMP_CFLAGS])
+ ])





reply via email to

[Prev in Thread] Current Thread [Next in Thread]