2 dnl Copyright (C) 2006-2018 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)],
43 call omp_set_num_threads(2)
47 # _AC_LANG_OPENMP(Fortran)
48 # ---------------------------
49 m4_copy([_AC_LANG_OPENMP(Fortran 77)], [_AC_LANG_OPENMP(Fortran)])
53 # Check which options need to be passed to the C compiler to support OpenMP.
54 # Set the OPENMP_CFLAGS / OPENMP_CXXFLAGS / OPENMP_FFLAGS variable to these
56 # The options are necessary at compile time (so the #pragmas are understood)
57 # and at link time (so the appropriate library is linked with).
58 # This macro takes care to not produce redundant options if $CC $CFLAGS already
59 # supports OpenMP. It also is careful to not pass options to compilers that
60 # misinterpret them; for example, most compilers accept "-openmp" and create
61 # an output file called 'penmp' rather than activating OpenMP support.
64 OPENMP_[]_AC_LANG_PREFIX[]FLAGS=
65 AC_ARG_ENABLE([openmp],
66 [AS_HELP_STRING([--disable-openmp], [do not use OpenMP])])
67 if test "$enable_openmp" != no; then
68 AC_CACHE_CHECK([for $CC option to support OpenMP],
69 [ac_cv_prog_[]_AC_LANG_ABBREV[]_openmp],
70 [AC_LINK_IFELSE([_AC_LANG_OPENMP],
71 [ac_cv_prog_[]_AC_LANG_ABBREV[]_openmp='none needed'],
72 [ac_cv_prog_[]_AC_LANG_ABBREV[]_openmp='unsupported'
74 dnl GCC >= 4.2 -fopenmp
78 dnl Tru64 Compaq C -omp
79 dnl IBM C (AIX, Linux) -qsmp=omp
82 dnl Lahey Fortran (Linux) --openmp
83 dnl If in this loop a compiler is passed an option that it doesn't
84 dnl understand or that it misinterprets, the AC_LINK_IFELSE test
85 dnl will fail (since we know that it failed without the option),
86 dnl therefore the loop will continue searching for an option, and
87 dnl no output file called 'penmp' or 'mp' is created.
88 for ac_option in -fopenmp -xopenmp -openmp -mp -omp -qsmp=omp -homp \
90 ac_save_[]_AC_LANG_PREFIX[]FLAGS=$[]_AC_LANG_PREFIX[]FLAGS
91 _AC_LANG_PREFIX[]FLAGS="$[]_AC_LANG_PREFIX[]FLAGS $ac_option"
92 AC_LINK_IFELSE([_AC_LANG_OPENMP],
93 [ac_cv_prog_[]_AC_LANG_ABBREV[]_openmp=$ac_option])
94 _AC_LANG_PREFIX[]FLAGS=$ac_save_[]_AC_LANG_PREFIX[]FLAGS
95 if test "$ac_cv_prog_[]_AC_LANG_ABBREV[]_openmp" != unsupported; then
99 case $ac_cv_prog_[]_AC_LANG_ABBREV[]_openmp in #(
100 "none needed" | unsupported)
103 OPENMP_[]_AC_LANG_PREFIX[]FLAGS=$ac_cv_prog_[]_AC_LANG_ABBREV[]_openmp ;;
106 AC_SUBST([OPENMP_]_AC_LANG_PREFIX[FLAGS])