maint: update copyright
[gnulib.git] / m4 / openmp.m4
1 # openmp.m4 serial 9
2 dnl Copyright (C) 2006-2014 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 [
39       program main
40       implicit none
41 !$    integer tid
42       tid = 42
43       call omp_set_num_threads(2)
44       end
45 ])
46
47 # _AC_LANG_OPENMP(Fortran)
48 # ---------------------------
49 m4_copy([_AC_LANG_OPENMP(Fortran 77)], [_AC_LANG_OPENMP(Fortran)])
50
51 # AC_OPENMP
52 # ---------
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
55 # options.
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.
62 AC_DEFUN([AC_OPENMP],
63 [
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'
73           dnl Try these flags:
74           dnl   GCC >= 4.2           -fopenmp
75           dnl   SunPRO C             -xopenmp
76           dnl   Intel C              -openmp
77           dnl   SGI C, PGI C         -mp
78           dnl   Tru64 Compaq C       -omp
79           dnl   IBM C (AIX, Linux)   -qsmp=omp
80           dnl   Cray CCE             -homp
81           dnl   NEC SX               -Popenmp
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 \
89                            -Popenmp --openmp; do
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
96               break
97             fi
98           done])])
99     case $ac_cv_prog_[]_AC_LANG_ABBREV[]_openmp in #(
100       "none needed" | unsupported)
101         ;; #(
102       *)
103         OPENMP_[]_AC_LANG_PREFIX[]FLAGS=$ac_cv_prog_[]_AC_LANG_ABBREV[]_openmp ;;
104     esac
105   fi
106   AC_SUBST([OPENMP_]_AC_LANG_PREFIX[FLAGS])
107 ])
108
109 ])