MPI-SCATCI 2.0
An MPI version of SCATCI
Loading...
Searching...
No Matches
ARPACKDiagonalizer_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
22!> \brief Diagonalizer type using Arpack backend
23!> \authors A Al-Refaie
24!> \date 2017
25!>
26!> Requires Arpack routine \c mkarp. This module is only included in the build if ARPACK_LIBRARIES are
27!> given on the CMake command line.
28!>
29!> \note 16/01/2019 - Jakub Benda: Unifom coding style and expanded documentation.
30!>
31module arpackdiagonalizer_module
32
33 use precisn, only: longint, wp
34 use const_gbl, only: stdout
35 use basematrix_module, only: basematrix
36 use baseintegral_module, only: baseintegral
37 use writermatrix_module, only: writermatrix
38 use diagonalizer_module, only: basediagonalizer
39 use diagonalizerresult_module, only: diagonalizerresult
40 use options_module, only: options
41 use mpi_gbl, only: myrank, master, mpi_xermsg
42 use m_4_mkarp, only: mkarp, default_arpack_max_iter
44
45 implicit none
46
47 type, extends(basediagonalizer) :: arpackdiagonalizer
48 contains
49 procedure, public :: diagonalize => diagonalize_arpack
50 procedure, private :: diagonalize_writermatrix
51 end type arpackdiagonalizer
52
53contains
54
55 subroutine diagonalize_arpack (this, matrix_elements, num_eigenpair, dresult, all_procs, option, integrals)
56 class(arpackdiagonalizer) :: this
57 class(diagonalizerresult) :: dresult
58 class(basematrix), intent(in) :: matrix_elements
59 class(baseintegral), intent(in) :: integrals
60 type(options), intent(in) :: option
61 integer, intent(in) :: num_eigenpair
62 logical, intent(in) :: all_procs
63
64 integer :: max_iterations
65 real(wp) :: max_tolerance
66
67 !Only the first rank can do it
68 if (myrank /= master) return
69
70 max_iterations = option % max_iterations
71 max_tolerance = option % max_tolerance
72
73 if (max_iterations < 0) then
74 max_iterations = max(num_eigenpair * 50, default_arpack_max_iter)
75 end if
76
77 select type(matrix_elements)
78 type is (writermatrix)
79 call this % diagonalize_writermatrix(matrix_elements, num_eigenpair, dresult, max_iterations, max_tolerance, &
80 option, integrals)
81 class is (basematrix)
82 call mpi_xermsg('ARPACKDiagonalizer_module', 'diagonalize_ARPACK', &
83 'Only WriterMatrix format can use Arpack', 1, 1)
84 end select
85
86 end subroutine diagonalize_arpack
87
88
89 subroutine diagonalize_writermatrix (this, matrix_elements, num_eigenpair, dresult, max_iterations, max_tolerance, &
90 option, integrals)
91 class(arpackdiagonalizer) :: this
92 class(diagonalizerresult) :: dresult
93 type(writermatrix), intent(in) :: matrix_elements
94 class(baseintegral), intent(in) :: integrals
95 type(options), intent(in) :: option
96 integer, intent(in) :: num_eigenpair
97 integer, intent(in) :: max_iterations
98 real(wp), intent(in) :: max_tolerance
99
100 !for now these are default but will be included i the input
101
102 integer :: matrix_unit
103 integer :: matrix_size
104 integer :: i1, i2
105
106 integer :: arpack_numeig
107 integer :: arpack_maxit
108 real(wp) :: arpack_maxtol
109 integer :: num_matrix_elements_per_record, num_elems
110
111 real(wp), allocatable :: eigenvalues(:), eigenvector(:)
112
113 write (stdout, "('Diagonalization done with ARPACK')")
114 write (stdout, "('Parameters:')")
115 write (stdout, "('N: ',i8)") matrix_elements % get_matrix_size()
116 write (stdout, "('Requested # of eigenpairs',i8)") num_eigenpair
117
118 arpack_numeig = num_eigenpair
119 arpack_maxit = max_iterations
120 arpack_maxtol = max_tolerance
121 matrix_size = matrix_elements % get_matrix_size()
122 num_elems = matrix_elements % get_size()
123 matrix_unit = matrix_elements % get_matrix_unit()
124
125 allocate(eigenvalues(num_eigenpair), eigenvector(matrix_size))
126
127 call mkarp(matrix_size, arpack_numeig, arpack_maxit, arpack_maxtol, matrix_unit)
128
129 ! 3. Opening the produced file "eigensystem_arpack_file.bin" file.
130 ! This file contains the produced eigenpairs and it is
131 ! written to the hard disk.
132
133 open (unit = 11, file = "___tmp_eigensys", status = "old", action = "read", form = "unformatted")
134
135 ! 4. Reading the eigenvalues.
136
137 do i1 = 1, num_eigenpair
138 read (unit = 11) eigenvalues(i1)
139 end do
140
141 if (iand(option % vector_storage_method, pass_to_cdenprop) /= 0) then
142 call dresult % export_header(option, integrals)
143 if (allocated(dresult % ci_vec % CV)) deallocate(dresult % ci_vec % CV)
144 allocate (dresult % ci_vec % CV(matrix_size, num_eigenpair))
145 dresult % ci_vec % CV_is_scalapack = .false.
146 end if
147 call dresult % write_header(option, integrals)
148 call dresult % handle_eigenvalues(eigenvalues, matrix_elements % diagonal, num_eigenpair, matrix_size)
149
150 ! 5. Reading the eigenvectors.
151
152 do i1 = 1, num_eigenpair
153 do i2 = 1, matrix_size
154 read (unit = 11) eigenvector(i2)
155 end do
156 call dresult % handle_eigenvector(eigenvector, matrix_size)
157 if (iand(option % vector_storage_method, pass_to_cdenprop) /= 0) then
158 dresult % ci_vec % CV(1:matrix_size, i1) = eigenvector(1:matrix_size)
159 end if
160 eigenvector = 0
161 end do
162
163 ! 6. Closing the unit and deleting the file
164 ! "___tmp_eigensys".
165
166 close (unit = 11, status = "delete")
167
168 if (iand(option % vector_storage_method, pass_to_cdenprop) /= 0) then
169 call dresult % export_eigenvalues(eigenvalues(1:num_eigenpair), matrix_elements % diagonal, &
170 num_eigenpair, matrix_size, dresult % ci_vec % ei, dresult % ci_vec % iphz)
171 write (stdout, '(/," Eigensolutions exported into the CIVect structure.",/)')
172 end if
173
174 deallocate(eigenvalues, eigenvector)
175
176 end subroutine diagonalize_writermatrix
177
178end module arpackdiagonalizer_module
MPI SCATCI Constants module.
integer, parameter diagonalize
Diagonalize.
integer, parameter pass_to_cdenprop
Eigenpairs will be saved in memory and passed to CDENPROP and outer interface.