NECICalcEnd Subroutine

subroutine NECICalcEnd(iCacheFlag)


Type IntentOptional Attributes Name
integer, intent(in) :: iCacheFlag


Source Code

Source Code

subroutine NECICalcEnd(iCacheFlag)
    != Calculation specific termination: just a wrapper for the individual
    != termination routines: deallocation etc.
    != In:
    !=    iCacheFlag: controls the behaviour of the 4-index integral cache.
    !=                Currently relevant only for CPMD and VASP calculations.
    !=                iCacheFlag=0,2: destroy the cache on exit.
    !=                iCacheFlag=1,3: keep the cache on exit: it will be re-used
    !=                                in subsequent calculations within the same
    !=                                call to CPMD/VASP.

    ! Main level modules.
    use System, only: SysCleanup
    use Integrals_neci, only: IntCleanup
    use Determinants, only: DetCleanup
    use Calc, only: CalcCleanup
    use replica_data, only: clean_replica_arrays
    use OneEInts, only: DestroyTMat, DestroyPropInts
    use Parallel_neci, only: clean_parallel
    use SymExcitDataMod, only: SpinOrbSymLabel, SymInvLabel
    use SystemData, only: arr, brr, g1, tagArr, tagBrr, tagG1
    use DeterminantData, only: FDet, tagFDet
    use MemoryManager
    use FciMCData, only: ValidSpawnedList, InitialSpawnedSlots
    use LoggingData, only: tCalcPropEst

    implicit none
    integer, intent(in) :: iCacheFlag

!   Tidy up:
    call CalcCleanup()
    call DetCleanup()
    call IntCleanup(iCacheFlag)
    call DestroyTMAT(.true.)
    call DestroyTMAT(.false.)
    if (tCalcPropEst) call DestroyPropInts
    call SysCleanup()
    call clean_replica_arrays()
    call clean_parallel()

    if (allocated(SpinOrbSymLabel)) deallocate(SpinOrbSymLabel)
    if (allocated(SymInvLabel)) deallocate(SymInvLabel)
    if (allocated(ValidSpawnedList)) deallocate(ValidSpawnedList)
    if (allocated(InitialSpawnedSlots)) deallocate(InitialSpawnedSlots)
    if (associated(arr)) then
        call LogMemDealloc('NECICore', tagArr)
    end if
    if (associated(brr)) then
        call LogMemDealloc('NECICore', tagBrr)
    end if
    if (associated(G1)) then
        call LogMemDealloc('NECICore', tagG1)
    end if
    if (associated(FDet)) then
        call LogMemDealloc('NECICore', tagFDet)
    end if

end subroutine NECICalcEnd