From dfb4538a50bcc5667552f3063f4f7055aec38bb7 Mon Sep 17 00:00:00 2001 From: Matthieu Verstraete Date: Fri, 21 Dec 2018 11:59:16 +0100 Subject: [PATCH 1/2] bugfix: calling w90 as a lib twice does not reinitialize Hamiltonian properly. --- src/hamiltonian.F90 | 8 ++++++++ src/wannierise.F90 | 15 +++++++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/hamiltonian.F90 b/src/hamiltonian.F90 index 6d8d4cbe7..d136fd87f 100644 --- a/src/hamiltonian.F90 +++ b/src/hamiltonian.F90 @@ -152,6 +152,14 @@ subroutine hamiltonian_dealloc() if (ierr /= 0) call io_error('Error in deallocating wannier_centres_translated in param_dealloc') end if + ham_have_setup = .false. + have_translated = .false. + use_translation = .false. + have_ham_r = .false. + have_ham_k = .false. + hr_written = .false. + tb_written = .false. + return end subroutine hamiltonian_dealloc diff --git a/src/wannierise.F90 b/src/wannierise.F90 index 49b783538..7e78a3c99 100644 --- a/src/wannierise.F90 +++ b/src/wannierise.F90 @@ -235,8 +235,16 @@ subroutine wann_main if (ierr /= 0) call io_error('Error in allocating cdq in wann_main') ! for MPI - allocate (counts(0:num_nodes - 1), displs(0:num_nodes - 1), stat=ierr) - if (ierr /= 0) call io_error('Error in allocating counts and displs in wann_main') + allocate (counts(0:num_nodes - 1), stat=ierr) + if (ierr /= 0) then + call io_error('Error in allocating counts in wann_main') + end if + + if (allocated(displs)) deallocate(displs) + allocate (displs(0:num_nodes - 1), stat=ierr) + if (ierr /= 0) then + call io_error('Error in allocating displs in wann_main') + end if call comms_array_split(num_kpts, counts, displs) allocate (rnkb_loc(num_wann, nntot, max(1, counts(my_node_id))), stat=ierr) if (ierr /= 0) call io_error('Error in allocating rnkb_loc in wann_main') @@ -801,6 +809,9 @@ subroutine wann_main if (ierr /= 0) call io_error('Error in deallocating m0_loc in wann_main') end if + if (allocated(counts)) deallocate(counts) + if (allocated(displs)) deallocate(displs) + deallocate (history, stat=ierr) if (ierr /= 0) call io_error('Error deallocating history in wann_main') From e2481266becd844a8d25e7cb7d1604afe159825d Mon Sep 17 00:00:00 2001 From: Matthieu Verstraete Date: Fri, 21 Dec 2018 16:58:10 +0100 Subject: [PATCH 2/2] hooks --- src/wannierise.F90 | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/wannierise.F90 b/src/wannierise.F90 index 7e78a3c99..efb1c4e02 100644 --- a/src/wannierise.F90 +++ b/src/wannierise.F90 @@ -235,12 +235,13 @@ subroutine wann_main if (ierr /= 0) call io_error('Error in allocating cdq in wann_main') ! for MPI + if (allocated(counts)) deallocate (counts) allocate (counts(0:num_nodes - 1), stat=ierr) if (ierr /= 0) then call io_error('Error in allocating counts in wann_main') end if - if (allocated(displs)) deallocate(displs) + if (allocated(displs)) deallocate (displs) allocate (displs(0:num_nodes - 1), stat=ierr) if (ierr /= 0) then call io_error('Error in allocating displs in wann_main') @@ -809,8 +810,8 @@ subroutine wann_main if (ierr /= 0) call io_error('Error in deallocating m0_loc in wann_main') end if - if (allocated(counts)) deallocate(counts) - if (allocated(displs)) deallocate(displs) + if (allocated(counts)) deallocate (counts) + if (allocated(displs)) deallocate (displs) deallocate (history, stat=ierr) if (ierr /= 0) call io_error('Error deallocating history in wann_main')