write_rdms_hdf5 Subroutine

public subroutine write_rdms_hdf5(rdm_defs, rdm, rdm_trace, one_rdms)

Write all RDMs specified in the input to an HDF5 archive.

Arguments

Type IntentOptional Attributes Name
type(rdm_definitions_t), intent(in) :: rdm_defs

Type carrying information such as number and type of RDM (regular/transition)

type(rdm_list_t), intent(in) :: rdm

2RDM data distributed over all MPI ranks

real(kind=dp), intent(in) :: rdm_trace(rdm%sign_length)

Normalisation of the 2RDM

type(one_rdm_t), intent(inout), optional :: one_rdms(:)

Array carrying the 1RDM belonging to each root


Contents

Source Code


Source Code

    subroutine write_rdms_hdf5(rdm_defs, rdm, rdm_trace, one_rdms)
        use rdm_data, only: rdm_definitions_t, rdm_list_t, one_rdm_t
        use LoggingData, only: tWriteSpinFreeRDM, tPrint1RDM
        !> Type carrying information such as number and type of RDM (regular/transition)
        type(rdm_definitions_t), intent(in) :: rdm_defs
        !> 2RDM data distributed over all MPI ranks
        type(rdm_list_t), intent(in) :: rdm
        !> Normalisation of the 2RDM
        real(dp), intent(in) :: rdm_trace(rdm%sign_length)
        !> Array carrying the 1RDM belonging to each root
        type(one_rdm_t), intent(inout), optional :: one_rdms(:)
        !> Required for the stop all to check for HDF5 library
        character(*), parameter :: this_routine = 'write_hdf5_rdms'
#ifdef USE_HDF_
        !> File and group handles
        integer(hid_t) :: file_id, root_id, rdm_id, plist_id
        !> HDF5 error code
        integer(hdf_err) :: err
        !> Name of the HDF5 archive
        character(255) :: filename
        !> The iroot'th eigenvector of Hamiltonian, e.g. 1 for ground state,
        !> 2 for first excited state, ...
        integer :: iroot

        if (rdm_defs%nrdms_transition > 0) then
            call stop_all(this_routine, "Transition RDM support pending.")
        end if

        do iroot = 1, rdm_defs%nrdms
            if (iProcIndex == 0) then
                filename = 'fciqmc.rdms.' // str(iroot) // '.h5'
                write(stdout, *) "============== Writing HDF5 RDMs =============="
                write(stdout, *) "File name: ", trim(filename)
                write(stdout, *) "Regular RDMs saved in /archive/rdms/AA00/ where &
                                     &A denotes the number of fermion operators."
            end if
            call MPIBCast(filename)

            ! All HDF5 APIs that modify structural metadata are collective
            call h5open_f(err)
            call h5pcreate_f(H5P_FILE_ACCESS_F, plist_id, err)
            ! setup file access property list for MPI-IO access.
            call h5pset_fapl_mpio_f(plist_id, CommGlobal, mpiInfoNull, err)
            ! create the file collectively, H5F_ACC_TRUNC_F = overwrite existing file
            call h5fcreate_f(filename, H5F_ACC_TRUNC_F, file_id, err, access_prp=plist_id)
            call h5pclose_f(plist_id, err)
            call h5gcreate_f(file_id, 'archive', root_id, err)
            call h5gcreate_f(root_id, 'rdms', rdm_id, err)

            if (tPrint1RDM) then
                call write_1rdm_hdf5(rdm_id, one_rdms(iroot)%matrix)
                write(stdout, *) "1RDM written to file."
            end if
            if (tWriteSpinFreeRDM) then
                call write_2rdm_hdf5(rdm_id, rdm, rdm_trace, iroot)
                write(stdout, *) "2RDM written to file."
            end if

            if (iProcIndex == 0) write(stdout, *) "closing RDM file."
            call h5gclose_f(rdm_id, err)
            call h5gclose_f(root_id, err)
            call h5fclose_f(file_id, err)
            call h5close_f(err)
            call h5garbage_collect_f(err)
            if (iProcIndex == 0) write(stdout, *) "RDM file write successful."
        end do
#else
      unused_var(rdm_defs)
      unused_var(rdm)
      unused_var(rdm_trace)
      unused_var(one_rdms)
      call stop_all(this_routine, 'HDF5 support not enabled at compile time.')
#endif
    end subroutine write_rdms_hdf5