diff --git a/acinclude.m4 b/acinclude.m4 index 39dd1ec614..970d157d1a 100644 --- a/acinclude.m4 +++ b/acinclude.m4 @@ -19,6 +19,7 @@ sinclude(config/cxx_find_exception_flags.m4) sinclude(config/f77_check_type.m4) sinclude(config/f77_find_ext_symbol_convention.m4) sinclude(config/f77_get_alignment.m4) +sinclude(config/f77_get_fortran_handle_max.m4) sinclude(config/f77_get_sizeof.m4) sinclude(config/ompi_case_sensitive_fs_setup.m4) diff --git a/config/f77_get_fortran_handle_max.m4 b/config/f77_get_fortran_handle_max.m4 new file mode 100644 index 0000000000..c8a3cbaba4 --- /dev/null +++ b/config/f77_get_fortran_handle_max.m4 @@ -0,0 +1,53 @@ +dnl -*- shell-script -*- +dnl +dnl $HEADER$ +dnl + +AC_DEFUN([OMPI_F77_GET_FORTRAN_HANDLE_MAX],[ +# Find the maximum value of fortran integers, then calculate +# min(INT_MAX, max fortran INTEGER). This represents the maximum +# number of fortran MPI handle index. + +AC_MSG_CHECKING([for max fortran MPI handle index]) + +# Find max fortran INTEGER value. Set to sentinel value if we don't +# have a Fortran compiler (e.g., if --disable-f77 was given) + +if test "$OMPI_WANT_F77_BINDINGS" = "0" ; then + ompi_fint_max=-1 +else + ompi_sizeof_fint=`expr $OMPI_SIZEOF_FORTRAN_INT \* 8 - 1` + ompi_fint_max=1 + while test "$ompi_sizeof_fint" != "0"; do + ompi_fint_max=`expr $ompi_fint_max \* 2` + ompi_sizeof_fint=`expr $ompi_sizeof_fint - 1` + done + ompi_fint_max=`expr $ompi_fint_max - 1` +fi + +# Compare to C MAX_INT. + +rm -f conftest.out > /dev/null 2>&1 +AC_RUN_IFELSE(AC_LANG_PROGRAM([[ +#include +#include +]],[[FILE *fp = fopen("conftest.out", "w"); +long fint = $ompi_fint_max; +long cint = INT_MAX; +if (-1 == fint) fint = cint; +fprintf(fp, "%ld", (cint < fint) ? cint : fint); +fclose(fp);]]), HAPPY=1, HAPPY=0) +if test "$HAPPY" = "1"; then + OMPI_FORTRAN_HANDLE_MAX=`cat conftest.out` +else + # Something went wrong, so be conservative + OMPI_FORTRAN_HANDLE_MAX=32767 +fi +rm -f conftest.out > /dev/null 2>&1 + +AC_DEFINE_UNQUOTED(OMPI_FORTRAN_HANDLE_MAX, + $OMPI_FORTRAN_HANDLE_MAX, + [Max handle value for fortran MPI handles, effectively min(INT_MAX, max fortran INTEGER value)]) + +AC_MSG_RESULT([$OMPI_FORTRAN_HANDLE_MAX]) +])dnl diff --git a/configure.ac b/configure.ac index 815de49803..09b5fe1e02 100644 --- a/configure.ac +++ b/configure.ac @@ -428,6 +428,12 @@ AC_DEFINE_UNQUOTED(OMPI_ALIGNMENT_FORTRAN_DBLCOMPLEX, $OMPI_ALIGNMENT_FORTRAN_DBLCOMPLEX, [Alignment of fortran double complex]) +# Regardless of whether we have fortran bindings, or even a fortran +# compiler, get the max value for a fortran MPI handle (this macro +# handles the case where we don't have a fortran compiler). + +OMPI_F77_GET_FORTRAN_HANDLE_MAX + # # There are 2 layers to the MPI f77 layer. The only extra thing that # determine f77 bindings is that fortran can be disabled by user. In diff --git a/src/class/ompi_bitmap.c b/src/class/ompi_bitmap.c index 905261e740..f8f1b89fb8 100644 --- a/src/class/ompi_bitmap.c +++ b/src/class/ompi_bitmap.c @@ -5,8 +5,6 @@ #include "ompi_config.h" #include -#include -#define OMPI_FORTRAN_HANDLE_MAX INT_MAX #include "include/constants.h" #include "class/ompi_bitmap.h" diff --git a/src/class/ompi_pointer_array.c b/src/class/ompi_pointer_array.c index a3489d9c37..5b115a5e6f 100644 --- a/src/class/ompi_pointer_array.c +++ b/src/class/ompi_pointer_array.c @@ -8,9 +8,6 @@ #include #include -#include -#define OMPI_FORTRAN_HANDLE_MAX INT_MAX - #include "include/constants.h" #include "class/ompi_pointer_array.h" #include "util/output.h"