maint: update almost all copyright ranges to include 2011
[gnulib.git] / m4 / openmp.m4
1 # openmp.m4 serial 7
2 dnl Copyright (C) 2006-2011 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.
6
7 dnl This file can be removed once we assume autoconf >= 2.62.
8
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], [], [
12
13 # _AC_LANG_OPENMP
14 # ---------------
15 # Expands to some language dependent source code for testing the presence of
16 # OpenMP.
17 AC_DEFUN([_AC_LANG_OPENMP],
18 [_AC_LANG_DISPATCH([$0], _AC_LANG, $@)])
19
20 # _AC_LANG_OPENMP(C)
21 # ------------------
22 m4_define([_AC_LANG_OPENMP(C)],
23 [
24 #ifndef _OPENMP
25  choke me
26 #endif
27 #include <omp.h>
28 int main () { return omp_get_num_threads (); }
29 ])
30
31 # _AC_LANG_OPENMP(C++)
32 # --------------------
33 m4_copy([_AC_LANG_OPENMP(C)], [_AC_LANG_OPENMP(C++)])
34
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])])
39
40 # _AC_LANG_OPENMP(Fortran)
41 # ---------------------------
42 m4_copy([_AC_LANG_OPENMP(Fortran 77)], [_AC_LANG_OPENMP(Fortran)])
43
44 # AC_OPENMP
45 # ---------
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
48 # options.
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.
55 AC_DEFUN([AC_OPENMP],
56 [
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'
66           dnl Try these flags:
67           dnl   GCC >= 4.2           -fopenmp
68           dnl   SunPRO C             -xopenmp
69           dnl   Intel C              -openmp
70           dnl   SGI C, PGI C         -mp
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
85               break
86             fi
87           done])])
88     case $ac_cv_prog_[]_AC_LANG_ABBREV[]_openmp in #(
89       "none needed" | unsupported)
90         ;; #(
91       *)
92         OPENMP_[]_AC_LANG_PREFIX[]FLAGS=$ac_cv_prog_[]_AC_LANG_ABBREV[]_openmp ;;
93     esac
94   fi
95   AC_SUBST([OPENMP_]_AC_LANG_PREFIX[FLAGS])
96 ])
97
98 ])