From 55dc398898aa80eadf709771c6112bee367e3610 Mon Sep 17 00:00:00 2001 From: Miki Bonacci Date: Fri, 16 Feb 2024 11:36:18 +0100 Subject: [PATCH] adding the deallocation of variables - eigval2, eigval_opt, utmp in hamiltonian_get_hr - umatnew, ZU, deltaU, carr in sitesym_dis_extract_symmetry also, I moved the eigval2 allocation after the *if (ham_logical%have_ham_k) go to 100* line, because if we go to 100, we do not need the eigval2 variale --- src/hamiltonian.F90 | 39 ++++++++++++++++++++++++++++++++------- src/sitesym.F90 | 26 +++++++++++++++++++++++++- 2 files changed, 57 insertions(+), 8 deletions(-) diff --git a/src/hamiltonian.F90 b/src/hamiltonian.F90 index d100a591..f0721f63 100644 --- a/src/hamiltonian.F90 +++ b/src/hamiltonian.F90 @@ -286,12 +286,6 @@ subroutine hamiltonian_get_hr(atom_data, dis_manifold, ham_logical, real_space_h complex(kind=dp), allocatable :: utmp(:, :) !(num_bands, num_wann) complex(kind=dp) :: fac - allocate (eigval2(num_wann, num_kpts), stat=ierr) - if (ierr /= 0) then - call set_error_alloc(error, 'Error in allocating eigval2 in hamiltonian_get_hr', comm) - return - endif - if (print_output%timing_level > 1) call io_stopwatch_start('hamiltonian: get_hr', timer) if (ham_logical%have_ham_r) then @@ -306,6 +300,14 @@ subroutine hamiltonian_get_hr(atom_data, dis_manifold, ham_logical, real_space_h ham_k = cmplx_0 + allocate (eigval2(num_wann, num_kpts), stat=ierr) + if (ierr /= 0) then + call set_error_alloc(error, 'Error in allocating eigval2 in hamiltonian_get_hr', comm) + return + endif + + eigval2 = 0.0_dp + if (have_disentangled) then ! start allocation of eigval_opt, utmp; used only if have_disentangled. @@ -322,7 +324,6 @@ subroutine hamiltonian_get_hr(atom_data, dis_manifold, ham_logical, real_space_h endif eigval_opt = 0.0_dp - eigval2 = 0.0_dp ! end allocation of eigval_opt, utmp ! slim down eigval to contain states within the outer window @@ -473,6 +474,30 @@ subroutine hamiltonian_get_hr(atom_data, dis_manifold, ham_logical, real_space_h endif end if + if (allocated(eigval2)) then + deallocate (eigval2, stat=ierr) + if (ierr /= 0) then + call set_error_dealloc(error, 'Error in deallocating eigval2 in hamiltonian_get_hr', comm) + return + endif + end if + + if (allocated(eigval_opt)) then + deallocate (eigval_opt, stat=ierr) + if (ierr /= 0) then + call set_error_dealloc(error, 'Error in deallocating eigval_opt in hamiltonian_get_hr', comm) + return + endif + end if + + if (allocated(utmp)) then + deallocate (utmp, stat=ierr) + if (ierr /= 0) then + call set_error_dealloc(error, 'Error in deallocating utmp in hamiltonian_get_hr', comm) + return + endif + end if + if (print_output%timing_level > 1) call io_stopwatch_stop('hamiltonian: get_hr', timer) return diff --git a/src/sitesym.F90 b/src/sitesym.F90 index 6fc58986..beac85c8 100644 --- a/src/sitesym.F90 +++ b/src/sitesym.F90 @@ -560,7 +560,7 @@ subroutine sitesym_dis_extract_symmetry(sitesym, lambda, umat, zmat, ik, n, num_ !================================================! use w90_wannier90_types, only: sitesym_type - use w90_error, only: w90_error_type, set_error_fatal, set_error_alloc + use w90_error, only: w90_error_type, set_error_fatal, set_error_alloc, set_error_dealloc implicit none @@ -667,6 +667,30 @@ subroutine sitesym_dis_extract_symmetry(sitesym, lambda, umat, zmat, ik, n, num_ umat(:, :) = umatnew(:, :) enddo ! iter + deallocate (umatnew, stat=ierr) + if (ierr /= 0) then + call set_error_dealloc(error, 'Error in deallocating umatnew in sitesym_dis_extract_symmetry', comm) + return + endif + + deallocate (ZU, stat=ierr) + if (ierr /= 0) then + call set_error_dealloc(error, 'Error in deallocating ZU in sitesym_dis_extract_symmetry', comm) + return + endif + + deallocate (deltaU, stat=ierr) + if (ierr /= 0) then + call set_error_dealloc(error, 'Error in deallocating deltaU in sitesym_dis_extract_symmetry', comm) + return + endif + + deallocate (carr, stat=ierr) + if (ierr /= 0) then + call set_error_dealloc(error, 'Error in deallocating carr in sitesym_dis_extract_symmetry', comm) + return + endif + return end subroutine sitesym_dis_extract_symmetry