2 dnl Copyright (C) 2006-2010 Free Software Foundation, Inc.
3 dnl This file is free software; the Free Software Foundation
4 dnl gives unlimited permission to copy and/or distribute it,
5 dnl with or without modifications, as long as this notice is preserved.
7 dnl This file can be removed once we assume autoconf >= 2.62.
9 dnl Expand to nothing in autoconf >= 2.62. m4_copy has a different
10 dnl semantic in autoconf > 2.63.
11 m4_ifdef([AC_OPENMP], [], [
15 # Expands to some language dependent source code for testing the presence of
17 AC_DEFUN([_AC_LANG_OPENMP],
18 [_AC_LANG_DISPATCH([$0], _AC_LANG, $@)])
22 m4_define([_AC_LANG_OPENMP(C)],
28 int main () { return omp_get_num_threads (); }
31 # _AC_LANG_OPENMP(C++)
32 # --------------------
33 m4_copy([_AC_LANG_OPENMP(C)], [_AC_LANG_OPENMP(C++)])
35 # _AC_LANG_OPENMP(Fortran 77)
36 # ---------------------------
37 m4_define([_AC_LANG_OPENMP(Fortran 77)],
38 [AC_LANG_FUNC_LINK_TRY([omp_get_num_threads])])
40 # _AC_LANG_OPENMP(Fortran)
41 # ---------------------------
42 m4_copy([_AC_LANG_OPENMP(Fortran 77)], [_AC_LANG_OPENMP(Fortran)])
46 # Check which options need to be passed to the C compiler to support OpenMP.
47 # Set the OPENMP_CFLAGS / OPENMP_CXXFLAGS / OPENMP_FFLAGS variable to these
49 # The options are necessary at compile time (so the #pragmas are understood)
50 # and at link time (so the appropriate library is linked with).
51 # This macro takes care to not produce redundant options if $CC $CFLAGS already
52 # supports OpenMP. It also is careful to not pass options to compilers that
53 # misinterpret them; for example, most compilers accept "-openmp" and create
54 # an output file called 'penmp' rather than activating OpenMP support.
57 OPENMP_[]_AC_LANG_PREFIX[]FLAGS=
58 AC_ARG_ENABLE([openmp],
59 [AS_HELP_STRING([--disable-openmp], [do not use OpenMP])])
60 if test "$enable_openmp" != no; then
61 AC_CACHE_CHECK([for $CC option to support OpenMP],
62 [ac_cv_prog_[]_AC_LANG_ABBREV[]_openmp],
63 [AC_LINK_IFELSE([_AC_LANG_OPENMP],
64 [ac_cv_prog_[]_AC_LANG_ABBREV[]_openmp='none needed'],
65 [ac_cv_prog_[]_AC_LANG_ABBREV[]_openmp='unsupported'
67 dnl GCC >= 4.2 -fopenmp
71 dnl Tru64 Compaq C -omp
72 dnl IBM C (AIX, Linux) -qsmp=omp
73 dnl If in this loop a compiler is passed an option that it doesn't
74 dnl understand or that it misinterprets, the AC_LINK_IFELSE test
75 dnl will fail (since we know that it failed without the option),
76 dnl therefore the loop will continue searching for an option, and
77 dnl no output file called 'penmp' or 'mp' is created.
78 for ac_option in -fopenmp -xopenmp -openmp -mp -omp -qsmp=omp; do
79 ac_save_[]_AC_LANG_PREFIX[]FLAGS=$[]_AC_LANG_PREFIX[]FLAGS
80 _AC_LANG_PREFIX[]FLAGS="$[]_AC_LANG_PREFIX[]FLAGS $ac_option"
81 AC_LINK_IFELSE([_AC_LANG_OPENMP],
82 [ac_cv_prog_[]_AC_LANG_ABBREV[]_openmp=$ac_option])
83 _AC_LANG_PREFIX[]FLAGS=$ac_save_[]_AC_LANG_PREFIX[]FLAGS
84 if test "$ac_cv_prog_[]_AC_LANG_ABBREV[]_openmp" != unsupported; then
88 case $ac_cv_prog_[]_AC_LANG_ABBREV[]_openmp in #(
89 "none needed" | unsupported)
92 OPENMP_[]_AC_LANG_PREFIX[]FLAGS=$ac_cv_prog_[]_AC_LANG_ABBREV[]_openmp ;;
95 AC_SUBST([OPENMP_]_AC_LANG_PREFIX[FLAGS])