subroutine perform_davidson(this, hamil_type_in, print_info_in)
use mpi
integer, intent(in) :: hamil_type_in
logical, intent(in) :: print_info_in
logical :: print_info
integer :: i
real(dp) :: start_time, end_time
type(DavidsonCalcType), intent(inout) :: this
character(*), parameter :: this_routine = "perform_davidson"
! Only let the root processor print information.
print_info = print_info_in .and. (iProcIndex == root)
call InitDavidsonCalc(this, print_info, hamil_type_in)
if (print_info) write(stdout, '(1X,"Iteration",4X,"Residual norm",12X,"Energy",7X,"Time")'); call neci_flush(stdout)
do i = 2, max_num_davidson_iters
if (this%super%skip_calc) exit
start_time = MPI_WTIME()
if (iProcIndex == root) call subspace_expansion(this, i)
call project_hamiltonian(this, i)
if (iProcIndex == root) call subspace_extraction(this, i)
call calculate_residual(this, i)
call calculate_residual_norm(this)
end_time = MPI_WTIME()
if (print_info) write(stdout, '(8X,i2,3X,f14.9,2x,f16.10,2x,f9.3)') i - 1, this%residual_norm, &
this%davidson_eigenvalue, end_time - start_time; call neci_flush(stdout)
if (this%residual_norm < residual_norm_target) exit
if (i == max_num_davidson_iters) then
call stop_all(this_routine, "Davidson iteration reached the maximum number of iterations. &
&The deterministic energy may not be converged. &
&You can increase 'davidson-max-iters' or 'davidson-target-tolerance'.")
end if
end do
if (print_info) write(stdout, '(/,1x,"Final calculated correlation energy:",1X,f16.10)') this%davidson_eigenvalue
call FreeDavidsonCalc(this)
end subroutine perform_davidson