33 use const_gbl,
only: stdout
40 use mpi_gbl,
only: master, myrank, mpi_mod_bcast, mpi_xermsg
53 subroutine diagonalize_davidson(this, matrix_elements, num_eigenpair, dresult, all_procs, option, integrals)
56 class(
basematrix),
intent(in) :: matrix_elements
58 type(
options),
intent(in) :: option
59 integer,
intent(in) :: num_eigenpair
60 logical,
intent(in) :: all_procs
62 integer :: max_iterations
63 real(wp) :: max_tolerance
66 if (myrank /= master)
return
69 call mpi_xermsg(
'DavidsonDiagonalizer_module',
'diagonalize_davidson', &
70 'PASS_TO_CDENPROP not implemented for Davidson', 1, 1)
73 max_iterations = option % max_iterations
74 max_tolerance = option % max_tolerance
76 if (max_iterations < 0)
then
77 max_iterations = max(num_eigenpair * 40, 500)
80 print *,
'max_iterations', max_iterations
81 print *,
'max_tolerance', max_tolerance
83 select type(matrix_elements)
85 call this % diagonalize_writermatrix(matrix_elements, num_eigenpair, dresult, all_procs, &
86 max_iterations, max_tolerance, option, integrals)
88 call mpi_xermsg(
'DavidsonDiagonalizer_module',
'diagonalize_davidson', &
89 'Only WriterMatrix format can use Davidson', 1, 1)
95 subroutine diagonalize_writermatrix (this, matrix_elements, num_eigenpair, dresult, all_procs, max_iterations, max_tolerance, &
101 type(
options),
intent(in) :: option
102 integer,
intent(in) :: num_eigenpair
103 logical,
intent(in) :: all_procs
104 integer,
intent(in) :: max_iterations
105 real(wp),
intent(in) :: max_tolerance
109 real(wp) :: CRITC = 1e-10_wp
110 real(wp) :: CRITR = 1e-8_wp
111 real(wp) :: ORTHO = 1e-7_wp
113 integer :: matrix_unit
114 integer :: matrix_size
115 integer :: num_matrix_elements_per_record, num_elems
117 real(wp),
allocatable :: hamiltonian(:), diagonal(:), eig(:)
118 real(wp),
pointer :: vec_ptr(:)
120 integer :: mpi_num_eig, mpi_num_vecs, ido, ierr
122 real(wp),
allocatable :: eigen(:)
123 real(wp),
allocatable :: vecs(:,:)
125 character(len=4),
dimension(30) :: NAMP
126 integer,
dimension(10) :: NHD
127 integer,
dimension(20) :: KEYCSF, NHE
128 real(kind=wp),
dimension(41) :: dtnuc
130 write (stdout,
"('Diagonalization done with Davidson')")
131 write (stdout,
"('Parameters:')")
132 write (stdout,
"('N: ',i8)") matrix_elements % get_matrix_size()
133 write (stdout,
"('Requested # of eigenpairs',i8)") num_eigenpair
135 allocate(eigen(num_eigenpair), vecs(matrix_elements % get_matrix_size(), num_eigenpair))
141 if (myrank == master)
then
143 matrix_unit = matrix_elements % get_matrix_unit()
147 read (matrix_unit) matrix_size, num_matrix_elements_per_record, nhd, namp, nhe, dtnuc
149 num_elems = matrix_elements % get_size()
150 print *,
'matrix_size', matrix_size
151 print *,
'num_elems', num_elems
154 allocate(diagonal(matrix_size))
155 call mkdvm(vecs, eigen, diagonal, matrix_size, num_eigenpair, stdout, matrix_unit, &
156 num_matrix_elements_per_record, num_elems, max_tolerance, critc, critr, ortho, &
157 max_iterations, ierr)
160 call mpi_xermsg(
'DavidsonDiagonalizer_module',
'DavidsonDiagonalizer', &
161 'Davidson diagonalization failed', ierr, 1)
166 call mpi_mod_bcast(matrix_size, master)
167 mpi_num_vecs = matrix_size * num_eigenpair
168 mpi_num_eig = num_eigenpair
169 call mpi_mod_bcast(eigen,master)
170 do ido = 1, num_eigenpair
171 call mpi_mod_bcast(vecs(:,ido), master)
176 call dresult % export_header(option, integrals)
178 call dresult % write_header(option, integrals)
179 call dresult % handle_eigenvalues(eigen, matrix_elements % diagonal, num_eigenpair, matrix_size)
181 do ido = 1, num_eigenpair
182 call dresult % handle_eigenvector(vecs(:,ido), matrix_size)
185 deallocate(eigen, vecs)