File: f90_check.m4

package info (click to toggle)
openmpi 1.6.5-9.1%2Bdeb8u1
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 91,628 kB
  • ctags: 44,305
  • sloc: ansic: 408,966; cpp: 44,454; sh: 27,828; makefile: 10,486; asm: 3,882; python: 1,239; lex: 805; perl: 549; csh: 253; fortran: 232; f90: 126; tcl: 12
file content (179 lines) | stat: -rw-r--r-- 8,931 bytes parent folder | download | duplicates (2)
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
dnl -*- shell-script -*-
dnl
dnl Copyright (c) 2004-2006 The Trustees of Indiana University and Indiana
dnl                         University Research and Technology
dnl                         Corporation.  All rights reserved.
dnl Copyright (c) 2004-2005 The University of Tennessee and The University
dnl                         of Tennessee Research Foundation.  All rights
dnl                         reserved.
dnl Copyright (c) 2004-2005 High Performance Computing Center Stuttgart, 
dnl                         University of Stuttgart.  All rights reserved.
dnl Copyright (c) 2004-2005 The Regents of the University of California.
dnl                         All rights reserved.
dnl Copyright (c) 2006      Cisco Systems, Inc.
dnl $COPYRIGHT$
dnl 
dnl Additional copyrights may follow
dnl 
dnl $HEADER$
dnl

# OMPI_F90_CHECK(Fortran type, expected size)
#----------------------------------------------------------------------------
# Check Fortran type/kind combinations, including:
# - whether compiler supports or not
# - size of type
# - equal to expected size
# - range (optional)
# - precision (optional)

# Note that we do *not* check for the alignment here.  This is a long,
# sordid tale.

# We have been unable to devise a F90 test that will result in a
# consistent answer.  Specifically, our prior tests have been similar
# to the f77 test -- have a small chunk of f90 code compiled with the
# C code to actually compute the offsets.  The f90 code was a
# struct-like entity (a "type") with multiple members -- on a
# character and the other of the target type.  The C code measured the
# distance between them.  But even if you use the keyword to ensure
# that the F90 compiler does not re-order this struct, you may still
# get a different alignment answer than the F77 test (!).  This is
# apparently because F90 allows compilers to align types differently
# according to use (in common blocks, as standalone variables, and as
# a member of a struct).  Hence, the alignment can be different
# depending on how to measure (and use) it.  This was confirmed by
# various members of the Fortran committee and several Fortran
# compiler vendors.

# We check the F77 alignment based on common block usage, but this is
# only one of the available types for F90.  Hence, we may actually get
# a different answer between f77 and f90 in the same compiler series
# (and some compilers do!  E.g., g95 gives different answers even when
# "g95" itself is used as both the f77 and f90 compiler).

# So we gave up.

# Additionally, this was really only a sanity check anyway, because
# the way out F90 MPI layer is organized, there is no translation
# between the data and datatypes performed -- we simply invoke the F77
# layer from the F90 layer.  Hence, we make no distinction between
# them, and therefore the OMPI DDT engine uses only the F77 sizes and
# alignments.  So rather than display a warning to the user for a test
# that was questionable at best, we just eliminated the F90 alignment
# test, corresponding F77 comparison, and ensuring warning -- because
# it really didn't mean anything anyway.

# types to search is a comma-seperated list of values
AC_DEFUN([OMPI_F90_CHECK], [
    ofc_fortran_type="$1"
    ofc_expected_size="$2"

    ofc_have_type=0
    ofc_type_size=$ac_cv_sizeof_int

    # Only check if we actually want the F90 bindings / have a F90
    # compiler.  This allows us to call this macro even if there is
    # no F90 compiler.  If we have no f90 compiler, then just set a
    # bunch of defaults.
    if test "$OMPI_WANT_F90_BINDINGS" = "1"; then
        OMPI_F90_CHECK_TYPE([$1], [ofc_have_type=1], [ofc_have_type=0])
    else
        AC_MSG_CHECKING([if Fortran 90 compiler supports $ofc_fortran_type])
        AC_MSG_RESULT([skipped])
    fi

    if test "$ofc_have_type" = "1"; then
        # What is the size of this type?  

        # NOTE: Some Fortran compilers actually will return that a
        # type exists even if it doesn't support it -- the compiler
        # will automatically convert the unsupported type to a type
        # that it *does* support.  For example, if you try to use
        # INTEGER*16 and the compiler doesn't support it, it may well
        # automatically convert it to INTEGER*8 for you (!).  So we
        # have to check the actual size of the type once we determine
        # that the compiler doesn't error if we try to use it
        # (i.e,. the compiler *might* support that type).  If the size
        # doesn't match the expected size, then the compiler doesn't
        # really support it.
        OMPI_F90_GET_SIZEOF([$1], [ofc_type_size])
        if test "$ofc_expected_size" != "" -a "$ofc_type_size" != "$ofc_expected_size"; then
            AC_MSG_WARN([*** Fortran 90 $ofc_fortran_type does not have expected size!])
            AC_MSG_WARN([*** Expected $ofc_expected_size, got $ofc_type_size])
            AC_MSG_WARN([*** Disabling MPI support for Fortran $ofc_fortran_type])
            ofc_have_type=0
        else
            # If this type has an F77 counterpart, see if it's
            # supported.
            [ofc_f77_have_type=$OMPI_HAVE_FORTRAN_]m4_bpatsubst(m4_bpatsubst([$1], [*], []), [[^a-zA-Z0-9_]], [_])
            if test "$ofc_f77_have_type" = "0"; then
                AC_MSG_WARN([*** Corresponding Fortran 77 type ($1) not supported])
                AC_MSG_WARN([*** Skipping Fortran 90 type ($1)])
            else

                # Check the size of this type against its F77 counterpart
                [ofc_f77_sizeof=$OMPI_SIZEOF_FORTRAN_]m4_bpatsubst(m4_bpatsubst([$1], [*], []), [[^a-zA-Z0-9_]], [_])
                if test "$ofc_f77_sizeof" != ""; then
                    AC_MSG_CHECKING([if Fortran 77 and 90 type sizes match])
                    if test "$ofc_f77_sizeof" != "$ofc_type_size"; then
                        AC_MSG_RESULT([no])
                        AC_MSG_WARN([*** Fortran 77 size for $1 ($ofc_f77_sizeof) does not match])
                        AC_MSG_WARN([*** Fortran 90 size for $1 ($ofc_type_size)])
                        AC_MSG_ERROR([*** Cannot continue])
                    else
                        AC_MSG_RESULT([yes])
                    fi
                fi

                # If we passed in the expected size, then also add the
                # type to the relevant list of types found.
                if test "$ofc_expected_size" != ""; then
                    ofc_letter=m4_translit(m4_bpatsubst($1, [^\(.\).+], [[\1]]), [a-z], [A-Z])
                    ofc_str="OMPI_F90_${ofc_letter}KINDS=\"\$OMPI_F90_${ofc_letter}KINDS $ofc_type_size \""
                    eval $ofc_str
                fi
            fi
        fi
    fi

    # We always need these defines -- even if we don't have a given
    # type, there are some places in the code where we have to have
    # *something*.  Note that the bpatsubst's are the same as used
    # above (see comment above), but we added a translit to make them
    # uppercase.

    # If we got a pretty name, use that as the basis.  If not, use the
    # first part of the provided fortran type (e.g.,
    # "logical(selected_int_kind(2))" -> logical1")

    # Note that there is no need to AC_DEFINE the size of the F90
    # datatype.  We have ensured (above) that they are the same as the
    # corresponding F77 datatypes, and that's good enough (i.e., the
    # DDT engine only looks at the F77 sizes).

    # Finally, note that it is necessary to use the Big Long Ugly m4
    # expressions in the AC_DEFINE_UNQUOTEDs.  If you don't (e.g., put
    # the result of the BLUm4E in a shell variable and use that in
    # AC_DEFINE_UNQUOTED), autoheader won't put them in the
    # AC_CONFIG_HEADER (or AM_CONFIG_HEADER, in our case).

    AC_DEFINE_UNQUOTED([OMPI_HAVE_F90_]m4_translit(m4_bpatsubst(m4_bpatsubst([$1], [*], []), [[^a-zA-Z0-9_]], [_]), [a-z], [A-Z]),
                       [$ofc_have_type], 
                       [Whether we have Fortran 90 $ofc_fortran_type or not])

    # Save some in shell variables for later use.  Have to use m4
    # functions here (vs. $ompi_upper_var_name, defined above) because
    # these need to be set at autoconf time, not configure time.
    [OMPI_SIZEOF_F90_]m4_translit(m4_bpatsubst(m4_bpatsubst([$1], [*], []), [[^a-zA-Z0-9_]], [_]), [a-z], [A-Z])[=$ofc_type_size]
    AC_DEFINE_UNQUOTED([OMPI_SIZEOF_F90_]m4_translit(m4_bpatsubst(m4_bpatsubst([$1], [*], []), [[^a-zA-Z0-9_]], [_]), [a-z], [A-Z]),
                       [$ofc_type_size],
                       [Size of Fortran 77 $ofc_fortran_type])
    AC_SUBST([OMPI_SIZEOF_F90_]m4_translit(m4_bpatsubst(m4_bpatsubst([$1], [*], []), [[^a-zA-Z0-9_]], [_]), [a-z], [A-Z]))

    # Clean up
    unset ofc_fortran_type ofc_expected_size ofc_want_range ofc_pretty_name
    unset ofc_have_type ofc_type_size ofc_letter ofc_str
    unset ofc_type_range ofc_type_precision
    unset ofc_f77_sizeof 
])dnl