subroutine write_popsfile_hdf5(MaxEx, IterSuffix)
use CalcData, only: iPopsFileNoWrite
use LoggingData, only: tIncrementPops
use FciMCData, only: Iter, PreviousCycles
! TODO:
! 1) Deal with multiple filenames
! 2) Deal with build configurations without HDF5
! 3) Deal with HDF5 build configurations without MPIO
! 4) Should we in some way make incrementpops default?
integer, intent(in), optional :: MaxEx
logical, intent(in), optional :: IterSuffix
#ifndef USE_HDF_
character(*), parameter :: this_routine = 'write_popsfile_hdf5'
#endif
#ifdef USE_HDF_
integer(hid_t) :: plist_id, file_id
integer(hdf_err) :: err
integer :: mpi_err
character(255) :: filename
character(64) :: stem
character(4) :: MaxExStr
character(32) :: IterStr
! Get a unique filename for this popsfile. This needs to be done on
! the head node to avoid collisions.
if (iProcIndex == 0) then
if (present(MaxEx)) then
write(MaxExStr, '(I0)') MaxEx
stem = 'popsfile_trunc'//MaxExStr
else
stem = 'popsfile'
end if
if (present(IterSuffix) .and. IterSuffix) then
write(IterStr, '(I0)') (Iter + PreviousCycles)
stem = trim(stem)//'_'//IterStr
end if
call get_unique_filename(trim(stem), &
tIncrementPops, .true., iPopsFileNoWrite, &
filename, ext='.h5')
end if
call MPIBCast(filename)
write(stdout, *)
if (present(MaxEx)) then
write(stdout, *) "========= Writing Truncated HDF5 popsfile ========="
else
write(stdout, *) "============== Writing HDF5 popsfile =============="
end if
write(stdout, *) "File name: ", trim(filename)
! Initialise the hdf5 fortran interface
call h5open_f(err)
! Set up a property list to ensure file handling across all nodes.
! TODO: Check if we should be using a more specific communicator
call h5pcreate_f(H5P_FILE_ACCESS_F, plist_id, err)
! call h5pset_fapl_mpio_f(plist_id, MPI_COMM_WORLD, MPI_INFO_NULl, err)
call h5pset_fapl_mpio_f(plist_id, CommGlobal, mpiInfoNull, err)
! TODO: Do sensible file handling here...
call h5fcreate_f(filename, H5F_ACC_TRUNC_F, file_id, err, &
access_prp=plist_id)
call h5pclose_f(plist_id, err)
write(stdout, *) "writing metadata"
call write_metadata(file_id)
write(stdout, *) "writing calc_data"
call write_calc_data(file_id)
call MPIBarrier(mpi_err)
if (present(MaxEx)) then
write(stdout, *) "writing walkers up to excitation level: ", MaxExStr
else
write(stdout, *) "writing walkers"
end if
call write_walkers(file_id, MaxEx)
call MPIBarrier(mpi_err)
write(stdout, *) "closing popsfile"
! And we are done!
call h5fclose_f(file_id, err)
call h5close_f(err)
call h5garbage_collect_f(err)
call MPIBarrier(mpi_err)
write(stdout, *) "popsfile write successful"
#else
call stop_all(this_routine, 'HDF5 support not enabled at compile time')
unused_var(MaxEx)
unused_var(IterSuffix)
unused_var(tIncrementPops)
unused_var(iPopsFileNoWrite)
unused_var(iter)
unused_var(PreviousCycles)
#endif
end subroutine write_popsfile_hdf5