1 dnl -*- shell-script -*-
3 dnl Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
4 dnl University Research and Technology
5 dnl Corporation. All rights reserved.
6 dnl Copyright (c) 2004-2005 The University of Tennessee and The University
7 dnl of Tennessee Research Foundation. All rights
9 dnl Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
10 dnl University of Stuttgart. All rights reserved.
11 dnl Copyright (c) 2004-2005 The Regents of the University of California.
12 dnl All rights reserved.
15 dnl Additional copyrights may follow
20 # OMPI_F77_GET_FORTRAN_HANDLE_MAX()
21 # ---------------------------------------------------------------
22 # Find the maximum value of fortran integers, then calculate
23 # min(INT_MAX, max fortran INTEGER). This represents the maximum
24 # number of fortran MPI handle index.
25 AC_DEFUN([OMPI_F77_GET_FORTRAN_HANDLE_MAX],[
26 AC_CACHE_CHECK([for max Fortran MPI handle index],
27 [ompi_cv_f77_fortran_handle_max],
28 [ # Find max fortran INTEGER value. Set to sentinel value if we don't
29 # have a Fortran compiler (e.g., if --disable-f77 was given).
30 if test "$OMPI_WANT_F77_BINDINGS" = "0" ; then
33 # Calculate the number of f's that we need to append to the hex
34 # value. Do one less than we really need becaue we assume the
35 # top nybble is 0x7 to avoid sign issues.
36 ompi_numf=`expr $OMPI_SIZEOF_FORTRAN_INTEGER \* 2 - 1`
38 while test "$ompi_numf" -gt "0"; do
39 ompi_fint_max=${ompi_fint_max}f
40 ompi_numf=`expr $ompi_numf - 1`
44 # Get INT_MAX. Compute a SWAG if we are cross compiling or something
46 rm -f conftest.out >/dev/null 2>&1
47 AC_RUN_IFELSE(AC_LANG_PROGRAM([[
50 ]],[[FILE *fp = fopen("conftest.out", "w");
52 fprintf(fp, "%ld", cint);
54 [ompi_cint_max=`cat conftest.out`],
56 [ #cross compiling is fun. compute INT_MAX same as INTEGER max
57 ompi_numf=`expr $ac_cv_sizeof_int \* 2 - 1`
59 while test "$ompi_numf" -gt "0" ; do
60 ompi_cint_max=${ompi_cint_max}f
61 ompi_numf=`expr $ompi_numf - 1`
64 if test "$ompi_cint_max" = "0" ; then
65 # wow - something went really wrong. Be conservative
66 ompi_cv_f77_fortran_handle_max=32767
67 elif test "$ompi_fint_max" = "0" ; then
68 # we aren't compiling Fortran - just set it to C INT_MAX
69 ompi_cv_f77_fortran_handle_max=$ompi_cint_max
71 # take the lesser of C INT_MAX and Fortran INTEGER
72 # max. The resulting value will then be storable in
73 # either type. There's no easy way to do this in
74 # the shell, so make the preprocessor do it.
75 ompi_cv_f77_fortran_handle_max="( $ompi_fint_max < $ompi_cint_max ? $ompi_fint_max : $ompi_cint_max )"
77 rm -f conftest.out > /dev/null 2>&1 ])
79 AC_DEFINE_UNQUOTED([OMPI_FORTRAN_HANDLE_MAX],
80 [$ompi_cv_f77_fortran_handle_max],
81 [Max handle value for fortran MPI handles, effectively min(INT_MAX, max fortran INTEGER value)])