35#include "./base/base_uses.f90"
43 CHARACTER(len=*),
PARAMETER,
PRIVATE :: moduleN =
'qs_condnum'
65 SUBROUTINE overlap_condnum(matrixkp_s, condnum, iunit, norml1, norml2, use_arnoldi, blacs_env)
67 TYPE(
dbcsr_p_type),
DIMENSION(:, :),
POINTER :: matrixkp_s
68 REAL(kind=
dp),
DIMENSION(2),
INTENT(INOUT) :: condnum
69 INTEGER,
INTENT(IN) :: iunit
70 LOGICAL,
INTENT(IN) :: norml1, norml2, use_arnoldi
73 CHARACTER(len=*),
PARAMETER :: routinen =
'overlap_condnum'
75 INTEGER :: handle, ic, maxiter, nbas, ndep
77 REAL(kind=
dp) :: amnorm, anorm, eps_ev, max_ev, min_ev, &
79 REAL(kind=
dp),
DIMENSION(2) :: eigvals
85 CALL timeset(routinen, handle)
89 IF (
SIZE(matrixkp_s, 2) == 1)
THEN
90 IF (iunit > 0)
WRITE (iunit,
'(/,T2,A)')
"OVERLAP MATRIX CONDITION NUMBER"
91 smat => matrixkp_s(1, 1)%matrix
93 IF (iunit > 0)
WRITE (iunit,
'(/,T2,A)')
"OVERLAP MATRIX CONDITION NUMBER AT GAMMA POINT"
95 CALL dbcsr_create(smat, template=matrixkp_s(1, 1)%matrix)
97 DO ic = 2,
SIZE(matrixkp_s, 2)
98 CALL dbcsr_add(smat, matrixkp_s(1, ic)%matrix, 1.0_dp, 1.0_dp)
102 IF (
ASSOCIATED(smat))
THEN
107 CALL estimate_norm_invmat(smat, amnorm)
109 WRITE (iunit,
'(T2,A)')
"1-Norm Condition Number (Estimate)"
110 WRITE (iunit,
'(T4,A,ES11.3E3,T32,A,ES11.3E3,A4,ES11.3E3,T63,A,F8.4)') &
111 "CN : |A|*|A^-1|: ", anorm,
" * ", amnorm,
"=", anorm*amnorm,
"Log(1-CN):", log10(anorm*amnorm)
113 condnum(1) = anorm*amnorm
120 nrow_global=nbas, ncol_global=nbas)
124 CALL dbcsr_create(tempmat, template=smat, matrix_type=dbcsr_type_no_symmetry)
130 CALL cp_fm_power(fmsmat, fmwork, -1.0_dp, eps_ev, ndep, eigvals=eigvals)
141 WRITE (iunit,
'(T2,A)')
"1-Norm and 2-Norm Condition Numbers using Diagonalization"
143 WRITE (iunit,
'(T4,A,ES11.3E3,T32,A,ES11.3E3,A4,ES11.3E3,T63,A,F8.4)') &
144 "CN : |A|*|A^-1|: ", anorm,
" * ", amnorm,
"=", anorm*amnorm,
"Log(1-CN):", log10(anorm*amnorm)
145 WRITE (iunit,
'(T4,A,ES11.3E3,T32,A,ES11.3E3,A4,ES11.3E3,T63,A,F8.4)') &
146 "CN : max/min ev: ", max_ev,
" / ", min_ev,
"=", max_ev/min_ev,
"Log(2-CN):", log10(max_ev/min_ev)
148 WRITE (iunit,
'(T4,A,ES11.3E3,T32,A,ES11.3E3,T63,A)') &
149 "CN : max/min EV: ", max_ev,
" / ", min_ev,
"Log(CN): infinity"
153 condnum(1) = anorm*amnorm
154 condnum(2) = max_ev/min_ev
156 condnum(1:2) = 0.0_dp
159 IF (use_arnoldi)
THEN
161 threshold = 1.0e-6_dp
165 threshold=threshold, max_iter=maxiter, converged=converged)
167 WRITE (iunit,
'(T2,A)')
"2-Norm Condition Number using Arnoldi iterations"
169 WRITE (iunit,
'(T4,A,ES11.3E3,T32,A,ES11.3E3,A4,ES11.3E3,T63,A,F8.4)') &
170 "CN : max/min ev: ", max_ev,
" / ", min_ev,
"=", max_ev/min_ev,
"Log(2-CN):", log10(max_ev/min_ev)
172 WRITE (iunit,
'(T4,A,ES11.3E3,T32,A,ES11.3E3,T63,A)') &
173 "CN : max/min ev: ", max_ev,
" / ", min_ev,
"Log(CN): infinity"
177 condnum(2) = max_ev/min_ev
182 IF (min_ev == 0)
THEN
183 cpwarn(
"Ill-conditioned S matrix: basis set is overcomplete.")
184 ELSE IF ((max_ev/min_ev) > eps_ev)
THEN
185 cpwarn(
"Ill-conditioned S matrix: basis set is overcomplete.")
188 cpwarn(
"Condition number estimate of overlap matrix is not reliable (not converged).")
192 IF (
SIZE(matrixkp_s, 2) == 1)
THEN
199 CALL timestop(handle)
214 SUBROUTINE estimate_norm_invmat(amat, anorm)
216 REAL(kind=
dp),
INTENT(OUT) :: anorm
218 INTEGER :: i, k, nbas
219 INTEGER,
DIMENSION(1) :: r
220 REAL(kind=
dp) :: g, gg
221 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:) :: x, xsi
222 REAL(kind=
dp),
DIMENSION(2) :: work
223 REAL(kind=
dp),
EXTERNAL :: dlange
227 CALL dbcsr_create(pmat, name=
"SMAT Preconditioner", template=amat)
231 CALL smat_precon_diag(pmat)
235 ALLOCATE (x(nbas), xsi(nbas))
236 x(1:nbas) = 1._dp/real(nbas, kind=
dp)
237 CALL dbcsr_solve(amat, x, pmat)
238 g = dlange(
"1", nbas, 1, x, nbas, work)
239 xsi(1:nbas) = sign(1._dp, x(1:nbas))
240 x(1:nbas) = xsi(1:nbas)
241 CALL dbcsr_solve(amat, x, pmat)
247 CALL dbcsr_solve(amat, x, pmat)
249 g = dlange(
"1", nbas, 1, x, nbas, work)
251 x(1:nbas) = sign(1._dp, x(1:nbas))
252 IF (sum(abs(x - xsi)) == 0 .OR. sum(abs(x + xsi)) == 0)
EXIT
253 xsi(1:nbas) = x(1:nbas)
254 CALL dbcsr_solve(amat, x, pmat)
257 IF (sum(r) == sum(maxloc(abs(x))))
EXIT
262 x(i) = -1._dp**(i + 1)*(1._dp + real(i - 1,
dp)/real(nbas - 1,
dp))
267 CALL dbcsr_solve(amat, x, pmat)
268 gg = dlange(
"1", nbas, 1, x, nbas, work)
269 gg = 2._dp*gg/real(3*nbas,
dp)
274 END SUBROUTINE estimate_norm_invmat
282 SUBROUTINE dbcsr_solve(amat, x, pmat)
284 REAL(kind=
dp),
DIMENSION(:),
INTENT(INOUT) :: x
287 INTEGER :: max_iter, nbas
289 REAL(kind=
dp) :: threshold
292 max_iter = min(1000, nbas)
296 END SUBROUTINE dbcsr_solve
302 SUBROUTINE smat_precon_diag(pmat)
305 INTEGER :: iatom, info, jatom, n
306 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: sblock
312 cpassert(iatom == jatom)
314 CALL invmat(sblock(1:n, 1:n), info)
319 END SUBROUTINE smat_precon_diag
arnoldi iteration using dbcsr
subroutine, public arnoldi_extremal(matrix_a, max_ev, min_ev, converged, threshold, max_iter)
simple wrapper to estimate extremal eigenvalues with arnoldi, using the old lanczos interface this hi...
subroutine, public arnoldi_conjugate_gradient(matrix_a, vec_x, matrix_p, converged, threshold, max_iter)
Wrapper for conjugated gradient algorithm for Ax=b.
methods related to the blacs parallel environment
subroutine, public dbcsr_iterator_next_block(iterator, row, column, block, block_number_argument_has_been_removed, row_size, col_size, row_offset, col_offset)
...
character function, public dbcsr_get_matrix_type(matrix)
...
logical function, public dbcsr_iterator_blocks_left(iterator)
...
subroutine, public dbcsr_iterator_stop(iterator)
...
subroutine, public dbcsr_desymmetrize(matrix_a, matrix_b)
...
subroutine, public dbcsr_copy(matrix_b, matrix_a, name, keep_sparsity, keep_imaginary)
...
subroutine, public dbcsr_get_info(matrix, nblkrows_total, nblkcols_total, nfullrows_total, nfullcols_total, nblkrows_local, nblkcols_local, nfullrows_local, nfullcols_local, my_prow, my_pcol, local_rows, local_cols, proc_row_dist, proc_col_dist, row_blk_size, col_blk_size, row_blk_offset, col_blk_offset, distribution, name, matrix_type, group)
...
subroutine, public dbcsr_iterator_start(iterator, matrix, shared, dynamic, dynamic_byrows)
...
subroutine, public dbcsr_release(matrix)
...
subroutine, public dbcsr_add(matrix_a, matrix_b, alpha_scalar, beta_scalar)
...
real(dp) function, public dbcsr_gershgorin_norm(matrix)
Compute the gershgorin norm of a dbcsr matrix.
subroutine, public dbcsr_get_block_diag(matrix, diag)
Copies the diagonal blocks of matrix into diag.
DBCSR operations in CP2K.
subroutine, public copy_dbcsr_to_fm(matrix, fm)
Copy a DBCSR matrix to a BLACS matrix.
basic linear algebra operations for full matrices
real(kind=dp) function, public cp_fm_norm(matrix, mode)
norm of matrix using (p)dlange
used for collecting some of the diagonalization schemes available for cp_fm_type. cp_fm_power also mo...
subroutine, public cp_fm_power(matrix, work, exponent, threshold, n_dependent, verbose, eigvals)
...
represent the structure of a full matrix
subroutine, public cp_fm_struct_create(fmstruct, para_env, context, nrow_global, ncol_global, nrow_block, ncol_block, descriptor, first_p_pos, local_leading_dimension, template_fmstruct, square_blocks, force_block)
allocates and initializes a full matrix structure
subroutine, public cp_fm_struct_release(fmstruct)
releases a full matrix structure
represent a full matrix distributed on many processors
subroutine, public cp_fm_create(matrix, matrix_struct, name, use_sp)
creates a new full matrix with the given structure
Defines the basic variable types.
integer, parameter, public dp
Collection of simple mathematical functions and subroutines.
subroutine, public invmat(a, info)
returns inverse of matrix using the lapack routines DGETRF and DGETRI
Calculation of overlap matrix condition numbers.
subroutine, public overlap_condnum(matrixkp_s, condnum, iunit, norml1, norml2, use_arnoldi, blacs_env)
Calculation of the overlap matrix Condition Number.
represent a blacs multidimensional parallel environment (for the mpi corrispective see cp_paratypes/m...
keeps the information about the structure of a full matrix