[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: detection and support of OpenMP
From: |
Bruno Haible |
Subject: |
Re: detection and support of OpenMP |
Date: |
Fri, 18 May 2007 00:49:16 +0200 |
User-agent: |
KMail/1.5.4 |
Ralf Wildenhues wrote:
> > Yes, they sell a port of XLC for Linux [1]. But I have no
> > info about the command-line option for OpenMP in this compiler.
> > [1]
> http://www-306.ibm.com/software/info/ecatalog/en_US/products/Q860134T18351F02.html?&S_TACT=none&S_CMP=none
>
> As per
> <http://www-1.ibm.com/support/docview.wss?rs=2239&context=SSJT9L&dc=DA410&uid=swg27007011&loc=en_US&cs=utf-8&lang=en>
>
> it uses -qsmp=omp as well. As per
> <http://predef.sourceforge.net/precomp.html#sec17>,
> you should be able to use __xlC__ or __IBMC__ / __IBMCPP__ I guess.
Thanks for this info; it's integrated in the patch in the other mail.
(I see that xlc and xlC define both __xlc__ and __xlC__.)
> I've only now found this macro which seems to already have done this step:
> <http://autoconf-archive.cryp.to/ax_openmp.html>.
> Sorry it did not occur to me earlier, that approach looks like the
> canonical way to generalize it to Fortran and C++.
Find attached a draft, that still works in C and might work for C++. For
Fortran, I don't know how to distinguish the various compiler brands.
The GNU one can be tested through $ac_compiler_gnu, I suppose? But the
others?
> FYI, the potential downside of this is that one can easily forget to add
> $OPENMP_CFLAGS to CFLAGS before the next compile test that may have a
> different outcome depending on this.
This is not a big problems: Such mistakes will become apparent immediately,
because no compiler I know of has OpenMP support enabled by default.
> make check TESTSUITEFLAGS='-k AC_C_OPENMP -v -d -x'
This fails, apparently because the variables OPENMP_CFLAGS and enable_openmp
(which you told me to use instead of ac_openmp_choice) are not inside
autoconf's namespace. You know how to fix the testsuite?
Bruno
2007-05-17 Bruno Haible <address@hidden>
* lib/autoconf/c.m4 (_AC_LANG_OPENMP, AC_OPENMP): New macros.
* doc/autoconf.texi (Generic Compiler Characteristics): Document
AC_OPENMP.
* NEWS: Mention AC_OPENMP.
*** NEWS 14 May 2007 16:54:55 -0000 1.428
--- NEWS 17 May 2007 22:44:22 -0000
***************
*** 1,5 ****
--- 1,7 ----
* Major changes in Autoconf 2.61b (????-??-??)
+ ** New macro AC_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
*** doc/autoconf.texi 14 May 2007 16:54:55 -0000 1.1154
--- doc/autoconf.texi 17 May 2007 22:44:30 -0000
***************
*** 6259,6264 ****
--- 6259,6300 ----
Execute @var{action-if-fails} if the value cannot be determined correctly.
@end defmac
+ @defmac AC_OPENMP
+ @acindex{OPENMP}
+ @cvindex _OPENMP
+ OpenMP (@url{http://www.openmp.org/}) is an extension of the C, C++, and
+ Fortran languages that makes it possible to optimize programs for Shared
+ Multiprocessing architectures, such as multi-core CPUs, with very small
+ effort.
+
+ If the current language is set to C, the macro @code{AC_OPENMP} sets the
+ variable @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. Also, the
+ user can reject OpenMP support if it is not the default, by invoking
+ @samp{configure} with the @samp{--disable-openmp} option; then
+ @code{OPENMP_CFLAGS} is set to empty as well.
+
+ The @code{OPENMP_CFLAGS} need to be used when compiling programs, when
+ preprocessing program source, and when linking programs. Therefore you
+ need to add them to the @code{CFLAGS} and @code{CPPFLAGS} of your programs
+ that use OpenMP. The presence of OpenMP support at compile time is revealed
+ by the preprocessor macro @code{_OPENMP}.
+
+ 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}.
+
+ If the current language is set to C++, @code{AC_OPENMP} sets the variable
+ @code{OPENMP_CXXFLAGS}, suitably for the C++ compiler. The same remarks
+ hold as for C.
+
+ If the current language is set to Fortran 77 or Fortran, @code{AC_OPENMP}
+ sets the variable @code{OPENMP_FFLAGS} or @code{OPENMP_FCFLAGS}, respectively.
+ Similar remarks as for C hold, except that @code{CPPFLAGS} is not used for
+ Fortran, and there is no preprocessor macro signalling the support of OpenMP.
+ @end defmac
+
@defmac AC_LANG_WERROR
@acindex{LANG_WERROR}
Normally Autoconf ignores warnings generated by the compiler, linker, and
*** lib/autoconf/c.m4 14 May 2007 16:54:55 -0000 1.247
--- lib/autoconf/c.m4 17 May 2007 22:44:31 -0000
***************
*** 1841,1843 ****
--- 1841,1965 ----
fi
fi
])
+
+
+ # _AC_LANG_OPENMP
+ # ---------------
+ # Expands to some language dependent source code for testing the presence of
+ # OpenMP.
+ AC_DEFUN([_AC_LANG_OPENMP],
+ [_AC_LANG_DISPATCH([$0], _AC_LANG, $@)])
+
+ # _AC_LANG_OPENMP(C)
+ # ------------------
+ m4_define([_AC_LANG_OPENMP(C)],
+ [
+ #ifndef _OPENMP
+ choke me
+ #endif
+ #include <omp.h>
+ int main () { return omp_get_num_threads (); }
+ ])
+
+ # _AC_LANG_OPENMP(C++)
+ # --------------------
+ m4_copy([_AC_LANG_OPENMP(C)], [_AC_LANG_OPENMP(C++)])
+
+ # _AC_LANG_OPENMP(Fortran 77)
+ # ---------------------------
+ m4_define([_AC_LANG_OPENMP(Fortran 77)],
+ [AC_LANG_FUNC_LINK_TRY([omp_get_num_threads])])
+
+ # _AC_LANG_OPENMP(Fortran)
+ # ---------------------------
+ m4_copy([_AC_LANG_OPENMP(Fortran 77)], [_AC_LANG_OPENMP(Fortran)])
+
+ # AC_OPENMP
+ # ---------
+ # Check which options need to be passed to the C compiler to support OpenMP.
+ # Set the OPENMP_CFLAGS / OPENMP_CXXFLAGS / OPENMP_FFLAGS 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_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_[]_AC_LANG_PREFIX[]FLAGS=
+ if test "$enable_openmp" = yes; then
+ AC_MSG_CHECKING([for $CC option to support OpenMP])
+ AC_CACHE_VAL([ac_cv_prog_[]_AC_LANG_ABBREV[]_openmp], [
+ ac_cv_prog_[]_AC_LANG_ABBREV[]_openmp=unsupported
+ AC_LINK_IFELSE([_AC_LANG_OPENMP],
+ [ac_cv_prog_[]_AC_LANG_ABBREV[]_openmp="none needed"])
+ if test "$ac_cv_prog_[]_AC_LANG_ABBREV[]_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 ac_brand in GCC SunPRO Intel SGI/PGI Compaq IBM; do
+ case $ac_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 $ac_brand = GCC; then
+ if test "$ac_compiler_gnu" = 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_[]_AC_LANG_PREFIX[]FLAGS=$[]_AC_LANG_PREFIX[]FLAGS
+ _AC_LANG_PREFIX[]FLAGS="$[]_AC_LANG_PREFIX[]FLAGS $ac_option"
+ AC_LINK_IFELSE([_AC_LANG_OPENMP],
+ [ac_cv_prog_[]_AC_LANG_ABBREV[]_openmp=$ac_option])
+ _AC_LANG_PREFIX[]FLAGS=$ac_save_[]_AC_LANG_PREFIX[]FLAGS
+ break
+ fi
+ done
+ fi
+ ])
+ AC_MSG_RESULT([$ac_cv_prog_[]_AC_LANG_ABBREV[]_openmp])
+ case $ac_cv_prog_[]_AC_LANG_ABBREV[]_openmp in
+ "none needed" | unsupported)
+ OPENMP_[]_AC_LANG_PREFIX[]FLAGS= ;;
+ *)
+
OPENMP_[]_AC_LANG_PREFIX[]FLAGS=$ac_cv_prog_[]_AC_LANG_ABBREV[]_openmp ;;
+ esac
+ fi
+ AC_SUBST([OPENMP_]_AC_LANG_PREFIX[FLAGS])
+ ])
Re: detection and support of OpenMP, Noah Misch, 2007/05/17
Re: detection and support of OpenMP, Paul Eggert, 2007/05/17