File: omp.m4

package info (click to toggle)
cpl 7.1.3-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 14,808 kB
  • sloc: ansic: 132,627; javascript: 6,382; sh: 4,232; makefile: 637
file content (121 lines) | stat: -rw-r--r-- 4,610 bytes parent folder | download | duplicates (13)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# NOTE:
#   The macros in this file were taken from c.m4 which is shipped with
#   Autoconf. Newer version of Autoconf provide these macros to check for
#   OpenMP support. For preparing CPL releases it would be sufficient to use
#   a recent Autotools installation, however the nightly build system, is still
#   using an Autotools installation which is too old, and there is no plan for
#   upgrading it yet, hence the macros have been copied and the renamed so that
#   there are no name clashes in case a new version of Autoconf is used.
#
#   However the symbols produced by these macros are kept identical to the
#   official macro versions, so that removing this file will have (almost) no
#   impact when the Autotools installation of the nightly build system will
#   be upgraded.
#
#   In addition, the command line option to disable OpenMP support has been
#   remove, so that the macro just reports the results, which can be used
#   by a calling custom macro.  
#
 
# _CPL_LANG_OPENMP
# ---------------
# Expands to some language dependent source code for testing the presence of
# OpenMP.
AC_DEFUN([_CPL_LANG_OPENMP],
[AC_LANG_SOURCE([_AC_LANG_DISPATCH([$0], _AC_LANG, $@)])])

# _CPL_LANG_OPENMP(C)
# ------------------
# This tries to see if linking properly resolves omp_get_num_threads() object.
# It also checks that the #pragma omp threadprivate directive is supported,
# since some combinations of compiler/OS do not support it (e.g. gcc/OSX).
m4_define([_CPL_LANG_OPENMP(C)],
[
#ifndef _OPENMP
 choke me
#endif
#include <omp.h>
int var;
#pragma omp threadprivate(var)
int main () { 
return omp_get_num_threads (); 
}
])

# _CPL_LANG_OPENMP(C++)
# --------------------
m4_copy([_CPL_LANG_OPENMP(C)], [_CPL_LANG_OPENMP(C++)])

# _CPL_LANG_OPENMP(Fortran 77)
# ---------------------------
m4_define([_CPL_LANG_OPENMP(Fortran 77)],
[
      program main
      implicit none
!$    integer tid
      tid = 42
      call omp_set_num_threads(2)
      end
])

# _CPL_LANG_OPENMP(Fortran)
# -------------------------
m4_copy([_CPL_LANG_OPENMP(Fortran 77)], [_CPL_LANG_OPENMP(Fortran)])

# CPL_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([CPL_OPENMP],
[
  OPENMP_[]_AC_LANG_PREFIX[]FLAGS=
  dnl AC_ARG_ENABLE([openmp],
  dnl   [AS_HELP_STRING([--disable-openmp], [do not use OpenMP])])
  dnl if test "$enable_openmp" != no; then
  AC_CACHE_CHECK([for the compiler option to support OpenMP],
    [ac_cv_prog_[]_AC_LANG_ABBREV[]_openmp],
    [AC_LINK_IFELSE([_CPL_LANG_OPENMP],
    [ac_cv_prog_[]_AC_LANG_ABBREV[]_openmp='none needed'],
    [ac_cv_prog_[]_AC_LANG_ABBREV[]_openmp='unsupported'
	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
    dnl   Cray CCE             -homp
    dnl   NEC SX               -Popenmp
    dnl   Lahey Fortran (Linux)  --openmp
	dnl If in this loop a compiler is passed an option that it doesn't
	dnl understand or that it misinterprets, the AC_LINK_IFELSE test
	dnl will fail (since we know that it failed without the option),
	dnl therefore the loop will continue searching for an option, and
	dnl no output file called 'penmp' or 'mp' is created.
	for ac_option in -fopenmp -xopenmp -openmp -mp -omp -qsmp=omp -homp \
                     -Popenmp --openmp; do
	  ac_save_[]_AC_LANG_PREFIX[]FLAGS=$[]_AC_LANG_PREFIX[]FLAGS
	  _AC_LANG_PREFIX[]FLAGS="$[]_AC_LANG_PREFIX[]FLAGS $ac_option"
	  AC_LINK_IFELSE([_CPL_LANG_OPENMP],
	    [ac_cv_prog_[]_AC_LANG_ABBREV[]_openmp=$ac_option])
	  _AC_LANG_PREFIX[]FLAGS=$ac_save_[]_AC_LANG_PREFIX[]FLAGS
	  if test "$ac_cv_prog_[]_AC_LANG_ABBREV[]_openmp" != unsupported; then
	    break
	  fi
    done])])
  case $ac_cv_prog_[]_AC_LANG_ABBREV[]_openmp in #(
  "none needed" | unsupported)
    ;; #(
  *)
    OPENMP_[]_AC_LANG_PREFIX[]FLAGS=$ac_cv_prog_[]_AC_LANG_ABBREV[]_openmp ;;
  esac
  dnl fi
  AC_SUBST([OPENMP_]_AC_LANG_PREFIX[FLAGS])
])