Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Determine MPI LOGICAL during build, used in tests. #4246

Merged
merged 2 commits into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 57 additions & 2 deletions config/cmake/HDF5UseFortran.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,12 @@ endif ()
#-----------------------------------------------------------------------------
# Determine the available KINDs for REALs and INTEGERs
#-----------------------------------------------------------------------------
if (${HAVE_ISO_FORTRAN_ENV})
READ_SOURCE ("PROGRAM FC08_AVAIL_KINDS" "END PROGRAM FC08_AVAIL_KINDS" SOURCE_CODE)
else ()
READ_SOURCE ("PROGRAM FC_AVAIL_KINDS" "END PROGRAM FC_AVAIL_KINDS" SOURCE_CODE)
endif ()

READ_SOURCE ("PROGRAM FC_AVAIL_KINDS" "END PROGRAM FC_AVAIL_KINDS" SOURCE_CODE)
FORTRAN_RUN ("REAL and INTEGER KINDs"
"${SOURCE_CODE}"
XX
Expand All @@ -167,6 +171,9 @@ FORTRAN_RUN ("REAL and INTEGER KINDs"
# dnl -- LINE 3 -- max decimal precision for reals
# dnl -- LINE 4 -- number of valid integer kinds
# dnl -- LINE 5 -- number of valid real kinds
# dnl -- LINE 6 -- number of valid logical kinds
# dnl -- LINE 7 -- valid logical kinds (comma separated list)

#
# Convert the string to a list of strings by replacing the carriage return with a semicolon
string (REGEX REPLACE "[\r\n]+" ";" PROG_OUTPUT "${PROG_OUTPUT}")
Expand Down Expand Up @@ -202,6 +209,55 @@ message (STATUS "....REAL KINDS FOUND ${PAC_FC_ALL_REAL_KINDS}")
message (STATUS "....INTEGER KINDS FOUND ${PAC_FC_ALL_INTEGER_KINDS}")
message (STATUS "....MAX DECIMAL PRECISION ${${HDF_PREFIX}_PAC_FC_MAX_REAL_PRECISION}")

if (${HAVE_ISO_FORTRAN_ENV})

list (GET PROG_OUTPUT 5 NUM_LKIND)
set (PAC_FORTRAN_NUM_LOGICAL_KINDS "${NUM_LKIND}")

list (GET PROG_OUTPUT 6 pac_validLogicalKinds)
# If the list is empty then something went wrong.
if (NOT pac_validLogicalKinds)
message (FATAL_ERROR "Failed to find available LOGICAL KINDs for Fortran")
endif ()

set (PAC_FC_ALL_LOGICAL_KINDS "\{${pac_validLogicalKinds}\}")
message (STATUS "....LOGICAL KINDS FOUND ${PAC_FC_ALL_LOGICAL_KINDS}")

# ********************
# LOGICAL KIND FOR MPI
# ********************
if (HDF5_ENABLE_PARALLEL AND BUILD_TESTING)
string (REGEX REPLACE "," ";" VAR "${pac_validLogicalKinds}")

set(CMAKE_REQUIRED_QUIET TRUE)
foreach (KIND ${VAR})
unset(MPI_LOGICAL_KIND CACHE)
set (PROG_SRC
"
PROGRAM main
USE MPI
IMPLICIT NONE
LOGICAL(KIND=${KIND}) :: flag
INTEGER(KIND=MPI_INTEGER_KIND) :: info_ret, mpierror
CHARACTER(LEN=3) :: info_val
CALL mpi_info_get(info_ret,\"foo\", 3_MPI_INTEGER_KIND, info_val, flag, mpierror)
END
"
)
check_fortran_source_compiles (${PROG_SRC} MPI_LOGICAL_KIND SRC_EXT f90)

if (MPI_LOGICAL_KIND)
set (${HDF_PREFIX}_MPI_LOGICAL_KIND ${KIND})
message (STATUS "....FORTRAN LOGICAL KIND for MPI is ${KIND}")
endif ()
endforeach ()
if (${HDF_PREFIX}_MPI_LOGICAL_KIND STREQUAL "")
message (FATAL_ERROR "Failed to determine LOGICAL KIND for MPI")
endif ()
set(CMAKE_REQUIRED_QUIET FALSE)
endif()
endif()

#-----------------------------------------------------------------------------
# Determine the available KINDs for REALs and INTEGERs
#-----------------------------------------------------------------------------
Expand Down Expand Up @@ -350,7 +406,6 @@ if (NOT PAC_FORTRAN_NATIVE_DOUBLE_KIND)
message (FATAL_ERROR "Failed to find KIND of NATIVE DOUBLE for Fortran")
endif ()


set (${HDF_PREFIX}_FORTRAN_SIZEOF_LONG_DOUBLE ${${HDF_PREFIX}_SIZEOF_LONG_DOUBLE})

# remove the invalid kind from the list
Expand Down
19 changes: 17 additions & 2 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -830,8 +830,13 @@ if test "X$HDF_FORTRAN" = "Xyes"; then
PAC_FC_NATIVE_INTEGER

## Find all available KINDs
PAC_FC_AVAIL_KINDS
## Find all sizeofs for available KINDs
if test "X$HAVE_ISO_FORTRAN_ENV" = "X1";then
PAC_FC_AVAIL_KINDS_F08
else
PAC_FC_AVAIL_KINDS
fi

## Find all SIZEOFs for available KINDs
PAC_FC_SIZEOF_INT_KINDS
PAC_FC_SIZEOF_REAL_KINDS

Expand Down Expand Up @@ -3055,6 +3060,16 @@ if test -n "$PARALLEL"; then
[AC_MSG_RESULT([no])]
)
AC_LANG_POP(Fortran)

if test "X$HDF5_TESTS" = "Xyes"; then
AC_SUBST([MPI_LOGICAL_KIND])
PAC_FIND_MPI_LOGICAL_KIND
if test "X$" = "Xyes"; then
HAVE_ISO_FORTRAN_ENV="1"
AC_DEFINE([HAVE_ISO_FORTRAN_ENV], [1], [Define if Fortran supports ISO_FORTRAN_ENV (F08)])
fi
fi

fi

## ----------------------------------------------------------------------
Expand Down
5 changes: 5 additions & 0 deletions fortran/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ if (H5_FORTRAN_HAVE_CHAR_ALLOC)
set (CMAKE_H5_FORTRAN_HAVE_CHAR_ALLOC 1)
endif ()

set (CMAKE_H5_MPI_LOGICAL_KIND 0)
if (H5_MPI_LOGICAL_KIND)
set (CMAKE_H5_MPI_LOGICAL_KIND 1)
endif ()

configure_file (${HDF5_F90_SRC_SOURCE_DIR}/H5config_f.inc.cmake ${HDF5_F90_BINARY_DIR}/H5config_f.inc @ONLY)
configure_file (${HDF5_F90_SRC_SOURCE_DIR}/H5fort_type_defines.h.cmake ${HDF5_F90_BINARY_DIR}/H5fort_type_defines.h @ONLY)

Expand Down
8 changes: 8 additions & 0 deletions fortran/src/H5config_f.inc.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,14 @@
! Define if Fortran C_BOOL is different from default LOGICAL
#define H5_FORTRAN_C_BOOL_IS_UNIQUE @H5_FORTRAN_C_BOOL_IS_UNIQUE@

! Define MPI Fortran KIND of LOGICAL
#cmakedefine01 CMAKE_H5_MPI_LOGICAL_KIND
#if CMAKE_H5_MPI_LOGICAL_KIND == 0
#undef H5_MPI_LOGICAL_KIND
#else
#define H5_MPI_LOGICAL_KIND @H5_MPI_LOGICAL_KIND@
#endif

! Define if Fortran supports ISO_FORTRAN_ENV (F08)
#cmakedefine01 CMAKE_H5_HAVE_ISO_FORTRAN_ENV
#if CMAKE_H5_HAVE_ISO_FORTRAN_ENV == 0
Expand Down
3 changes: 3 additions & 0 deletions fortran/src/H5config_f.inc.in
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@
! Define if Fortran supports ISO_FORTRAN_ENV (F08)
#undef HAVE_ISO_FORTRAN_ENV

! Define MPI Fortran KIND of LOGICAL
#undef MPI_LOGICAL_KIND

! Define the size of C's double
#undef SIZEOF_DOUBLE

Expand Down
15 changes: 4 additions & 11 deletions fortran/testpar/mpi_param.F90
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@

SUBROUTINE mpi_param_03(nerrors)

#ifdef H5_HAVE_ISO_FORTRAN_ENV
USE, INTRINSIC :: iso_fortran_env, ONLY : atomic_logical_kind
#endif
USE MPI
USE HDF5
USE TH5_MISC
Expand All @@ -39,8 +36,8 @@ SUBROUTINE mpi_param_03(nerrors)
INTEGER(KIND=MPI_INTEGER_KIND) :: info, info_ret
INTEGER(KIND=MPI_INTEGER_KIND) :: comm, comm_ret
INTEGER(KIND=MPI_INTEGER_KIND) :: nkeys
#ifdef H5_HAVE_ISO_FORTRAN_ENV
LOGICAL(KIND=atomic_logical_kind) :: flag
#ifdef H5_MPI_LOGICAL_KIND
LOGICAL(KIND=H5_MPI_LOGICAL_KIND) :: flag
#else
LOGICAL(KIND=MPI_INTEGER_KIND) :: flag
#endif
Expand Down Expand Up @@ -178,10 +175,6 @@ END SUBROUTINE mpi_param_03
SUBROUTINE mpi_param_08(nerrors)

#ifdef H5_HAVE_MPI_F08

#ifdef H5_HAVE_ISO_FORTRAN_ENV
USE, INTRINSIC :: iso_fortran_env, ONLY : atomic_logical_kind
#endif
USE MPI_F08
USE HDF5
USE TH5_MISC
Expand All @@ -199,8 +192,8 @@ SUBROUTINE mpi_param_08(nerrors)
TYPE(MPI_INFO) :: info, info_ret
TYPE(MPI_COMM) :: comm, comm_ret
INTEGER(KIND=MPI_INTEGER_KIND) :: nkeys
#ifdef H5_HAVE_ISO_FORTRAN_ENV
LOGICAL(KIND=atomic_logical_kind) :: flag
#ifdef H5_MPI_LOGICAL_KIND
LOGICAL(KIND=H5_MPI_LOGICAL_KIND) :: flag
#else
LOGICAL(KIND=MPI_INTEGER_KIND) :: flag
#endif
Expand Down
46 changes: 46 additions & 0 deletions fortran/testpar/ptest.F90
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,52 @@ PROGRAM parallel_test
CHARACTER(LEN=10), DIMENSION(1:2) :: chr_chunk =(/"contiguous", "chunk "/)
INTEGER(KIND=MPI_INTEGER_KIND) :: mpi_int_type

INTERFACE

SUBROUTINE mpi_param_03(ret_total_error)
IMPLICIT NONE
INTEGER, INTENT(inout) :: ret_total_error
END SUBROUTINE mpi_param_03

SUBROUTINE mpi_param_08(ret_total_error)
IMPLICIT NONE
INTEGER, INTENT(inout) :: ret_total_error
END SUBROUTINE mpi_param_08

SUBROUTINE hyper(length,do_collective,do_chunk, mpi_size, mpi_rank, nerrors)
USE MPI
IMPLICIT NONE
INTEGER, INTENT(in) :: length
LOGICAL, INTENT(in) :: do_collective
LOGICAL, INTENT(in) :: do_chunk
INTEGER(KIND=MPI_INTEGER_KIND), INTENT(in) :: mpi_size
INTEGER(KIND=MPI_INTEGER_KIND), INTENT(in) :: mpi_rank
INTEGER, INTENT(inout) :: nerrors
END SUBROUTINE hyper

SUBROUTINE pmultiple_dset_hyper_rw(do_collective, do_chunk, mpi_size, mpi_rank, nerrors)
USE MPI
IMPLICIT NONE
LOGICAL, INTENT(in) :: do_collective
LOGICAL, INTENT(in) :: do_chunk
INTEGER(KIND=MPI_INTEGER_KIND), INTENT(in) :: mpi_size
INTEGER(KIND=MPI_INTEGER_KIND), INTENT(in) :: mpi_rank
INTEGER, INTENT(inout) :: nerrors
END SUBROUTINE pmultiple_dset_hyper_rw

SUBROUTINE multiple_dset_write(length, do_collective, do_chunk, mpi_size, mpi_rank, nerrors)
USE MPI
IMPLICIT NONE
INTEGER, INTENT(in) :: length
LOGICAL, INTENT(in) :: do_collective
LOGICAL, INTENT(in) :: do_chunk
INTEGER(KIND=MPI_INTEGER_KIND), INTENT(in) :: mpi_size
INTEGER(KIND=MPI_INTEGER_KIND), INTENT(in) :: mpi_rank
INTEGER, INTENT(inout) :: nerrors
END SUBROUTINE multiple_dset_write

END INTERFACE

!
! initialize MPI
!
Expand Down
7 changes: 2 additions & 5 deletions fortran/testpar/subfiling.F90
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@

PROGRAM subfiling_test
USE, INTRINSIC :: ISO_C_BINDING, ONLY : C_INT64_T
#ifdef H5_HAVE_ISO_FORTRAN_ENV
USE, INTRINSIC :: iso_fortran_env, ONLY : atomic_logical_kind
#endif
USE HDF5
USE MPI
USE TH5_MISC
Expand Down Expand Up @@ -50,8 +47,8 @@ PROGRAM subfiling_test
INTEGER(C_INT64_T) inode
TYPE(H5FD_subfiling_config_t) :: vfd_config
TYPE(H5FD_ioc_config_t) :: vfd_config_ioc
#ifdef H5_HAVE_ISO_FORTRAN_ENV
LOGICAL(KIND=atomic_logical_kind) :: flag
#ifdef H5_MPI_LOGICAL_KIND
LOGICAL(KIND=H5_MPI_LOGICAL_KIND) :: flag
#else
LOGICAL(KIND=MPI_INTEGER_KIND) :: flag
#endif
Expand Down
67 changes: 65 additions & 2 deletions m4/aclocal_fc.f90
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@
!

PROGRAM PROG_FC_ISO_FORTRAN_ENV
USE, INTRINSIC :: ISO_FORTRAN_ENV, ONLY : atomic_logical_kind
LOGICAL(KIND=atomic_logical_kind) :: state
USE, INTRINSIC :: ISO_FORTRAN_ENV, ONLY : logical_kinds
END PROGRAM PROG_FC_ISO_FORTRAN_ENV

PROGRAM PROG_FC_SIZEOF
Expand Down Expand Up @@ -183,6 +182,70 @@ PROGRAM FC_AVAIL_KINDS
END PROGRAM FC_AVAIL_KINDS
!---- END ----- Determine the available KINDs for REALs and INTEGERs

!---- START ----- Determine the available KINDs for REALs, INTEGERs and LOGICALs -- ISO_FORTRAN_ENV (F08)
PROGRAM FC08_AVAIL_KINDS
USE, INTRINSIC :: ISO_FORTRAN_ENV, ONLY : stdout=>OUTPUT_UNIT, integer_kinds, real_kinds, logical_kinds
IMPLICIT NONE
INTEGER :: ik, jk, k, max_decimal_prec
INTEGER :: num_rkinds, num_ikinds, num_lkinds

! Find integer KINDs

num_ikinds = SIZE(integer_kinds)

DO k = 1, num_ikinds
WRITE(stdout,'(I0)', ADVANCE='NO') integer_kinds(k)
IF(k.NE.num_ikinds)THEN
WRITE(stdout,'(A)',ADVANCE='NO') ','
ELSE
WRITE(stdout,'()')
ENDIF
ENDDO

! Find real KINDs

num_rkinds = SIZE(real_kinds)

max_decimal_prec = 1

prec: DO ik = 2, 36
exp: DO jk = 1, 700
k = SELECTED_REAL_KIND(ik,jk)
IF(k.LT.0) EXIT exp
max_decimal_prec = ik
ENDDO exp
ENDDO prec

DO k = 1, num_rkinds
WRITE(stdout,'(I0)', ADVANCE='NO') real_kinds(k)
IF(k.NE.num_rkinds)THEN
WRITE(stdout,'(A)',ADVANCE='NO') ','
ELSE
WRITE(stdout,'()')
ENDIF
ENDDO

WRITE(stdout,'(I0)') max_decimal_prec
WRITE(stdout,'(I0)') num_ikinds
WRITE(stdout,'(I0)') num_rkinds

! Find logical KINDs

num_lkinds = SIZE(logical_kinds)
WRITE(stdout,'(I0)') num_lkinds

DO k = 1, num_lkinds
WRITE(stdout,'(I0)', ADVANCE='NO') logical_kinds(k)
IF(k.NE.num_lkinds)THEN
WRITE(stdout,'(A)',ADVANCE='NO') ','
ELSE
WRITE(stdout,'()')
ENDIF
ENDDO

END PROGRAM FC08_AVAIL_KINDS
!---- END ----- Determine the available KINDs for REALs, INTEGERs and LOGICALs -- ISO_FORTRAN_ENV (F08)

PROGRAM FC_MPI_CHECK
USE mpi
INTEGER :: comm, amode, info, fh, ierror
Expand Down
Loading
Loading