31#include "./base/base_uses.f90"
36 CHARACTER(len=*),
PARAMETER,
PRIVATE :: moduleN =
'gw_fm_utils'
55 TYPE(
cp_cfm_type),
INTENT(INOUT),
OPTIONAL :: matrix_c
60 cpassert(
ASSOCIATED(matrix_a%matrix_struct))
61 cpassert(
ASSOCIATED(matrix_b%matrix_struct))
63 cpassert(nrow == ncol)
68 IF (
PRESENT(matrix_c))
THEN
69 cpassert(
ASSOCIATED(matrix_c%matrix_struct))
89 SUBROUTINE fm_invert(matrix_A, eigenvalue_threshold, unit_nr)
91 REAL(kind=
dp),
INTENT(IN),
OPTIONAL :: eigenvalue_threshold
92 INTEGER,
INTENT(IN),
OPTIONAL :: unit_nr
94 INTEGER :: info, n_dependent
95 LOGICAL :: cholesky_successful
96 REAL(kind=
dp) :: threshold
100 IF (
PRESENT(eigenvalue_threshold)) threshold = eigenvalue_threshold
106 cholesky_successful = info == 0
108 IF (cholesky_successful)
THEN
113 CALL cp_fm_power(matrix_a, work, -1.0_dp, threshold, n_dependent)
114 IF (
PRESENT(unit_nr))
THEN
115 IF (unit_nr > 0)
THEN
116 WRITE (unit_nr,
'(T2,A)') &
117 'Cholesky decomposition failed; matrix inverted by diagonalization.'
118 WRITE (unit_nr,
'(T2,A,T72,I9)')
'Discarded eigenmodes:', n_dependent
135 SUBROUTINE fm_sqrt(matrix_A, matrix_B, eigenvalue_threshold, unit_nr)
138 REAL(kind=
dp),
INTENT(IN),
OPTIONAL :: eigenvalue_threshold
139 INTEGER,
INTENT(IN),
OPTIONAL :: unit_nr
141 INTEGER :: i_row, info, j_col, n_dependent, &
142 ncol_local, nrow_local
143 INTEGER,
DIMENSION(:),
POINTER :: col_indices, row_indices
144 LOGICAL :: cholesky_successful
145 REAL(kind=
dp) :: threshold
149 IF (
PRESENT(eigenvalue_threshold)) threshold = eigenvalue_threshold
154 cholesky_successful = info == 0
155 IF (cholesky_successful)
THEN
157 CALL cp_fm_get_info(matrix=matrix_b, nrow_local=nrow_local, ncol_local=ncol_local, &
158 row_indices=row_indices, col_indices=col_indices)
159 DO j_col = 1, ncol_local
160 DO i_row = 1, nrow_local
161 IF (row_indices(i_row) > col_indices(j_col))
THEN
162 matrix_b%local_data(i_row, j_col) = 0.0_dp
168 CALL cp_fm_power(matrix_b, work, 0.5_dp, threshold, n_dependent)
169 IF (
PRESENT(unit_nr))
THEN
170 IF (unit_nr > 0)
THEN
171 WRITE (unit_nr,
'(T2,A)') &
172 'Cholesky decomposition failed, using diagonalization.'
173 WRITE (unit_nr,
'(T2,A,T72,I9)')
'Discarded eigenmodes:', n_dependent
190 TYPE(
cp_fm_type),
INTENT(INOUT),
OPTIONAL :: matrix_C
192 INTEGER :: ncol, nrow
195 cpassert(
ASSOCIATED(matrix_a%matrix_struct))
196 cpassert(
ASSOCIATED(matrix_b%matrix_struct))
198 cpassert(nrow == ncol)
201 CALL parallel_gemm(
"N",
"N", nrow, nrow, nrow, 1.0_dp, matrix_b, matrix_a, &
203 IF (
PRESENT(matrix_c))
THEN
204 cpassert(
ASSOCIATED(matrix_c%matrix_struct))
205 CALL parallel_gemm(
"T",
"N", nrow, nrow, nrow, 1.0_dp, matrix_a, work, &
208 CALL parallel_gemm(
"T",
"N", nrow, nrow, nrow, 1.0_dp, matrix_a, work, &
222 SUBROUTINE fm_contract_aba_set(matrix_A, matrix_B, matrix_C)
224 TYPE(
cp_fm_type),
DIMENSION(:),
INTENT(INOUT) :: matrix_B
225 TYPE(
cp_fm_type),
DIMENSION(:),
INTENT(INOUT), &
228 INTEGER :: i, ncol, nrow
231 cpassert(
ASSOCIATED(matrix_a%matrix_struct))
233 cpassert(nrow == ncol)
234 IF (
PRESENT(matrix_c))
THEN
235 cpassert(
SIZE(matrix_c) ==
SIZE(matrix_b))
239 DO i = 1,
SIZE(matrix_b)
240 cpassert(
ASSOCIATED(matrix_b(i)%matrix_struct))
241 CALL parallel_gemm(
"N",
"N", nrow, nrow, nrow, 1.0_dp, matrix_b(i), matrix_a, &
243 IF (
PRESENT(matrix_c))
THEN
244 cpassert(
ASSOCIATED(matrix_c(i)%matrix_struct))
245 CALL parallel_gemm(
"T",
"N", nrow, nrow, nrow, 1.0_dp, matrix_a, work, &
248 CALL parallel_gemm(
"T",
"N", nrow, nrow, nrow, 1.0_dp, matrix_a, work, &
255 END SUBROUTINE fm_contract_aba_set
Represents a complex full matrix distributed on many processors.
subroutine, public cp_cfm_release(matrix)
Releases a full matrix.
subroutine, public cp_cfm_create(matrix, matrix_struct, name, nrow, ncol, set_zero)
Creates a new full matrix with the given structure.
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.
Basic linear algebra operations for full matrices.
subroutine, public cp_fm_uplo_to_full(matrix, work, uplo)
given a triangular matrix according to uplo, computes the corresponding full matrix
various cholesky decomposition related routines
subroutine, public cp_fm_cholesky_invert(matrix, n, info_out)
used to replace the cholesky decomposition by the inverse
subroutine, public cp_fm_cholesky_decompose(matrix, n, info_out)
used to replace a symmetric positive def. matrix M with its cholesky decomposition U: M = U^T * U,...
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 a full matrix distributed on many processors
subroutine, public cp_fm_get_info(matrix, name, nrow_global, ncol_global, nrow_block, ncol_block, nrow_local, ncol_local, row_indices, col_indices, local_data, context, nrow_locals, ncol_locals, matrix_struct, para_env)
returns all kind of information about the full matrix
subroutine, public cp_fm_create(matrix, matrix_struct, name, nrow, ncol, set_zero)
creates a new full matrix with the given structure
Common full-matrix operations used by GW modules.
subroutine, public cfm_contract_aba(matrix_a, matrix_b, matrix_c)
Computes A^H B A for complex full matrices.
subroutine, public fm_sqrt(matrix_a, matrix_b, eigenvalue_threshold, unit_nr)
For input A, computes B such that B^T B=A. First, Cholesky decomposition is tried....
subroutine, public fm_invert(matrix_a, eigenvalue_threshold, unit_nr)
Inverts a symmetric matrix. First, Cholesky decomposition is tried. If it fails, the matrix is diagon...
Defines the basic variable types.
integer, parameter, public dp
Definition of mathematical constants and functions.
complex(kind=dp), parameter, public z_one
complex(kind=dp), parameter, public z_zero
basic linear algebra operations for full matrixes
Represent a complex full matrix.