26 #if defined (__HAS_IEEE_EXCEPTIONS)
27 USE ieee_exceptions,
ONLY: ieee_get_halting_mode, &
28 ieee_set_halting_mode, &
32 #include "../base/base_uses.f90"
36 CHARACTER(len=*),
PARAMETER,
PRIVATE :: moduleN =
'cp_cfm_diag'
53 TYPE(cp_cfm_type),
INTENT(IN) :: matrix, eigenvectors
54 REAL(kind=
dp),
DIMENSION(:),
INTENT(OUT) :: eigenvalues
56 CHARACTER(len=*),
PARAMETER :: routinen =
'cp_cfm_heevd'
58 COMPLEX(KIND=dp),
DIMENSION(:),
POINTER :: work
59 COMPLEX(KIND=dp),
DIMENSION(:, :), &
61 INTEGER :: handle, info, liwork, &
63 INTEGER,
DIMENSION(:),
POINTER :: iwork
64 REAL(kind=
dp),
DIMENSION(:),
POINTER :: rwork
65 #if defined(__SCALAPACK)
66 INTEGER,
DIMENSION(9) :: descm, descv
67 COMPLEX(KIND=dp),
DIMENSION(:, :), &
69 #if defined (__HAS_IEEE_EXCEPTIONS)
70 LOGICAL,
DIMENSION(5) :: halt
74 CALL timeset(routinen, handle)
76 n = matrix%matrix_struct%nrow_global
77 m => matrix%local_data
78 ALLOCATE (iwork(1), rwork(1), work(1))
84 #if defined(__SCALAPACK)
85 v => eigenvectors%local_data
86 descm(:) = matrix%matrix_struct%descriptor(:)
87 descv(:) = eigenvectors%matrix_struct%descriptor(:)
88 CALL pzheevd(
'V',
'U', n, m(1, 1), 1, 1, descm, eigenvalues(1), v(1, 1), 1, 1, descv, &
89 work(1), lwork, rwork(1), lrwork, iwork(1), liwork, info)
92 lwork = ceiling(real(work(1), kind=
dp)) + 1000
94 lrwork = ceiling(real(rwork(1), kind=
dp)) + 1000000
97 CALL zheevd(
'V',
'U', n, m(1, 1),
SIZE(m, 1), eigenvalues(1), &
98 work(1), lwork, rwork(1), lrwork, iwork(1), liwork, info)
99 lwork = ceiling(real(work(1), kind=
dp))
100 lrwork = ceiling(real(rwork(1), kind=
dp))
104 DEALLOCATE (iwork, rwork, work)
105 ALLOCATE (iwork(liwork), rwork(lrwork), work(lwork))
107 #if defined(__SCALAPACK)
110 #if defined (__HAS_IEEE_EXCEPTIONS)
111 CALL ieee_get_halting_mode(ieee_all, halt)
112 CALL ieee_set_halting_mode(ieee_all, .false.)
115 CALL pzheevd(
'V',
'U', n, m(1, 1), 1, 1, descm, eigenvalues(1), v(1, 1), 1, 1, descv, &
116 work(1), lwork, rwork(1), lrwork, iwork(1), liwork, info)
118 #if defined (__HAS_IEEE_EXCEPTIONS)
119 CALL ieee_set_halting_mode(ieee_all, halt)
122 CALL zheevd(
'V',
'U', n, m(1, 1),
SIZE(m, 1), eigenvalues(1), &
123 work(1), lwork, rwork(1), lrwork, iwork(1), liwork, info)
124 eigenvectors%local_data = matrix%local_data
127 DEALLOCATE (iwork, rwork, work)
129 cpabort(
"Diagonalisation of a complex matrix failed")
131 CALL timestop(handle)
144 SUBROUTINE cp_cfm_geeig(amatrix, bmatrix, eigenvectors, eigenvalues, work)
146 TYPE(cp_cfm_type),
INTENT(IN) :: amatrix, bmatrix, eigenvectors
147 REAL(kind=
dp),
DIMENSION(:) :: eigenvalues
148 TYPE(cp_cfm_type),
INTENT(IN) :: work
150 CHARACTER(len=*),
PARAMETER :: routinen =
'cp_cfm_geeig'
152 INTEGER :: handle, nao, nmo
153 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:) :: evals
155 CALL timeset(routinen, handle)
158 ALLOCATE (evals(nao))
167 CALL cp_cfm_heevd(matrix=amatrix, eigenvectors=work, eigenvalues=evals)
170 nmo =
SIZE(eigenvalues)
171 CALL cp_cfm_to_cfm(work, eigenvectors, nmo)
172 eigenvalues(1:nmo) = evals(1:nmo)
176 CALL timestop(handle)
192 TYPE(cp_cfm_type),
INTENT(IN) :: amatrix, bmatrix, eigenvectors
193 REAL(kind=
dp),
DIMENSION(:) :: eigenvalues
194 TYPE(cp_cfm_type),
INTENT(IN) :: work
195 REAL(kind=
dp),
INTENT(IN) :: epseig
197 CHARACTER(len=*),
PARAMETER :: routinen =
'cp_cfm_geeig_canon'
198 COMPLEX(KIND=dp),
PARAMETER :: cone = cmplx(1.0_dp, 0.0_dp, kind=
dp), &
199 czero = cmplx(0.0_dp, 0.0_dp, kind=
dp)
201 COMPLEX(KIND=dp),
ALLOCATABLE,
DIMENSION(:) :: cevals
202 INTEGER :: handle, i, icol, irow, nao, nc, ncol, &
204 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:) :: evals
206 CALL timeset(routinen, handle)
210 nmo =
SIZE(eigenvalues)
211 ALLOCATE (evals(nao), cevals(nao))
214 CALL cp_cfm_scale(-cone, bmatrix)
219 IF (evals(i) < epseig)
THEN
230 CALL cp_cfm_to_cfm(work, eigenvectors, ncol, nc + 1, nc + 1)
233 DO icol = nc + 1, nao
239 evals(nc + 1:nao) = 1.0_dp
242 cevals(:) = cmplx(1.0_dp/sqrt(evals(:)), 0.0_dp, kind=
dp)
245 CALL cp_cfm_gemm(
"C",
"N", nao, nao, nao, cone, work, amatrix, czero, bmatrix)
246 CALL cp_cfm_gemm(
"N",
"N", nao, nao, nao, cone, bmatrix, work, czero, amatrix)
249 DO icol = nc + 1, nao
255 eigenvalues(1:nmo) = evals(1:nmo)
258 CALL cp_cfm_gemm(
"N",
"N", nao, nx, nc, cone, work, bmatrix, czero, eigenvectors)
262 CALL timestop(handle)
Basic linear algebra operations for complex full matrices.
subroutine, public cp_cfm_gemm(transa, transb, m, n, k, alpha, matrix_a, matrix_b, beta, matrix_c, a_first_col, a_first_row, b_first_col, b_first_row, c_first_col, c_first_row)
Performs one of the matrix-matrix operations: matrix_c = alpha * op1( matrix_a ) * op2( matrix_b ) + ...
subroutine, public cp_cfm_triangular_multiply(triangular_matrix, matrix_b, side, transa_tr, invert_tr, uplo_tr, unit_diag_tr, n_rows, n_cols, alpha)
Multiplies in place by a triangular matrix: matrix_b = alpha op(triangular_matrix) matrix_b or (if si...
subroutine, public cp_cfm_cholesky_decompose(matrix, n, info_out)
Used to replace a symmetric positive definite matrix M with its Cholesky decomposition U: M = U^T * U...
subroutine, public cp_cfm_column_scale(matrix_a, scaling)
Scales columns of the full matrix by corresponding factors.
subroutine, public cp_cfm_triangular_invert(matrix_a, uplo, info_out)
Inverts a triangular matrix.
used for collecting diagonalization schemes available for cp_cfm_type
subroutine, public cp_cfm_geeig(amatrix, bmatrix, eigenvectors, eigenvalues, work)
General Eigenvalue Problem AX = BXE Single option version: Cholesky decomposition of B.
subroutine, public cp_cfm_heevd(matrix, eigenvectors, eigenvalues)
Perform a diagonalisation of a complex matrix.
subroutine, public cp_cfm_geeig_canon(amatrix, bmatrix, eigenvectors, eigenvalues, work, epseig)
General Eigenvalue Problem AX = BXE Use canonical orthogonalization.
Represents a complex full matrix distributed on many processors.
subroutine, public cp_cfm_set_element(matrix, irow_global, icol_global, alpha)
Set the matrix element (irow_global,icol_global) of the full matrix to alpha.
subroutine, public cp_cfm_get_info(matrix, name, nrow_global, ncol_global, nrow_block, ncol_block, nrow_local, ncol_local, row_indices, col_indices, local_data, context, matrix_struct, para_env)
Returns information about a full matrix.
Defines the basic variable types.
integer, parameter, public dp