diff options
author | Allen Byrne <50328838+byrnHDF@users.noreply.github.com> | 2023-11-27 21:30:15 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-27 21:30:15 (GMT) |
commit | fc88fcde1091cf12c1e88c783a14ee0f1cffe31c (patch) | |
tree | 91b88b62cd30ed37ee9227e43989e95035be43c3 /HDF5Examples/FORTRAN/H5PAR | |
parent | a067bf71f57723d2dfca7dfe2ffd9ea502eccd4f (diff) | |
download | hdf5-fc88fcde1091cf12c1e88c783a14ee0f1cffe31c.zip hdf5-fc88fcde1091cf12c1e88c783a14ee0f1cffe31c.tar.gz hdf5-fc88fcde1091cf12c1e88c783a14ee0f1cffe31c.tar.bz2 |
Develop merge examples (#3851)
* Merge examples repo into library
* Change grepTest to be more fault-tolerant
* Update examples macro file
* Exclude all Fortran examples from doxygen
Diffstat (limited to 'HDF5Examples/FORTRAN/H5PAR')
-rw-r--r-- | HDF5Examples/FORTRAN/H5PAR/CMakeLists.txt | 80 | ||||
-rw-r--r-- | HDF5Examples/FORTRAN/H5PAR/Fortran_sourcefiles.cmake | 11 | ||||
-rw-r--r-- | HDF5Examples/FORTRAN/H5PAR/ph5_f90_dataset.F90 | 107 | ||||
-rw-r--r-- | HDF5Examples/FORTRAN/H5PAR/ph5_f90_file_create.F90 | 59 | ||||
-rw-r--r-- | HDF5Examples/FORTRAN/H5PAR/ph5_f90_hyperslab_by_chunk.F90 | 170 | ||||
-rw-r--r-- | HDF5Examples/FORTRAN/H5PAR/ph5_f90_hyperslab_by_col.F90 | 133 | ||||
-rw-r--r-- | HDF5Examples/FORTRAN/H5PAR/ph5_f90_hyperslab_by_pattern.F90 | 165 | ||||
-rw-r--r-- | HDF5Examples/FORTRAN/H5PAR/ph5_f90_hyperslab_by_row.F90 | 154 |
8 files changed, 879 insertions, 0 deletions
diff --git a/HDF5Examples/FORTRAN/H5PAR/CMakeLists.txt b/HDF5Examples/FORTRAN/H5PAR/CMakeLists.txt new file mode 100644 index 0000000..84c9641 --- /dev/null +++ b/HDF5Examples/FORTRAN/H5PAR/CMakeLists.txt @@ -0,0 +1,80 @@ +cmake_minimum_required (VERSION 3.12) +project (HDF5Examples_FORTRAN_H5PAR C CXX Fortran) + +# -------------------------------------------------------------------- +# Notes: When creating examples they should be prefixed +# with "f90_". This allows for easier filtering of the examples. +# -------------------------------------------------------------------- + +#----------------------------------------------------------------------------- +# Setup include Directories +#----------------------------------------------------------------------------- +INCLUDE_DIRECTORIES ( + ${CMAKE_Fortran_MODULE_DIRECTORY} + ${PROJECT_BINARY_DIR} + ${CMAKE_LIBRARY_OUTPUT_DIRECTORY} +) + +#----------------------------------------------------------------------------- +# Define Sources +#----------------------------------------------------------------------------- +include (Fortran_sourcefiles.cmake) + +foreach (example_name ${examples}) + add_executable (${EXAMPLE_VARNAME}_f90_${example_name} ${PROJECT_SOURCE_DIR}/${example_name}.F90) + target_compile_options(${EXAMPLE_VARNAME}_f90_${example_name} + PRIVATE + "-DH5_LIBVER_DIR=${H5_LIBVER_DIR}" + "$<$<BOOL:${${EXAMPLE_VARNAME}_USE_16_API}>:-DH5_USE_16_API>" + "$<$<BOOL:${${EXAMPLE_VARNAME}_USE_18_API}>:-DH5_USE_18_API>" + "$<$<BOOL:${${EXAMPLE_VARNAME}_USE_110_API}>:-DH5_USE_110_API>" + "$<$<BOOL:${${EXAMPLE_VARNAME}_USE_112_API}>:-DH5_USE_112_API>" + "$<$<BOOL:${${EXAMPLE_VARNAME}_USE_114_API}>:-DH5_USE_114_API>" + "$<$<BOOL:${${EXAMPLE_VARNAME}_USE_116_API}>:-DH5_USE_116_API>" + ) + target_include_directories (${EXAMPLE_VARNAME}_f90_${example_name} PUBLIC ${MPI_Fortran_INCLUDE_DIRS}) + target_link_libraries (${EXAMPLE_VARNAME}_f90_${example_name} ${LINK_Fortran_LIBS}) + set_target_properties (${EXAMPLE_VARNAME}_f90_${example_name} PROPERTIES LINKER_LANGUAGE Fortran) +endforeach () + +if (H5EX_BUILD_TESTING) + macro (ADD_GREP_TEST testname mumprocs) + add_test ( + NAME ${EXAMPLE_VARNAME}_f90_${testname}-clearall + COMMAND ${CMAKE_COMMAND} + -E remove + ${testname}.h5 + ) + if (last_test) + set_tests_properties (${EXAMPLE_VARNAME}_f90_${testname}-clearall PROPERTIES DEPENDS ${last_test}) + endif () + add_test (NAME ${EXAMPLE_VARNAME}_f90_${testname} COMMAND "${CMAKE_COMMAND}" + -D "TEST_PROGRAM=${MPIEXEC_EXECUTABLE};${MPIEXEC_NUMPROC_FLAG};${mumprocs};${MPIEXEC_PREFLAGS};$<TARGET_FILE:${EXAMPLE_VARNAME}_f90_${testname}>;${MPIEXEC_POSTFLAGS}" + -D "TEST_ARGS:STRING=" + -D "TEST_FOLDER=${PROJECT_BINARY_DIR}" + -D "TEST_EXPECT=0" + -D "TEST_SKIP_COMPARE=TRUE" + -D "TEST_OUTPUT=${testname}.out" + -D "TEST_REFERENCE:STRING=PHDF5 example finished with no errors" + -D "TEST_LIBRARY_DIRECTORY=${CMAKE_TEST_LIB_DIRECTORY}" + -P "${${EXAMPLE_PACKAGE_NAME}_RESOURCES_DIR}/grepTest.cmake" + ) + set_tests_properties (${EXAMPLE_VARNAME}_${testname} PROPERTIES DEPENDS ${EXAMPLE_VARNAME}_${testname}-clearall) + set (last_test "${EXAMPLE_VARNAME}_${testname}") + endmacro () + + # Ensure that 24 is a multiple of the number of processes. + # The number 24 corresponds to SPACE1_DIM1 and SPACE1_DIM2 defined in ph5example.c + math(EXPR NUMPROCS "24 / ((24 + ${MPIEXEC_MAX_NUMPROCS} - 1) / ${MPIEXEC_MAX_NUMPROCS})") + + foreach (example_name ${examples}) + if (${example_name} STREQUAL "ph5_hyperslab_by_col") + ADD_GREP_TEST (${example_name} 2) + elseif (${example_name} STREQUAL "ph5_hyperslab_by_chunk" OR ${example_name} STREQUAL "ph5_hyperslab_by_pattern") + ADD_GREP_TEST (${example_name} 4) + else () + ADD_GREP_TEST (${example_name} ${NUMPROCS}) + endif () + endforeach () + +endif () diff --git a/HDF5Examples/FORTRAN/H5PAR/Fortran_sourcefiles.cmake b/HDF5Examples/FORTRAN/H5PAR/Fortran_sourcefiles.cmake new file mode 100644 index 0000000..39c8940 --- /dev/null +++ b/HDF5Examples/FORTRAN/H5PAR/Fortran_sourcefiles.cmake @@ -0,0 +1,11 @@ +#----------------------------------------------------------------------------- +# Define Sources, one file per application +#----------------------------------------------------------------------------- +set (examples + ph5_f90_dataset + ph5_f90_file_create + ph5_f90_hyperslab_by_row + ph5_f90_hyperslab_by_col + ph5_f90_hyperslab_by_pattern + ph5_f90_hyperslab_by_chunk +) diff --git a/HDF5Examples/FORTRAN/H5PAR/ph5_f90_dataset.F90 b/HDF5Examples/FORTRAN/H5PAR/ph5_f90_dataset.F90 new file mode 100644 index 0000000..ce126a3 --- /dev/null +++ b/HDF5Examples/FORTRAN/H5PAR/ph5_f90_dataset.F90 @@ -0,0 +1,107 @@ + PROGRAM DATASET + + USE HDF5 ! This module contains all necessary modules + + IMPLICIT NONE + + INCLUDE 'mpif.h' + CHARACTER(LEN=10), PARAMETER :: filename = "sds.h5" ! File name + CHARACTER(LEN=8), PARAMETER :: dsetname = "IntArray" ! Dataset name + + INTEGER(HID_T) :: file_id ! File identifier + INTEGER(HID_T) :: dset_id ! Dataset identifier + INTEGER(HID_T) :: filespace ! Dataspace identifier in file + INTEGER(HID_T) :: plist_id ! Property list identifier + + INTEGER(HSIZE_T), DIMENSION(2) :: dimsf = (/5,8/) ! Dataset dimensions. +! INTEGER, DIMENSION(7) :: dimsfi = (/5,8,0,0,0,0,0/) +! INTEGER(HSIZE_T), DIMENSION(2) :: dimsfi = (/5,8/) + INTEGER(HSIZE_T), DIMENSION(2) :: dimsfi + + INTEGER, ALLOCATABLE :: data(:,:) ! Data to write + INTEGER :: rank = 2 ! Dataset rank + + INTEGER :: error, error_n ! Error flags + INTEGER :: i, j + ! + ! MPI definitions and calls. + ! + INTEGER :: mpierror ! MPI error flag + INTEGER :: comm, info + INTEGER :: mpi_size, mpi_rank + comm = MPI_COMM_WORLD + info = MPI_INFO_NULL + CALL MPI_INIT(mpierror) + CALL MPI_COMM_SIZE(comm, mpi_size, mpierror) + CALL MPI_COMM_RANK(comm, mpi_rank, mpierror) + ! + ! Initialize data buffer with trivial data. + ! + ALLOCATE ( data(dimsf(1),dimsf(2))) + do i = 1, dimsf(2) + do j = 1, dimsf(1) + data(j,i) = j - 1 + (i-1)*dimsf(1) + enddo + enddo + ! + ! Initialize FORTRAN interface + ! + CALL h5open_f(error) + + ! + ! Setup file access property list with parallel I/O access. + ! + CALL h5pcreate_f(H5P_FILE_ACCESS_F, plist_id, error) + CALL h5pset_fapl_mpio_f(plist_id, comm, info, error) + + ! + ! Create the file collectively. + ! + CALL h5fcreate_f(filename, H5F_ACC_TRUNC_F, file_id, error, access_prp = plist_id) + CALL h5pclose_f(plist_id, error) + ! + ! Create the data space for the dataset. + ! + CALL h5screate_simple_f(rank, dimsf, filespace, error) + + ! + ! Create the dataset with default properties. + ! + CALL h5dcreate_f(file_id, dsetname, H5T_NATIVE_INTEGER, filespace, & + dset_id, error) + ! + ! Create property list for collective dataset write + ! + CALL h5pcreate_f(H5P_DATASET_XFER_F, plist_id, error) + CALL h5pset_dxpl_mpio_f(plist_id, H5FD_MPIO_COLLECTIVE_F, error) + ! + ! For independent write use + ! CALL h5pset_dxpl_mpio_f(plist_id, H5FD_MPIO_INDEPENDENT_F, error) + ! + + ! + ! Write the dataset collectively. + ! + CALL h5dwrite_f(dset_id, H5T_NATIVE_INTEGER, data, dimsfi, error, & + xfer_prp = plist_id) + ! + ! Deallocate data buffer. + ! + DEALLOCATE(data) + + ! + ! Close resources. + ! + CALL h5sclose_f(filespace, error) + CALL h5dclose_f(dset_id, error) + CALL h5pclose_f(plist_id, error) + CALL h5fclose_f(file_id, error) + + ! + ! Close FORTRAN interface + ! + CALL h5close_f(error) + + CALL MPI_FINALIZE(mpierror) + + END PROGRAM DATASET diff --git a/HDF5Examples/FORTRAN/H5PAR/ph5_f90_file_create.F90 b/HDF5Examples/FORTRAN/H5PAR/ph5_f90_file_create.F90 new file mode 100644 index 0000000..f330d4e --- /dev/null +++ b/HDF5Examples/FORTRAN/H5PAR/ph5_f90_file_create.F90 @@ -0,0 +1,59 @@ +! +! This example creates HDF5 file in a parallel environment +! + + PROGRAM FILE_CREATE + + USE HDF5 ! This module contains all necessary modules + + IMPLICIT NONE + + INCLUDE 'mpif.h' + CHARACTER(LEN=10), PARAMETER :: filename = "sds.h5" ! File name + + INTEGER(HID_T) :: file_id ! File identifier + INTEGER(HID_T) :: plist_id ! Property list identifier + INTEGER :: error + + ! + ! MPI definitions and calls. + ! + INTEGER :: mpierror ! MPI error flag + INTEGER :: comm, info + INTEGER :: mpi_size, mpi_rank + comm = MPI_COMM_WORLD + info = MPI_INFO_NULL + + CALL MPI_INIT(mpierror) + CALL MPI_COMM_SIZE(comm, mpi_size, mpierror) + CALL MPI_COMM_RANK(comm, mpi_rank, mpierror) + ! + ! Initialize FORTRAN predefined datatypes + ! + CALL h5open_f(error) + + ! + ! Setup file access property list with parallel I/O access. + ! + CALL h5pcreate_f(H5P_FILE_ACCESS_F, plist_id, error) + CALL h5pset_fapl_mpio_f(plist_id, comm, info, error) + + ! + ! Create the file collectively. + ! + CALL h5fcreate_f(filename, H5F_ACC_TRUNC_F, file_id, error, access_prp = plist_id) + + ! + ! Close property list and the file. + ! + CALL h5pclose_f(plist_id, error) + CALL h5fclose_f(file_id, error) + + ! + ! Close FORTRAN interface + ! + CALL h5close_f(error) + + CALL MPI_FINALIZE(mpierror) + + END PROGRAM FILE_CREATE diff --git a/HDF5Examples/FORTRAN/H5PAR/ph5_f90_hyperslab_by_chunk.F90 b/HDF5Examples/FORTRAN/H5PAR/ph5_f90_hyperslab_by_chunk.F90 new file mode 100644 index 0000000..3a707af --- /dev/null +++ b/HDF5Examples/FORTRAN/H5PAR/ph5_f90_hyperslab_by_chunk.F90 @@ -0,0 +1,170 @@ +! +! Number of processes is assumed to be 4 +! + PROGRAM DATASET_BY_CHUNK + + USE HDF5 ! This module contains all necessary modules +! USE MPI + + IMPLICIT NONE + + include 'mpif.h' + CHARACTER(LEN=11), PARAMETER :: filename = "sds_chnk.h5" ! File name + CHARACTER(LEN=8), PARAMETER :: dsetname = "IntArray" ! Dataset name + + INTEGER(HID_T) :: file_id ! File identifier + INTEGER(HID_T) :: dset_id ! Dataset identifier + INTEGER(HID_T) :: filespace ! Dataspace identifier in file + INTEGER(HID_T) :: memspace ! Dataspace identifier in memory + INTEGER(HID_T) :: plist_id ! Property list identifier + + INTEGER(HSIZE_T), DIMENSION(2) :: dimsf = (/4,8/) ! Dataset dimensions + ! in the file. +! INTEGER, DIMENSION(7) :: dimsfi = (/4,8,0,0,0,0,0/) + INTEGER(HSIZE_T), DIMENSION (2) :: dimsfi = (/4,8/) + INTEGER(HSIZE_T), DIMENSION(2) :: chunk_dims = (/2,4/) ! Chunks dimensions + + INTEGER(HSIZE_T), DIMENSION(2) :: count + INTEGER(HSSIZE_T), DIMENSION(2) :: offset + INTEGER(HSIZE_T), DIMENSION(2) :: stride + INTEGER(HSIZE_T), DIMENSION(2) :: block + + INTEGER, ALLOCATABLE :: data (:,:) ! Data to write + INTEGER :: rank = 2 ! Dataset rank + + INTEGER :: error, error_n ! Error flags + ! + ! MPI definitions and calls. + ! + INTEGER :: mpierror ! MPI error flag + INTEGER :: comm, info + INTEGER :: mpi_size, mpi_rank + + comm = MPI_COMM_WORLD + info = MPI_INFO_NULL + + CALL MPI_INIT(mpierror) + CALL MPI_COMM_SIZE(comm, mpi_size, mpierror) + CALL MPI_COMM_RANK(comm, mpi_rank, mpierror) + ! Quit if mpi_size is not 4 + if (mpi_size .NE. 4) then + write(*,*) 'This example is set up to use only 4 processes' + write(*,*) 'Quitting....' + goto 100 + endif + + ! + ! Initialize HDF5 library and Fortran interfaces. + ! + CALL h5open_f(error) + + ! + ! Setup file access property list with parallel I/O access. + ! + CALL h5pcreate_f(H5P_FILE_ACCESS_F, plist_id, error) + CALL h5pset_fapl_mpio_f(plist_id, comm, info, error) + + ! + ! Create the file collectively. + ! + CALL h5fcreate_f(filename, H5F_ACC_TRUNC_F, file_id, error, access_prp = plist_id) + CALL h5pclose_f(plist_id, error) + ! + ! Create the data space for the dataset. + ! + CALL h5screate_simple_f(rank, dimsf, filespace, error) + CALL h5screate_simple_f(rank, chunk_dims, memspace, error) + + ! + ! Create chunked dataset. + ! + CALL h5pcreate_f(H5P_DATASET_CREATE_F, plist_id, error) + CALL h5pset_chunk_f(plist_id, rank, chunk_dims, error) + CALL h5dcreate_f(file_id, dsetname, H5T_NATIVE_INTEGER, filespace, & + dset_id, error, plist_id) + CALL h5sclose_f(filespace, error) + ! + ! Each process defines dataset in memory and writes it to the hyperslab + ! in the file. + ! + stride(1) = 1 + stride(2) = 1 + count(1) = 1 + count(2) = 1 + block(1) = chunk_dims(1) + block(2) = chunk_dims(2) + if (mpi_rank .EQ. 0) then + offset(1) = 0 + offset(2) = 0 + endif + if (mpi_rank .EQ. 1) then + offset(1) = chunk_dims(1) + offset(2) = 0 + endif + if (mpi_rank .EQ. 2) then + offset(1) = 0 + offset(2) = chunk_dims(2) + endif + if (mpi_rank .EQ. 3) then + offset(1) = chunk_dims(1) + offset(2) = chunk_dims(2) + endif + ! + ! Select hyperslab in the file. + ! + CALL h5dget_space_f(dset_id, filespace, error) + CALL h5sselect_hyperslab_f (filespace, H5S_SELECT_SET_F, offset, count, error, & + stride, block) + ! + ! Initialize data buffer with trivial data. + ! + ALLOCATE (data(chunk_dims(1),chunk_dims(2))) + data = mpi_rank + 1 + ! + ! Create property list for collective dataset write + ! + CALL h5pcreate_f(H5P_DATASET_XFER_F, plist_id, error) + CALL h5pset_dxpl_mpio_f(plist_id, H5FD_MPIO_COLLECTIVE_F, error) + + ! + ! Write the dataset collectively. + ! + CALL h5dwrite_f(dset_id, H5T_NATIVE_INTEGER, data, dimsfi, error, & + file_space_id = filespace, mem_space_id = memspace, xfer_prp = plist_id) + ! + ! Write the dataset independently. + ! +! CALL h5dwrite_f(dset_id, H5T_NATIVE_INTEGER, data, dimsfi,error, & +! file_space_id = filespace, mem_space_id = memspace) + ! + ! Deallocate data buffer. + ! + DEALLOCATE(data) + + ! + ! Close dataspaces. + ! + CALL h5sclose_f(filespace, error) + CALL h5sclose_f(memspace, error) + ! + ! Close the dataset. + ! + CALL h5dclose_f(dset_id, error) + ! + ! Close the property list. + ! + CALL h5pclose_f(plist_id, error) + ! + ! Close the file. + ! + CALL h5fclose_f(file_id, error) + + ! + ! Close FORTRAN interfaces and HDF5 library. + ! + CALL h5close_f(error) + +100 continue + CALL MPI_FINALIZE(mpierror) + + END PROGRAM DATASET_BY_CHUNK diff --git a/HDF5Examples/FORTRAN/H5PAR/ph5_f90_hyperslab_by_col.F90 b/HDF5Examples/FORTRAN/H5PAR/ph5_f90_hyperslab_by_col.F90 new file mode 100644 index 0000000..b7b46e8 --- /dev/null +++ b/HDF5Examples/FORTRAN/H5PAR/ph5_f90_hyperslab_by_col.F90 @@ -0,0 +1,133 @@ +! +! Number of processes is assumed to be 1 or multiples of 2 (1,2,4,6,8) +! + + PROGRAM DATASET_BY_COL + + USE HDF5 ! This module contains all necessary modules + + IMPLICIT NONE + + include 'mpif.h' + CHARACTER(LEN=10), PARAMETER :: filename = "sds_col.h5" ! File name + CHARACTER(LEN=8), PARAMETER :: dsetname = "IntArray" ! Dataset name + + INTEGER(HID_T) :: file_id ! File identifier + INTEGER(HID_T) :: dset_id ! Dataset identifier + INTEGER(HID_T) :: filespace ! Dataspace identifier in file + INTEGER(HID_T) :: memspace ! Dataspace identifier in memory + INTEGER(HID_T) :: plist_id ! Property list identifier + + INTEGER(HSIZE_T), DIMENSION(2) :: dimsf = (/5,8/) ! Dataset dimensions. +! INTEGER, DIMENSION(7) :: dimsfi = (/5,8,0,0,0,0,0/) + INTEGER(HSIZE_T), DIMENSION(2) :: dimsfi = (/5,8/) + + INTEGER(HSIZE_T), DIMENSION(2) :: count + INTEGER(HSSIZE_T), DIMENSION(2) :: offset + INTEGER, ALLOCATABLE :: data (:,:) ! Data to write + INTEGER :: rank = 2 ! Dataset rank + + INTEGER :: error, error_n ! Error flags + ! + ! MPI definitions and calls. + ! + INTEGER :: mpierror ! MPI error flag + INTEGER :: comm, info + INTEGER :: mpi_size, mpi_rank + comm = MPI_COMM_WORLD + info = MPI_INFO_NULL + CALL MPI_INIT(mpierror) + CALL MPI_COMM_SIZE(comm, mpi_size, mpierror) + CALL MPI_COMM_RANK(comm, mpi_rank, mpierror) + ! + ! Initialize FORTRAN predefined datatypes + ! + CALL h5open_f(error) + + ! + ! Setup file access property list with parallel I/O access. + ! + CALL h5pcreate_f(H5P_FILE_ACCESS_F, plist_id, error) + CALL h5pset_fapl_mpio_f(plist_id, comm, info, error) + + ! + ! Create the file collectively. + ! + CALL h5fcreate_f(filename, H5F_ACC_TRUNC_F, file_id, error, access_prp = plist_id) + CALL h5pclose_f(plist_id, error) + ! + ! Create the data space for the dataset. + ! + CALL h5screate_simple_f(rank, dimsf, filespace, error) + + ! + ! Create the dataset with default properties. + ! + CALL h5dcreate_f(file_id, dsetname, H5T_NATIVE_INTEGER, filespace, & + dset_id, error) + CALL h5sclose_f(filespace, error) + ! + ! Each process defines dataset in memory and writes it to the hyperslab + ! in the file. + ! + count(1) = dimsf(1) + count(2) = dimsf(2)/mpi_size + offset(1) = 0 + offset(2) = mpi_rank * count(2) + CALL h5screate_simple_f(rank, count, memspace, error) + ! + ! Select hyperslab in the file. + ! + CALL h5dget_space_f(dset_id, filespace, error) + CALL h5sselect_hyperslab_f (filespace, H5S_SELECT_SET_F, offset, count, error) + ! + ! Initialize data buffer with trivial data. + ! + ALLOCATE ( data(count(1),count(2))) + data = mpi_rank + 10 + ! + ! Create property list for collective dataset write + ! + CALL h5pcreate_f(H5P_DATASET_XFER_F, plist_id, error) + CALL h5pset_dxpl_mpio_f(plist_id, H5FD_MPIO_COLLECTIVE_F, error) + + ! + ! Write the dataset collectively. + ! + CALL h5dwrite_f(dset_id, H5T_NATIVE_INTEGER, data, dimsfi, error, & + file_space_id = filespace, mem_space_id = memspace, xfer_prp = plist_id) + ! + ! Write the dataset independently. + ! +! CALL h5dwrite_f(dset_id, H5T_NATIVE_INTEGER, data, dimsfi, error, & +! file_space_id = filespace, mem_space_id = memspace) + ! + ! Deallocate data buffer. + ! + DEALLOCATE(data) + + ! + ! Close dataspaces. + ! + CALL h5sclose_f(filespace, error) + CALL h5sclose_f(memspace, error) + + ! + ! Close the dataset and property list. + ! + CALL h5dclose_f(dset_id, error) + CALL h5pclose_f(plist_id, error) + + ! + ! Close the file. + ! + CALL h5fclose_f(file_id, error) + + ! + ! Close FORTRAN predefined datatypes. + ! + CALL h5close_f(error) + + CALL MPI_FINALIZE(mpierror) + + END PROGRAM DATASET_BY_COL diff --git a/HDF5Examples/FORTRAN/H5PAR/ph5_f90_hyperslab_by_pattern.F90 b/HDF5Examples/FORTRAN/H5PAR/ph5_f90_hyperslab_by_pattern.F90 new file mode 100644 index 0000000..0f2077f --- /dev/null +++ b/HDF5Examples/FORTRAN/H5PAR/ph5_f90_hyperslab_by_pattern.F90 @@ -0,0 +1,165 @@ +! +! Number of processes is assumed to be 4 +! + + PROGRAM DATASET_BY_PATTERN + + USE HDF5 ! This module contains all necessary modules + + IMPLICIT NONE + + include 'mpif.h' + CHARACTER(LEN=10), PARAMETER :: filename = "sds_pat.h5" ! File name + CHARACTER(LEN=8), PARAMETER :: dsetname = "IntArray" ! Dataset name + + INTEGER(HID_T) :: file_id ! File identifier + INTEGER(HID_T) :: dset_id ! Dataset identifier + INTEGER(HID_T) :: filespace ! Dataspace identifier in file + INTEGER(HID_T) :: memspace ! Dataspace identifier in memory + INTEGER(HID_T) :: plist_id ! Property list identifier + + INTEGER(HSIZE_T), DIMENSION(2) :: dimsf = (/4,8/) ! Dataset dimensions + ! in the file. +! INTEGER, DIMENSION(7) :: dimsfi = (/4,8,0,0,0,0,0/) + INTEGER(HSIZE_T), DIMENSION(2) :: dimsfi = (/4,8/) + INTEGER(HSIZE_T), DIMENSION(1) :: dimsm = (/8/) ! Dataset dimensions + ! in memory. + + INTEGER(HSIZE_T), DIMENSION(2) :: count + INTEGER(HSSIZE_T), DIMENSION(2) :: offset + INTEGER(HSIZE_T), DIMENSION(2) :: stride + INTEGER, ALLOCATABLE :: data (:) ! Data to write + INTEGER :: rank = 2 ! Dataset rank + INTEGER :: rank1 = 1 ! Memory dataset rank + + INTEGER :: error, error_n ! Error flags + ! + ! MPI definitions and calls. + ! + INTEGER :: mpierror ! MPI error flag + INTEGER :: comm, info + INTEGER :: mpi_size, mpi_rank + + comm = MPI_COMM_WORLD + info = MPI_INFO_NULL + + CALL MPI_INIT(mpierror) + CALL MPI_COMM_SIZE(comm, mpi_size, mpierror) + CALL MPI_COMM_RANK(comm, mpi_rank, mpierror) + ! Quit if mpi_size is not 4 + if (mpi_size .NE. 4) then + write(*,*) 'This example is set up to use only 4 processes' + write(*,*) 'Quitting....' + goto 100 + endif + + ! + ! Initialize HDF5 library and Fortran interfaces. + ! + CALL h5open_f(error) + + ! + ! Setup file access property list with parallel I/O access. + ! + CALL h5pcreate_f(H5P_FILE_ACCESS_F, plist_id, error) + CALL h5pset_fapl_mpio_f(plist_id, comm, info, error) + + ! + ! Create the file collectively. + ! + CALL h5fcreate_f(filename, H5F_ACC_TRUNC_F, file_id, error, access_prp = plist_id) + CALL h5pclose_f(plist_id, error) + ! + ! Create the data space for the dataset. + ! + CALL h5screate_simple_f(rank, dimsf, filespace, error) + CALL h5screate_simple_f(rank1, dimsm, memspace, error) + + ! + ! Create the dataset with default properties. + ! + CALL h5dcreate_f(file_id, dsetname, H5T_NATIVE_INTEGER, filespace, & + dset_id, error) + CALL h5sclose_f(filespace, error) + ! + ! Each process defines dataset in memory and writes it to the hyperslab + ! in the file. + ! + stride(1) = 2 + stride(2) = 2 + count(1) = 2 + count(2) = 4 + if (mpi_rank .EQ. 0) then + offset(1) = 0 + offset(2) = 0 + endif + if (mpi_rank .EQ. 1) then + offset(1) = 0 + offset(2) = 1 + endif + if (mpi_rank .EQ. 2) then + offset(1) = 1 + offset(2) = 0 + endif + if (mpi_rank .EQ. 3) then + offset(1) = 1 + offset(2) = 1 + endif + ! + ! Select hyperslab in the file. + ! + CALL h5dget_space_f(dset_id, filespace, error) + CALL h5sselect_hyperslab_f (filespace, H5S_SELECT_SET_F, offset, count, error, & + stride) + ! + ! Initialize data buffer with trivial data. + ! + ALLOCATE (data(dimsm(1))) + data = mpi_rank + 1 + ! + ! Create property list for collective dataset write + ! + CALL h5pcreate_f(H5P_DATASET_XFER_F, plist_id, error) + CALL h5pset_dxpl_mpio_f(plist_id, H5FD_MPIO_COLLECTIVE_F, error) + + ! + ! Write the dataset collectively. + ! + CALL h5dwrite_f(dset_id, H5T_NATIVE_INTEGER, data, dimsfi, error, & + file_space_id = filespace, mem_space_id = memspace, xfer_prp = plist_id) + ! + ! Write the dataset independently. + ! +! CALL h5dwrite_f(dset_id, H5T_NATIVE_INTEGER, data, dimsfi, error, & +! file_space_id = filespace, mem_space_id = memspace) + ! + ! Deallocate data buffer. + ! + DEALLOCATE(data) + + ! + ! Close dataspaces. + ! + CALL h5sclose_f(filespace, error) + CALL h5sclose_f(memspace, error) + + ! + ! Close the dataset and property list. + ! + CALL h5dclose_f(dset_id, error) + CALL h5pclose_f(plist_id, error) + + ! + ! Close the file. + ! + CALL h5fclose_f(file_id, error) + + ! + ! Close FORTRAN interfaces and HDF5 library. + ! + CALL h5close_f(error) + +100 continue + CALL MPI_FINALIZE(mpierror) + + END PROGRAM DATASET_BY_PATTERN diff --git a/HDF5Examples/FORTRAN/H5PAR/ph5_f90_hyperslab_by_row.F90 b/HDF5Examples/FORTRAN/H5PAR/ph5_f90_hyperslab_by_row.F90 new file mode 100644 index 0000000..398be23 --- /dev/null +++ b/HDF5Examples/FORTRAN/H5PAR/ph5_f90_hyperslab_by_row.F90 @@ -0,0 +1,154 @@ +! +! Number of processes is assumed to be 2 +! + PROGRAM DATASET_BY_ROW + + USE HDF5 ! This module contains all necessary modules + + IMPLICIT NONE + + include 'mpif.h' + CHARACTER(LEN=10), PARAMETER :: filename = "sds_row.h5" ! File name + CHARACTER(LEN=8), PARAMETER :: dsetname = "IntArray" ! Dataset name + + INTEGER(HID_T) :: file_id ! File identifier + INTEGER(HID_T) :: dset_id ! Dataset identifier + INTEGER(HID_T) :: filespace ! Dataspace identifier in file + INTEGER(HID_T) :: memspace ! Dataspace identifier in memory + INTEGER(HID_T) :: plist_id ! Property list identifier + + INTEGER(HSIZE_T), DIMENSION(2) :: dimsf = (/6,8/) ! Dataset dimensions + ! in the file. +! INTEGER, DIMENSION(7) :: dimsfi = (/6,8,0,0,0,0,0/) + INTEGER(HSIZE_T), DIMENSION(2) :: dimsfi = (/6,8/) + INTEGER(HSIZE_T), DIMENSION(2) :: dimsm = (/3,8/) ! Dataset dimensions + ! in memory. + + INTEGER(HSIZE_T), DIMENSION(2) :: count + INTEGER(HSSIZE_T), DIMENSION(2) :: offset + INTEGER(HSIZE_T), DIMENSION(2) :: stride + INTEGER(HSIZE_T), DIMENSION(2) :: block + INTEGER, ALLOCATABLE :: data (:,:) ! Data to write + INTEGER :: rank = 2 ! Dataset rank + + INTEGER :: error, error_n ! Error flags + ! + ! MPI definitions and calls. + ! + INTEGER :: mpierror ! MPI error flag + INTEGER :: comm, info + INTEGER :: mpi_size, mpi_rank + + comm = MPI_COMM_WORLD + info = MPI_INFO_NULL + + CALL MPI_INIT(mpierror) + CALL MPI_COMM_SIZE(comm, mpi_size, mpierror) + CALL MPI_COMM_RANK(comm, mpi_rank, mpierror) + ! Quit if mpi_size is not 2 + if (mpi_size .NE. 2) then + write(*,*) 'This example is set up to use only 2 processes' + write(*,*) 'Quitting....' + goto 100 + endif + + ! + ! Initialize HDF5 library and Fortran interfaces. + ! + CALL h5open_f(error) + + ! + ! Setup file access property list with parallel I/O access. + ! + CALL h5pcreate_f(H5P_FILE_ACCESS_F, plist_id, error) + CALL h5pset_fapl_mpio_f(plist_id, comm, info, error) + + ! + ! Create the file collectively. + ! + CALL h5fcreate_f(filename, H5F_ACC_TRUNC_F, file_id, error, access_prp = plist_id) + CALL h5pclose_f(plist_id, error) + ! + ! Create the data space for the dataset. + ! + CALL h5screate_simple_f(rank, dimsf, filespace, error) + CALL h5screate_simple_f(rank, dimsm, memspace, error) + + ! + ! Create the dataset with default properties. + ! + CALL h5dcreate_f(file_id, dsetname, H5T_NATIVE_INTEGER, filespace, & + dset_id, error) + CALL h5sclose_f(filespace, error) + ! + ! Each process defines dataset in memory and writes it to the hyperslab + ! in the file. + ! + count(1) = dimsm(1) + count(2) = 1 + offset(1) = mpi_rank + offset(2) = 0 + stride(1) = 2 + stride(2) = 1 + block(1) = 1 + block(2) = dimsf(2) + ! + ! Select hyperslab in the file. + ! + CALL h5dget_space_f(dset_id, filespace, error) + CALL h5sselect_hyperslab_f (filespace, H5S_SELECT_SET_F, offset, count, error, & + stride, block) + ! + ! Initialize data buffer with trivial data. + ! + ALLOCATE (data(dimsm(1),dimsm(2))) + data(1,:) = mpi_rank+1 + data(2,:) = (mpi_rank+1)*10 + data(3,:) = (mpi_rank+1)*100 + ! + ! Create property list for collective dataset write + ! + CALL h5pcreate_f(H5P_DATASET_XFER_F, plist_id, error) + CALL h5pset_dxpl_mpio_f(plist_id, H5FD_MPIO_COLLECTIVE_F, error) + + ! + ! Write the dataset collectively. + ! + CALL h5dwrite_f(dset_id, H5T_NATIVE_INTEGER, data, dimsfi, error, & + file_space_id = filespace, mem_space_id = memspace, xfer_prp = plist_id) + ! + ! Write the dataset independently. + ! +! CALL h5dwrite_f(dset_id, H5T_NATIVE_INTEGER, data, dimsfi, error, & +! file_space_id = filespace, mem_space_id = memspace) + ! + ! Deallocate data buffer. + ! + DEALLOCATE(data) + + ! + ! Close dataspaces. + ! + CALL h5sclose_f(filespace, error) + CALL h5sclose_f(memspace, error) + + ! + ! Close the dataset and property list. + ! + CALL h5dclose_f(dset_id, error) + CALL h5pclose_f(plist_id, error) + + ! + ! Close the file. + ! + CALL h5fclose_f(file_id, error) + + ! + ! Close FORTRAN interfaces and HDF5 library. + ! + CALL h5close_f(error) + +100 continue + CALL MPI_FINALIZE(mpierror) + + END PROGRAM DATASET_BY_ROW |