MPI-SCATCI  2.0
An MPI version of SCATCI
DavidsonDiagonalizer_module.f90
Go to the documentation of this file.
1 ! Copyright 2019
2 !
3 ! For a comprehensive list of the developers that contributed to these codes
4 ! see the UK-AMOR website.
5 !
6 ! This file is part of UKRmol-in (UKRmol+ suite).
7 !
8 ! UKRmol-in is free software: you can redistribute it and/or modify
9 ! it under the terms of the GNU General Public License as published by
10 ! the Free Software Foundation, either version 3 of the License, or
11 ! (at your option) any later version.
12 !
13 ! UKRmol-in is distributed in the hope that it will be useful,
14 ! but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ! GNU General Public License for more details.
17 !
18 ! You should have received a copy of the GNU General Public License
19 ! along with UKRmol-in (in source/COPYING). Alternatively, you can also visit
20 ! <https://www.gnu.org/licenses/>.
21 
31 
32  use precisn, only: wp
33  use const_gbl, only: stdout
35  use basematrix_module, only: basematrix
39  use options_module, only: options
40  use mpi_gbl, only: master, myrank, mpi_mod_bcast, mpi_xermsg
42 
43  implicit none
44 
46  contains
47  procedure, public :: diagonalize => diagonalize_davidson
48  procedure, private :: diagonalize_writermatrix
49  end type davidsondiagonalizer
50 
51 contains
52 
53  subroutine diagonalize_davidson(this, matrix_elements, num_eigenpair, dresult, all_procs, option, integrals)
54  class(davidsondiagonalizer) :: this
55  class(diagonalizerresult) :: dresult
56  class(basematrix), intent(in) :: matrix_elements
57  class(baseintegral), intent(in) :: integrals
58  type(options), intent(in) :: option
59  integer, intent(in) :: num_eigenpair
60  logical, intent(in) :: all_procs
61 
62  integer :: max_iterations
63  real(wp) :: max_tolerance
64 
65  !Only the first rank can do it
66  if (myrank /= master) return
67 
68  if (iand(dresult % vector_storage, pass_to_cdenprop) /= 0) then
69  call mpi_xermsg('DavidsonDiagonalizer_module', 'diagonalize_davidson', &
70  'PASS_TO_CDENPROP not implemented for Davidson', 1, 1)
71  end if
72 
73  max_iterations = option % max_iterations
74  max_tolerance = option % max_tolerance
75 
76  if (max_iterations < 0) then
77  max_iterations = max(num_eigenpair * 40, 500)
78  end if
79 
80  print *, 'max_iterations', max_iterations
81  print *, 'max_tolerance', max_tolerance
82 
83  select type(matrix_elements)
84  type is (writermatrix)
85  call this % diagonalize_writermatrix(matrix_elements, num_eigenpair, dresult, all_procs, &
86  max_iterations, max_tolerance, option, integrals)
87  class is (basematrix)
88  call mpi_xermsg('DavidsonDiagonalizer_module', 'diagonalize_davidson', &
89  'Only WriterMatrix format can use Davidson', 1, 1)
90  end select
91 
92  end subroutine diagonalize_davidson
93 
94 
95  subroutine diagonalize_writermatrix (this, matrix_elements, num_eigenpair, dresult, all_procs, max_iterations, max_tolerance, &
96  option, integrals)
97  class(davidsondiagonalizer) :: this
98  class(diagonalizerresult) :: dresult
99  type(writermatrix), intent(in) :: matrix_elements
100  class(baseintegral), intent(in) :: integrals
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
106 
107  !for now these are default but will be included i the input
108 
109  real(wp) :: CRITC = 1e-10_wp
110  real(wp) :: CRITR = 1e-8_wp
111  real(wp) :: ORTHO = 1e-7_wp
112 
113  integer :: matrix_unit
114  integer :: matrix_size
115  integer :: num_matrix_elements_per_record, num_elems
116 
117  real(wp), allocatable :: hamiltonian(:), diagonal(:), eig(:)
118  real(wp), pointer :: vec_ptr(:)
119 
120  integer :: mpi_num_eig, mpi_num_vecs, ido, ierr
121 
122  real(wp), allocatable :: eigen(:)
123  real(wp), allocatable :: vecs(:,:)
124 
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
129 
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
134 
135  allocate(eigen(num_eigenpair), vecs(matrix_elements % get_matrix_size(), num_eigenpair))
136 
137  eigen = 0
138  vecs = 0
139  matrix_size = 0
140 
141  if (myrank == master) then
142  !Get our matrix unit
143  matrix_unit = matrix_elements % get_matrix_unit()
144 
145  !Lets follow scatcis example even though we can get these information from the matrix class itself
146  rewind matrix_unit
147  read (matrix_unit) matrix_size, num_matrix_elements_per_record, nhd, namp, nhe, dtnuc
148 
149  num_elems = matrix_elements % get_size()
150  print *, 'matrix_size', matrix_size
151  print *, 'num_elems', num_elems
152 
153  ! allocate(hamiltonian(matrix_size*num_eigenpair),diagonal(matrix_size),eig(matrix_size))
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)
158 
159  if (ierr /= 0) then
160  call mpi_xermsg('DavidsonDiagonalizer_module', 'DavidsonDiagonalizer', &
161  'Davidson diagonalization failed', ierr, 1)
162  end if
163  end if
164 
165  if (all_procs) then
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)
172  end do
173  end if
174 
175  if (iand(option % vector_storage_method, pass_to_cdenprop) /= 0) then
176  call dresult % export_header(option, integrals)
177  end if
178  call dresult % write_header(option, integrals)
179  call dresult % handle_eigenvalues(eigen, matrix_elements % diagonal, num_eigenpair, matrix_size)
180 
181  do ido = 1, num_eigenpair
182  call dresult % handle_eigenvector(vecs(:,ido), matrix_size)
183  end do
184 
185  deallocate(eigen, vecs)
186 
187  end subroutine diagonalize_writermatrix
188 
davidsondiagonalizer_module::davidsondiagonalizer
Definition: DavidsonDiagonalizer_module.f90:45
writermatrix_module
Write matrix module.
Definition: WriterMatrix_module.f90:31
diagonalizerresult_module::diagonalizerresult
Output from diagonalization.
Definition: DiagonalizerResult_module.f90:48
davidsondiagonalizer_module
Diagonalizer type using Davidson backend.
Definition: DavidsonDiagonalizer_module.f90:30
options_module::options
Calculation setup for a single Hamiltonian diagonalization.
Definition: Options_module.f90:74
writermatrix_module::writermatrix
Matrix associated with a disk drive.
Definition: WriterMatrix_module.f90:56
davidsondiagonalizer_module::diagonalize_writermatrix
subroutine diagonalize_writermatrix(this, matrix_elements, num_eigenpair, dresult, all_procs, max_iterations, max_tolerance, option, integrals)
Definition: DavidsonDiagonalizer_module.f90:97
basematrix_module
Base matrix module.
Definition: BaseMatrix_module.f90:28
consts_mpi_ci
MPI SCATCI Constants module.
Definition: consts_mpi_ci.f90:31
basematrix_module::basematrix
Base matrix type.
Definition: BaseMatrix_module.f90:47
baseintegral_module
Base integral module.
Definition: BaseIntegral_module.f90:28
diagonalizerresult_module
Diagonalizer result data object.
Definition: DiagonalizerResult_module.f90:28
diagonalizer_module
Base type for all diagonalizers.
Definition: Diagonalizer_module.f90:30
diagonalizer_module::basediagonalizer
Definition: Diagonalizer_module.f90:34
baseintegral_module::baseintegral
Definition: BaseIntegral_module.f90:41
options_module
Options module.
Definition: Options_module.f90:41
davidsondiagonalizer_module::diagonalize_davidson
subroutine diagonalize_davidson(this, matrix_elements, num_eigenpair, dresult, all_procs, option, integrals)
Definition: DavidsonDiagonalizer_module.f90:54
consts_mpi_ci::pass_to_cdenprop
integer, parameter pass_to_cdenprop
Eigenpairs will be saved in memory and passed to CDENPROP and outer interface.
Definition: consts_mpi_ci.f90:110