subroutine perform_davidson_ss(this, print_info_in, run)
logical, intent(in) :: print_info_in
integer, intent(in) :: run
logical :: print_info
integer :: i
real(dp) :: start_time, end_time
type(davidson_ss), intent(inout) :: this
character(*), parameter :: this_routine = "perform_davidson_ss"
! Only let the root processor print information.
print_info = print_info_in .and. (iProcIndex == root)
call init_davidson_ss(this, print_info, run)
if (print_info) write(stdout, '(1X,"Iteration",4X,"Residual norm",12X,"Energy",7X,"Time")'); call neci_flush(stdout)
do i = 2, min(max_num_davidson_iters, this%space_size)
start_time = MPI_WTIME()
call subspace_expansion_ss(this, i)
call project_hamiltonian_ss(this, i)
call subspace_extraction_ss(this, i)
call calculate_residual_ss(this, i)
call calculate_residual_norm_ss(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 == min(max_num_davidson_iters, this%space_size)) 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 free_davidson_ss(this)
end subroutine perform_davidson_ss