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

Addressed Fortran issues with promoted integers and reals via compilation flags, part 2 #4221

Merged
merged 12 commits into from
Mar 25, 2024
6 changes: 4 additions & 2 deletions HDF5Examples/FORTRAN/H5G/h5ex_g_traverse.F90
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ RECURSIVE INTEGER(KIND=C_INT) FUNCTION op_func(loc_id, name, info, operator_data
CHARACTER(LEN=10) :: space
INTEGER :: spaces ! Number of whitespaces to prepend to output
INTEGER :: len
INTEGER :: ret_val_func

ret_val_func = 0
ret_val = 0

name_string(1:10) = " "
Expand Down Expand Up @@ -140,8 +142,8 @@ RECURSIVE INTEGER(KIND=C_INT) FUNCTION op_func(loc_id, name, info, operator_data
ptr2 = C_LOC(nextod%recurs)
funptr = C_FUNLOC(op_func)
CALL h5literate_by_name_f(loc_id, name_string, H5_INDEX_NAME_F, H5_ITER_NATIVE_F, idx, &
funptr, ptr2, ret_val, status)

funptr, ptr2, ret_val_func, status)
ret_val = INT(ret_val_func,C_INT)
ENDIF
WRITE(*,'(A)') space(1:spaces)//"}"
RETURN
Expand Down
7 changes: 4 additions & 3 deletions HDF5Examples/FORTRAN/H5PAR/ph5_f90_dataset.F90
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ PROGRAM DATASET
!
! MPI definitions and calls.
!
INTEGER :: mpierror ! MPI error flag
INTEGER :: comm, info
INTEGER :: mpi_size, mpi_rank
INTEGER(KIND=MPI_INTEGER_KIND) :: mpierror ! MPI error flag
INTEGER(KIND=MPI_INTEGER_KIND) :: comm, info
INTEGER(KIND=MPI_INTEGER_KIND) :: mpi_size, mpi_rank

comm = MPI_COMM_WORLD
info = MPI_INFO_NULL
CALL MPI_INIT(mpierror)
Expand Down
6 changes: 3 additions & 3 deletions HDF5Examples/FORTRAN/H5PAR/ph5_f90_file_create.F90
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ PROGRAM FILE_CREATE
!
! MPI definitions and calls.
!
INTEGER :: mpierror ! MPI error flag
INTEGER :: comm, info
INTEGER :: mpi_size, mpi_rank
INTEGER(KIND=MPI_INTEGER_KIND) :: mpierror ! MPI error flag
INTEGER(KIND=MPI_INTEGER_KIND) :: comm, info
INTEGER(KIND=MPI_INTEGER_KIND) :: mpi_size, mpi_rank
comm = MPI_COMM_WORLD
info = MPI_INFO_NULL

Expand Down
18 changes: 10 additions & 8 deletions HDF5Examples/FORTRAN/H5PAR/ph5_f90_filtered_writes_no_sel.F90
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ MODULE filter
INTEGER , PARAMETER :: PATH_MAX = 512

! Global variables
INTEGER :: mpi_rank, mpi_size
INTEGER(KIND=MPI_INTEGER_KIND) :: mpi_rank, mpi_size

CONTAINS
!
Expand Down Expand Up @@ -91,10 +91,11 @@ SUBROUTINE cleanup(filename)

LOGICAL :: do_cleanup
INTEGER :: status
INTEGER(KIND=MPI_INTEGER_KIND) :: mpierror

CALL get_environment_variable("HDF5_NOCLEANUP", STATUS=status)
IF(status.EQ.0)THEN
CALL MPI_File_delete(filename, MPI_INFO_NULL, status)
CALL MPI_File_delete(filename, MPI_INFO_NULL, mpierror)
ENDIF

END SUBROUTINE cleanup
Expand Down Expand Up @@ -241,18 +242,19 @@ PROGRAM main
USE filter
IMPLICIT NONE

INTEGER :: comm = MPI_COMM_WORLD
INTEGER :: info = MPI_INFO_NULL
INTEGER(KIND=MPI_INTEGER_KIND) :: comm = MPI_COMM_WORLD
INTEGER(KIND=MPI_INTEGER_KIND) :: info = MPI_INFO_NULL
INTEGER(hid_t) :: file_id
INTEGER(hid_t) :: fapl_id
INTEGER(hid_t) :: dxpl_id
CHARACTER(LEN=PATH_MAX) :: par_prefix
CHARACTER(LEN=PATH_MAX) :: filename
INTEGER :: status
INTEGER(KIND=MPI_INTEGER_KIND) :: mpierror

CALL MPI_Init(status)
CALL MPI_Comm_size(comm, mpi_size, status)
CALL MPI_Comm_rank(comm, mpi_rank, status)
CALL MPI_Init(mpierror)
CALL MPI_Comm_size(comm, mpi_size, mpierror)
CALL MPI_Comm_rank(comm, mpi_rank, mpierror)

!
! Initialize HDF5 library and Fortran interfaces.
Expand Down Expand Up @@ -349,6 +351,6 @@ PROGRAM main
! ------------------------------------
CALL cleanup(filename)

CALL MPI_Finalize(status)
CALL MPI_Finalize(mpierror)

END PROGRAM main
6 changes: 3 additions & 3 deletions HDF5Examples/FORTRAN/H5PAR/ph5_f90_hyperslab_by_chunk.F90
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ PROGRAM DATASET_BY_CHUNK
!
! MPI definitions and calls.
!
INTEGER :: mpierror ! MPI error flag
INTEGER :: comm, info
INTEGER :: mpi_size, mpi_rank
INTEGER(KIND=MPI_INTEGER_KIND) :: mpierror ! MPI error flag
INTEGER(KIND=MPI_INTEGER_KIND) :: comm, info
INTEGER(KIND=MPI_INTEGER_KIND) :: mpi_size, mpi_rank

comm = MPI_COMM_WORLD
info = MPI_INFO_NULL
Expand Down
6 changes: 3 additions & 3 deletions HDF5Examples/FORTRAN/H5PAR/ph5_f90_hyperslab_by_col.F90
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ PROGRAM DATASET_BY_COL
!
! MPI definitions and calls.
!
INTEGER :: mpierror ! MPI error flag
INTEGER :: comm, info
INTEGER :: mpi_size, mpi_rank
INTEGER(KIND=MPI_INTEGER_KIND) :: mpierror ! MPI error flag
INTEGER(KIND=MPI_INTEGER_KIND) :: comm, info
INTEGER(KIND=MPI_INTEGER_KIND) :: mpi_size, mpi_rank
comm = MPI_COMM_WORLD
info = MPI_INFO_NULL
CALL MPI_INIT(mpierror)
Expand Down
6 changes: 3 additions & 3 deletions HDF5Examples/FORTRAN/H5PAR/ph5_f90_hyperslab_by_pattern.F90
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ PROGRAM DATASET_BY_PATTERN
!
! MPI definitions and calls.
!
INTEGER :: mpierror ! MPI error flag
INTEGER :: comm, info
INTEGER :: mpi_size, mpi_rank
INTEGER(KIND=MPI_INTEGER_KIND) :: mpierror ! MPI error flag
INTEGER(KIND=MPI_INTEGER_KIND) :: comm, info
INTEGER(KIND=MPI_INTEGER_KIND) :: mpi_size, mpi_rank

comm = MPI_COMM_WORLD
info = MPI_INFO_NULL
Expand Down
6 changes: 3 additions & 3 deletions HDF5Examples/FORTRAN/H5PAR/ph5_f90_hyperslab_by_row.F90
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ PROGRAM DATASET_BY_ROW
!
! MPI definitions and calls.
!
INTEGER :: mpierror ! MPI error flag
INTEGER :: comm, info
INTEGER :: mpi_size, mpi_rank
INTEGER(KIND=MPI_INTEGER_KIND) :: mpierror ! MPI error flag
INTEGER(KIND=MPI_INTEGER_KIND) :: comm, info
INTEGER(KIND=MPI_INTEGER_KIND) :: mpi_size, mpi_rank

comm = MPI_COMM_WORLD
info = MPI_INFO_NULL
Expand Down
38 changes: 20 additions & 18 deletions HDF5Examples/FORTRAN/H5PAR/ph5_f90_subfiling.F90
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ SUBROUTINE subfiling_write_default(fapl_id, mpi_size, mpi_rank)

IMPLICIT NONE
INTEGER(HID_T) :: fapl_id
INTEGER :: mpi_size
INTEGER :: mpi_rank
INTEGER(KIND=MPI_INTEGER_KIND) :: mpi_size
INTEGER(KIND=MPI_INTEGER_KIND) :: mpi_rank

INTEGER, DIMENSION(:), ALLOCATABLE, TARGET :: wdata
INTEGER(hsize_t), DIMENSION(1:EXAMPLE_DSET_DIMS) :: dset_dims
Expand Down Expand Up @@ -171,8 +171,8 @@ SUBROUTINE subfiling_write_custom(fapl_id, mpi_size, mpi_rank)

IMPLICIT NONE
INTEGER(HID_T) :: fapl_id
INTEGER :: mpi_size
INTEGER :: mpi_rank
INTEGER(KIND=MPI_INTEGER_KIND) :: mpi_size
INTEGER(KIND=MPI_INTEGER_KIND) :: mpi_rank

INTEGER, DIMENSION(:), ALLOCATABLE, TARGET :: wdata

Expand Down Expand Up @@ -304,8 +304,8 @@ SUBROUTINE subfiling_write_precreate(fapl_id, mpi_size, mpi_rank)

IMPLICIT NONE
INTEGER(HID_T) :: fapl_id
INTEGER :: mpi_size
INTEGER :: mpi_rank
INTEGER(KIND=MPI_INTEGER_KIND) :: mpi_size
INTEGER(KIND=MPI_INTEGER_KIND) :: mpi_rank

INTEGER, DIMENSION(:), ALLOCATABLE, TARGET :: wdata
TYPE(H5FD_subfiling_config_t) :: subf_config
Expand All @@ -320,6 +320,7 @@ SUBROUTINE subfiling_write_precreate(fapl_id, mpi_size, mpi_rank)
INTEGER :: status
INTEGER(SIZE_T) :: i
TYPE(C_PTR) :: f_ptr
INTEGER(KIND=MPI_INTEGER_KIND) :: mpierror

! Make a copy of the FAPL so we don't disturb
! it for the other examples
Expand Down Expand Up @@ -413,7 +414,7 @@ SUBROUTINE subfiling_write_precreate(fapl_id, mpi_size, mpi_rank)
CALL H5Fclose_f(file_id, status)
ENDIF

CALL MPI_Barrier(MPI_COMM_WORLD, status)
CALL MPI_Barrier(MPI_COMM_WORLD, mpierror)

!
! Use all MPI ranks to re-open the file and
Expand Down Expand Up @@ -467,26 +468,27 @@ PROGRAM main
USE SUBF
IMPLICIT NONE

INTEGER :: comm = MPI_COMM_WORLD
INTEGER :: info = MPI_INFO_NULL
INTEGER(KIND=MPI_INTEGER_KIND) :: comm = MPI_COMM_WORLD
INTEGER(KIND=MPI_INTEGER_KIND) :: info = MPI_INFO_NULL
INTEGER(HID_T) :: fapl_id
INTEGER :: mpi_size
INTEGER :: mpi_rank
INTEGER :: required
INTEGER :: provided
INTEGER(KIND=MPI_INTEGER_KIND) :: mpi_size
INTEGER(KIND=MPI_INTEGER_KIND) :: mpi_rank
INTEGER(KIND=MPI_INTEGER_KIND) :: required
INTEGER(KIND=MPI_INTEGER_KIND) :: provided
INTEGER(KIND=MPI_INTEGER_KIND) :: mpierror
INTEGER :: status

! HDF5 Subfiling VFD requires MPI_Init_thread with MPI_THREAD_MULTIPLE
required = MPI_THREAD_MULTIPLE
provided = 0
CALL mpi_init_thread(required, provided, status)
CALL mpi_init_thread(required, provided, mpierror)
IF (provided .NE. required) THEN
WRITE(*,*) "MPI doesn't support MPI_Init_thread with MPI_THREAD_MULTIPLE *FAILED*"
CALL MPI_Abort(comm, -1, status)
CALL MPI_Abort(comm, -1_MPI_INTEGER_KIND, mpierror)
ENDIF

CALL MPI_Comm_size(comm, mpi_size, status)
CALL MPI_Comm_rank(comm, mpi_rank, status)
CALL MPI_Comm_size(comm, mpi_size, mpierror)
CALL MPI_Comm_rank(comm, mpi_rank, mpierror)

!
! Initialize HDF5 library and Fortran interfaces.
Expand Down Expand Up @@ -516,6 +518,6 @@ PROGRAM main

IF(mpi_rank .EQ. 0) WRITE(*,"(A)") "PHDF5 example finished with no errors"

CALL MPI_Finalize(status)
CALL MPI_Finalize(mpierror)

END PROGRAM main
8 changes: 4 additions & 4 deletions HDF5Examples/FORTRAN/H5T/h5ex_t_enum_F03.F90
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,14 @@ PROGRAM main
! Insert enumerated value for memtype.
!
val = i
CALL h5tenum_insert_f(memtype, TRIM(names(i+1)), val, hdferr)
f_ptr = C_LOC(val)
CALL h5tenum_insert_f(memtype, TRIM(names(i+1)), f_ptr, hdferr)
!
! Insert enumerated value for filetype. We must first convert
! the numerical value val to the base type of the destination.
!
f_ptr = C_LOC(val)
CALL h5tconvert_f (M_BASET, F_BASET, INT(1,SIZE_T), f_ptr, hdferr)
CALL h5tenum_insert_f(filetype, TRIM(names(i+1)), val, hdferr)
CALL h5tenum_insert_f(filetype, TRIM(names(i+1)), f_ptr, hdferr)
ENDDO
!
! Create dataspace. Setting maximum size to be the current size.
Expand Down Expand Up @@ -129,7 +129,7 @@ PROGRAM main
!
! Get the name of the enumeration member.
!
CALL h5tenum_nameof_f( memtype, rdata(i,j), NAME_BUF_SIZE, name, hdferr)
CALL h5tenum_nameof_f( memtype, INT(rdata(i,j)), NAME_BUF_SIZE, name, hdferr)
WRITE(*,'(" ", A6," ")', ADVANCE='NO') TRIM(NAME)
ENDDO
WRITE(*,'("]")')
Expand Down
7 changes: 4 additions & 3 deletions HDF5Examples/FORTRAN/H5T/h5ex_t_enumatt_F03.F90
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,15 @@ PROGRAM main
! Insert enumerated value for memtype.
!
val = i
CALL h5tenum_insert_f(memtype, TRIM(names(i+1)), val, hdferr)
f_ptr = C_LOC(val)
CALL h5tenum_insert_f(memtype, TRIM(names(i+1)), f_ptr, hdferr)
!
! Insert enumerated value for filetype. We must first convert
! the numerical value val to the base type of the destination.
!
f_ptr = C_LOC(val)
CALL h5tconvert_f(M_BASET, F_BASET, INT(1,SIZE_T), f_ptr, hdferr)
CALL h5tenum_insert_f(filetype, TRIM(names(i+1)), val, hdferr)
CALL h5tenum_insert_f(filetype, TRIM(names(i+1)), f_ptr, hdferr)
ENDDO
!
! Create dataspace with a null dataspace.
Expand Down Expand Up @@ -137,7 +138,7 @@ PROGRAM main
!
! Get the name of the enumeration member.
!
CALL h5tenum_nameof_f( memtype, rdata(i,j), NAME_BUF_SIZE, name, hdferr)
CALL h5tenum_nameof_f( memtype, INT(rdata(i,j)), NAME_BUF_SIZE, name, hdferr)
WRITE(*,'(" ",A6," ")', ADVANCE='NO') TRIM(NAME)
ENDDO
WRITE(*,'("]")')
Expand Down
16 changes: 16 additions & 0 deletions config/cmake/HDF5UseFortran.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,15 @@ macro (FORTRAN_RUN FUNCTION_NAME SOURCE_CODE RUN_RESULT_VAR1 COMPILE_RESULT_VAR1
else ()
set (_RUN_OUTPUT_VARIABLE "RUN_OUTPUT_STDOUT_VARIABLE")
endif()
if (${FUNCTION_NAME} STREQUAL "SIZEOF NATIVE KINDs")
set(TMP_CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS}")
else ()
set(TMP_CMAKE_Fortran_FLAGS "")
endif ()
TRY_RUN (RUN_RESULT_VAR COMPILE_RESULT_VAR
${CMAKE_BINARY_DIR}
${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/testFortranCompiler1.f90
CMAKE_FLAGS "${TMP_CMAKE_Fortran_FLAGS}"
LINK_LIBRARIES "${HDF5_REQUIRED_LIBRARIES}"
${_RUN_OUTPUT_VARIABLE} OUTPUT_VAR
)
Expand Down Expand Up @@ -111,6 +117,16 @@ else ()
set (${HDF_PREFIX}_FORTRAN_C_BOOL_IS_UNIQUE 0)
endif ()

# Check if the fortran compiler supports the intrinsic module "ISO_FORTRAN_ENV" (F08)

READ_SOURCE("PROGRAM PROG_FC_ISO_FORTRAN_ENV" "END PROGRAM PROG_FC_ISO_FORTRAN_ENV" SOURCE_CODE)
check_fortran_source_compiles (${SOURCE_CODE} HAVE_ISO_FORTRAN_ENV SRC_EXT f90)
if (${HAVE_ISO_FORTRAN_ENV})
set (${HDF_PREFIX}_HAVE_ISO_FORTRAN_ENV 1)
else ()
set (${HDF_PREFIX}_HAVE_ISO_FORTRAN_ENV 0)
endif ()

## Set the sizeof function for use later in the fortran tests
if (${HDF_PREFIX}_FORTRAN_HAVE_STORAGE_SIZE)
set (FC_SIZEOF_A "STORAGE_SIZE(a, c_size_t)/STORAGE_SIZE(c_char_'a',c_size_t)")
Expand Down
3 changes: 2 additions & 1 deletion config/cmake/HDFUseFortran.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ set (CHAR_ALLOC
set (ISO_FORTRAN_ENV_CODE
"
PROGRAM main
USE, INTRINSIC :: ISO_FORTRAN_ENV
USE, INTRINSIC :: ISO_FORTRAN_ENV, ONLY : atomic_logical_kind
LOGICAL(KIND=atomic_logical_kind) :: state
END PROGRAM
"
)
Expand Down
12 changes: 10 additions & 2 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -786,6 +786,15 @@ if test "X$HDF_FORTRAN" = "Xyes"; then
## See if the fortran compiler supports the intrinsic function "STORAGE_SIZE"
PAC_PROG_FC_STORAGE_SIZE

## --------------------------------------------------------------------
## Checking if the fortran compiler supports ISO_FORTRAN_ENV (Fortran 2008)
HAVE_ISO_FORTRAN_ENV="0"
PAC_PROG_FC_ISO_FORTRAN_ENV
if test "X$CHECK_ISO_FORTRAN_ENV" = "Xyes"; then
HAVE_ISO_FORTRAN_ENV="1"
AC_DEFINE([HAVE_ISO_FORTRAN_ENV], [1], [Define if Fortran supports ISO_FORTRAN_ENV (F08)])
fi

## Set the sizeof function for use later in the fortran tests
if test "X$HAVE_STORAGE_SIZE_FORTRAN" = "Xyes";then
FC_SIZEOF_A="STORAGE_SIZE(a, c_size_t)/STORAGE_SIZE(c_char_'a',c_size_t)"
Expand All @@ -802,8 +811,6 @@ if test "X$HDF_FORTRAN" = "Xyes"; then
fi
fi

## See if the fortran compiler supports the intrinsic module "ISO_FORTRAN_ENV"
PAC_PROG_FC_ISO_FORTRAN_ENV
## Check KIND and size of native integer
PAC_FC_NATIVE_INTEGER

Expand All @@ -829,6 +836,7 @@ if test "X$HDF_FORTRAN" = "Xyes"; then
AC_SUBST([FORTRAN_HAVE_C_LONG_DOUBLE])
AC_SUBST([FORTRAN_C_LONG_DOUBLE_IS_UNIQUE])
AC_SUBST([FORTRAN_C_BOOL_IS_UNIQUE])
AC_SUBST([HAVE_ISO_FORTRAN_ENV])
AC_SUBST([H5CONFIG_F_NUM_RKIND])
AC_SUBST([H5CONFIG_F_RKIND])
AC_SUBST([H5CONFIG_F_RKIND_SIZEOF])
Expand Down
5 changes: 5 additions & 0 deletions fortran/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ if (H5_FORTRAN_HAVE_C_SIZEOF)
set (CMAKE_H5_FORTRAN_HAVE_C_SIZEOF 1)
endif ()

set (CMAKE_H5_HAVE_ISO_FORTRAN_ENV 0)
if (H5_HAVE_ISO_FORTRAN_ENV)
set (CMAKE_H5_HAVE_ISO_FORTRAN_ENV 1)
endif ()

set (CMAKE_H5_FORTRAN_HAVE_CHAR_ALLOC 0)
if (H5_FORTRAN_HAVE_CHAR_ALLOC)
set (CMAKE_H5_FORTRAN_HAVE_CHAR_ALLOC 1)
Expand Down
Loading
Loading