使用fortran中的分块并行写入HDF5文件

时间:2017-05-04 20:12:07

标签: arrays parallel-processing fortran mpi hdf5

问题:我有两个分散在多个处理器上的2D阵列。想象一下,有一个数组被定义为

DOUBLE PRECISION :: F_TOTAL(n1:n2,m1:m2)

现在每个处理器都有一个数组

DOUBLE PRECISION :: F(n1:n2,mystart:myend)

最后,我想将F_TOTAL存储在HDF5文件中。

解决方案:这似乎是使用Hyperslabs的好地方。然而,需要注意的是,虽然所有处理器具有相同的n1n2 mystart,但myend不同。具体而言,每个处理器F的第二维是唯一的(但始终> 0)。

我的崩溃代码

  SUBROUTINE write_parhdf5(n1,n2,m1,m2,mystart,myend,Farr,var_name,comm)

  USE mpi_params
  USE hdf5

  IMPLICIT NONE
  INTEGER :: n1,n2,m1,m2,mystart,myend,comm
  DOUBLE PRECISION :: Farr(n1:n2,mystart:myend)
  CHARACTER(LEN=*), INTENT(in)  :: var_name

  INCLUDE 'mpif.h'

  INTEGER :: ier, info, rank
  INTEGER(HID_T) :: file_id, fspace_id, dset_id, mspace_id, &
                    fapl_id, dcpl_id, dxpl_id, driver_id
  INTEGER(HSIZE_T), ALLOCATABLE :: dimsf(:), counts(:), chunk_dims(:),&
                                   offset(:)

  !-------Begin Subroutine
  ier = 0
  info = MPI_INFO_NULL

  ! Initialize
  CALL h5open_f(ier)

  ! Setup File access
  CALL h5pcreate_f(H5P_FILE_ACCESS_F, fapl_id, ier)
  CALL h5pset_fapl_mpio_f(fapl_id, comm, info, ier)
  CALL h5pget_driver_f(fapl_id, driver_id, ier)
  ! Open file
  CALL h5fopen_f('file.h5', H5F_ACC_RDWR_F, file_id, ier, access_prp = fapl_id)

  ! Setup Helper Arrays
  rank =2;
  ALLOCATE(dimsf(rank),chunk_dims(rank),counts(rank),offset(rank))
  dimsf(1) = n2-n1+1
  dimsf(2) = m2-m1+1
  chunk_dims(1) = SIZE(Farr,1)
  chunk_dims(2) = SIZE(Farr,2)
  counts(1) = 1
  counts(2) = 1
  offset(1) = 0
  offset(2) = mystart-1

  ! Create Spaces
  CALL h5screate_simple_f(rank, dimsf, fspace_id, ier)
  CALL h5screate_simple_f(rank, dimsf, mspace_id, ier)

  ! Enable Chunking
  CALL h5pcreate_f(H5P_DATASET_CREATE_F, dcpl_id, ier)
  CALL h5pset_chunk_f(dcpl_id, rank, chunk_dims, ier)

  ! Create Dataset
  CALL h5dcreate_f(file_id, TRIM(var_name), H5T_NATIVE_DOUBLE, fspace_id, dset_id, ier, dcpl_id)


  ! Select Hyperslab in memory
  CALL h5sselect_hyperslab_f(mspace_id, H5S_SELECT_SET_F, offset, chunk_dims, ier)

  ! Select Hyperslab in File
  CALL h5sselect_hyperslab_f(fspace_id, H5S_SELECT_SET_F, offset, chunk_dims, ier)

  ! Create Properties
  CALL h5pcreate_f(H5P_DATASET_XFER_F, dxpl_id, ier)
  CALL h5pset_dxpl_mpio_f(dxpl_id, H5FD_MPIO_COLLECTIVE_F, ier)


  ! Write dataset
  CALL h5dwrite_f(dset_id, H5T_NATIVE_DOUBLE, Farr, dimsf, ier, mem_space_id = mspace_id, file_space_id = fspace_id, xfer_prp = dxpl_id)

  ! Close Property list
  CALL h5pclose_f(fapl_id, ier)
  CALL h5pclose_f(dcpl_id, ier)
  CALL h5pclose_f(dxpl_id, ier)
  CALL h5sclose_f(mspace_id, ier)
  CALL h5sclose_f(fspace_id, ier)
  CALL h5dclose_f(dset_id, ier)

  ! Deallocate Helpers
  DEALLOCATE(dimsf,chunk_dims,counts,offset)

  ! Close the file
  CALL h5fclose_f(file_id, ier)
  ! Close the fortran interface
  CALL h5close_f(ier)
  RETURN

  END SUBROUTINE write_parhdf5

我得到的问题是,当我调用此例程时,我收到错误

 Error: Unsupported datatype passed to ADIOI_Count_contiguous_blocks, combiner = 17

必须有可能让每个处理器写一个不同的hyperslab大小,对吧?

0 个答案:

没有答案