33 use blas_lapack_gbl,
only: blasint
34 use precisn,
only: longint, wp
35 use const_gbl,
only: stdout
42 use mpi_gbl,
only: master, myrank, nprocs, mpi_mod_bcast, mpi_mod_barrier
57 subroutine choose_matelem (this, matrix_elements, num_eigenpair, dresult, all_procs, option, integrals)
60 class(
basematrix),
intent(in) :: matrix_elements
62 type(
options),
intent(in) :: option
63 integer,
intent(in) :: num_eigenpair
64 logical,
intent(in) :: all_procs
66 select type(matrix_elements)
68 call this % diagonalize_writer(matrix_elements, num_eigenpair, dresult, all_procs, option, integrals)
77 subroutine diagonalize_writer (this, matrix_elements, num_eigenpair, dresult, all_procs, option, integrals)
82 type(
options),
intent(in) :: option
83 integer,
intent(in) :: num_eigenpair
84 logical,
intent(in) :: all_procs
86 real(wp),
dimension(1) :: eshift
87 real(wp),
allocatable,
target :: hmt(:,:), eig(:)
88 integer :: matrix_unit
89 integer :: matrix_size, error, ido, jdo
90 integer :: num_matrix_elements_per_record, num_elems
92 character(len=4),
dimension(30) :: NAMP
93 integer,
dimension(10) :: NHD
94 integer,
dimension(20) :: KEYCSF, NHE
95 real(kind=wp),
dimension(41) :: dtnuc
99 write (stdout,
"('Diagonalization done with LAPACK')")
100 write (stdout,
"('Parameters:')")
101 write (stdout,
"('N: ',i8)") matrix_elements % get_matrix_size()
102 write (stdout,
"('Requested # of eigenpairs',i8)") num_eigenpair
104 allocate(eig(matrix_elements % get_matrix_size()))
107 if (myrank == master)
then
109 matrix_unit = matrix_elements % get_matrix_unit()
114 read (matrix_unit) matrix_size, num_matrix_elements_per_record, nhd, namp, nhe, dtnuc
116 num_elems = matrix_elements % get_size()
118 allocate(hmt(matrix_size,matrix_size))
120 call hmat(hmt, 1, 1, eshift, 0, matrix_size, stdout, matrix_unit, num_matrix_elements_per_record, eone)
121 call qldiag(matrix_size, hmt, eig)
124 call dresult % export_header(option, integrals)
126 call dresult % write_header(option, integrals)
127 call dresult % handle_eigenvalues(eig(1:num_eigenpair), matrix_elements % diagonal, num_eigenpair, matrix_size)
129 do ido = 1, num_eigenpair
130 call dresult % handle_eigenvector(hmt(:,ido), matrix_size)
134 call mpi_mod_barrier(error)
138 write (stdout,
'(/," Only the continuum part of the eigenvectors will be saved to disk.")')
139 write (stdout,
'(" Index of the last continuum configuration: ",i10)') dresult % continuum_dimen
143 if (myrank /= master)
then
144 matrix_size = matrix_elements%get_matrix_size()
145 allocate(hmt(matrix_size,matrix_size))
148 call mpi_mod_barrier(error)
149 call mpi_mod_bcast(eig, master)
151 if (myrank /= master)
then
152 call dresult % handle_eigenvalues(eig(1:num_eigenpair), matrix_elements % diagonal, num_eigenpair, matrix_size)
155 do ido = 1, num_eigenpair
156 call mpi_mod_bcast(hmt(1:matrix_size,ido), master)
157 if (myrank /= master)
call dresult % handle_eigenvector(hmt(1:matrix_size,ido), matrix_size)
163 if (
allocated(dresult % ci_vec % CV))
deallocate(dresult % ci_vec % CV)
164 call move_alloc(hmt, dresult % ci_vec % CV)
165 dresult % ci_vec % CV_is_scalapack = .false.
168 call dresult % export_eigenvalues(eig(1:num_eigenpair), matrix_elements % diagonal, &
169 num_eigenpair, matrix_size, dresult % ci_vec % ei, dresult % ci_vec % iphz)
171 write (stdout,
'(/," Eigensolutions exported into the CIVect structure.",/)')
181 class(
basematrix),
intent(in) :: matrix_elements
182 integer,
intent(in) :: num_eigenpair
183 real(wp),
intent(inout) :: eigen(:)
184 real(wp),
intent(inout) :: vecs(:,:)
185 logical,
intent(in) :: all_procs
188 real(wp),
pointer :: pointer_mat(:,:)
189 real(wp),
allocatable,
target :: matrix(:)
190 real(wp),
allocatable :: t_eigen(:), work(:)
191 integer(blasint),
allocatable :: iwork(:)
192 integer(blasint) :: matrix_size, nelems, lwork, liwork
193 integer :: num_elements, ido, jdo, i, j, ierror, info
197 matrix_size = matrix_elements % get_matrix_size()
200 write (stdout,
"('Diagonalization done with LAPACK')")
201 write (stdout,
"('Parameters:')")
202 write (stdout,
"('N: ',i8)") matrix_size
203 write (stdout,
"('Requested # of eigenpairs',i8)") num_eigenpair
204 write (stdout,
"('Number of matrix elements',i8)") matrix_elements % get_size()
206 nelems = int(matrix_size, longint) * int(matrix_size, longint)
209 stop
"Serial diagonalizer used in MPI, use SCALAPACK instead"
213 allocate(matrix(nelems), stat = ierror)
214 pointer_mat(1:matrix_size,1:matrix_size) => matrix
216 if (ierror /= 0)
then
217 stop
"LapackDiagonalizer --matrix-- Out of memory"
220 allocate(t_eigen(matrix_size), stat = ierror)
222 if (ierror /= 0)
then
223 stop
"LapackDiagonalizer --eigen_-- Out of memory"
226 num_elements = matrix_elements % get_size()
232 do ido = 1, num_elements
233 call matrix_elements % get_matrix_element(ido, i, j, coeff)
234 pointer_mat(i,j) = pointer_mat(i,j) + coeff
242 allocate(work(1), iwork(1))
244 write (stdout,
"('Diagonalizing......')", advance =
'no')
246 call dsyevd(
'V',
'L', matrix_size, matrix, matrix_size, t_eigen, work, lwork,iwork, liwork, info)
249 write (stdout,
"(' dsyev returned ',i8)") info
250 stop
'lapack_dsyev - dsyev failed'
254 liwork = int(iwork(1))
256 deallocate(work, iwork)
257 allocate(work(lwork), iwork(liwork))
259 call dsyevd(
'V',
'L', matrix_size, matrix, matrix_size, t_eigen, work, lwork, iwork, liwork, info)
262 write (stdout,
"(' dsyev returned ',i8)") info
263 stop
'lapack_dsyev - dsyev failed'
266 write (stdout,
"('done!')")
268 eigen(1:num_eigenpair) = t_eigen(1:num_eigenpair)
270 do ido = 1, num_eigenpair
271 do jdo = 1, matrix_size
272 vecs(jdo,ido)=pointer_mat(jdo,ido)