Skip to content

Commit

Permalink
adding the deallocation of variables
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
mikibonacci committed Feb 16, 2024
1 parent b5293ec commit 55dc398
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 8 deletions.
39 changes: 32 additions & 7 deletions src/hamiltonian.F90
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
26 changes: 25 additions & 1 deletion src/sitesym.F90
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 55dc398

Please sign in to comment.