]> git.ipfire.org Git - thirdparty/autoconf.git/commitdiff
* doc/autoconf.texi (C Compiler): Tweak OpenMP documentation a bit.
authorPaul Eggert <eggert@cs.ucla.edu>
Mon, 21 May 2007 17:39:09 +0000 (17:39 +0000)
committerPaul Eggert <eggert@cs.ucla.edu>
Mon, 21 May 2007 17:39:09 +0000 (17:39 +0000)
2007-05-21  Bruno Haible  <bruno@clisp.org>

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

ChangeLog
NEWS
doc/autoconf.texi
lib/autoconf/c.m4

index b06ab4b2802e17f595ca0b28efbb37fe30ddc859..624a723aaf7561128ec0316b2e944700cdf76b96 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2007-05-21  Paul Eggert  <eggert@cs.ucla.edu>
+
+       * doc/autoconf.texi (C Compiler): Tweak OpenMP documentation a bit.
+
+2007-05-21  Bruno Haible  <bruno@clisp.org>
+
+       * lib/autoconf/c.m4 (AC_C_OPENMP): New macro.
+       * doc/autoconf.texi (C Compiler): Document AC_C_OPENMP.
+       * NEWS: Mention AC_C_OPENMP.
+
 2007-05-17  Ralf Wildenhues  <Ralf.Wildenhues@gmx.de>
 
        * bin/autom4te.in: Fix typos.
diff --git a/NEWS b/NEWS
index ca4615b0bc8348eb3e09422395039498be4c6d07..a91673097586c9fc9a0bebce4fb01df16573be7a 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -1,5 +1,7 @@
 * Major changes in Autoconf 2.61b (????-??-??)
 
+** New macro AC_C_OPENMP.
+
 ** AC_C_BIGENDIAN now supports universal binaries a la Mac OS X.
 
 ** AC_C_RESTRICT now prefers to #define 'restrict' to a variant spelling
index dd0701dfbc20f67eaf2044752a863618eeacb01e..7ddd6f55ef83d64da6e0db4ce7850862ec168fd0 100644 (file)
@@ -6593,6 +6593,33 @@ Otherwise define @code{inline} to @code{__inline__} or @code{__inline}
 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/}) specifies extensions of the C,
+C++, and Fortran languages that simplify optimization of shared memory
+parallelism, which is a common problem on multicore CPUs.
+
+The macro @code{AC_C_OPENMP} sets the variable @code{OPENMP_CFLAGS} to
+the C compiler flags needed for supporting OpenMP@.
+@code{OPENMP_CFLAGS} is set to empty if the compiler already supports
+OpenMP, if it has no way to activate OpenMP support, or if the user
+rejects OpenMP support by invoking @samp{configure} with the
+@samp{--disable-openmp} option.
+
+@code{OPENMP_CFLAGS} needs to be used when compiling programs, when
+preprocessing program source, and when linking programs.  Therefore you
+need to add @code{$(OPENMP_CFLAGS)} to the @code{CFLAGS} of programs
+that use OpenMP@.  If you preprocess OpenMP-specific code, you also need
+to add @code{$(OPENMP_CFLAGS)} to @code{CPPFLAGS}.  The presence of
+OpenMP support is revealed at compile time by the preprocessor macro
+@code{_OPENMP}.
+
+Linking a program with @code{OPENMP_CFLAGS} typically adds one more
+shared library to the program's dependencies, so its use is recommended
+only on programs that actually require OpenMP.
+@end defmac
+
 @defmac AC_C_CHAR_UNSIGNED
 @acindex{C_CHAR_UNSIGNED}
 @cvindex __CHAR_UNSIGNED__
index 7d816b5d82f7c702008052b87ae90196dc00f527..d860189aebc6bb1596d6c911d306d10e56be44a6 100644 (file)
@@ -1841,3 +1841,103 @@ AC_DEFUN([AC_C_TYPEOF],
     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,
+    [AS_HELP_STRING([--disable-openmp], [do not use OpenMP])],
+    [],
+    [enable_openmp=yes])
+  AC_MSG_RESULT([$enable_openmp])
+  OPENMP_CFLAGS=
+  if test "$enable_openmp" = yes; then
+    AC_MSG_CHECKING([for $CC option to support OpenMP])
+    AC_CACHE_VAL([ac_cv_prog_cc_openmp], [
+      ac_cv_prog_cc_openmp=unsupported
+      AC_LINK_IFELSE([
+#ifndef _OPENMP
+ choke me
+#endif
+#include <omp.h>
+int main () { return omp_get_num_threads (); }
+        ], [ac_cv_prog_cc_openmp="none needed"])
+      if test "$ac_cv_prog_cc_openmp" = unsupported; 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   IBM C (AIX, Linux)   -qsmp=omp
+        for brand in GCC SunPRO Intel SGI/PGI Compaq IBM; do
+          case $brand in
+            GCC)
+              ac_conditional='defined __GNUC__'
+              ac_option='-fopenmp' ;;
+            SunPRO)
+              ac_conditional='defined __SUNPRO_C || defined __SUNPRO_CC'
+              ac_option='-xopenmp' ;;
+            Intel)
+              ac_conditional='defined __INTEL_COMPILER'
+              ac_option='-openmp' ;;
+            SGI/PGI)
+              ac_conditional='defined __sgi || defined __PGI || defined __PGIC__'
+              ac_option='-mp' ;;
+            Compaq)
+              ac_conditional='defined __DECC || defined __DECCXX'
+              ac_option='-omp' ;;
+            IBM)
+              ac_conditional='defined __xlc__ || defined __xlC__'
+              ac_option='-qsmp=omp' ;;
+          esac
+          if test $brand = GCC; then
+            if test "$GCC" = yes; then
+              ac_openmp_result=yes
+            else
+              ac_openmp_result=no
+            fi
+          else
+            AC_EGREP_CPP([Brand], [
+              #if $ac_conditional
+               Brand
+              #endif
+              ], [ac_openmp_result=yes], [ac_openmp_result=no])
+          fi
+          if test $ac_openmp_result = yes; then
+            ac_save_CFLAGS=$CFLAGS
+            CFLAGS="$CFLAGS $ac_option"
+            AC_LINK_IFELSE([
+#ifndef _OPENMP
+ choke me
+#endif
+#include <omp.h>
+int main () { return omp_get_num_threads (); }
+              ], [ac_cv_prog_cc_openmp=$ac_option])
+            CFLAGS=$ac_save_CFLAGS
+            break
+          fi
+        done
+      fi
+      ])
+    AC_MSG_RESULT([$ac_cv_prog_cc_openmp])
+    case $ac_cv_prog_cc_openmp in
+      "none needed" | unsupported)
+        OPENMP_CFLAGS= ;;
+      *)
+        OPENMP_CFLAGS=$ac_cv_prog_cc_openmp ;;
+    esac
+  fi
+  AC_SUBST([OPENMP_CFLAGS])
+])