63 INTEGER,
INTENT(in),
OPTIONAL :: n
64 INTEGER,
INTENT(out),
OPTIONAL :: info_out
66 CHARACTER(len=*),
PARAMETER :: routinen =
'cp_fm_cholesky_decompose'
68 INTEGER :: handle, info, my_n
69 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: a
70#if defined(__parallel)
71 INTEGER,
DIMENSION(9) :: desca
74 CALL timeset(routinen, handle)
76 my_n = min(matrix%matrix_struct%nrow_global, &
77 matrix%matrix_struct%ncol_global)
83 a => matrix%local_data
85#if defined(__parallel)
86 desca(:) = matrix%matrix_struct%descriptor(:)
98 CALL pdpotrf(
'U', my_n, a(1, 1), 1, 1, desca, info)
103 CALL dpotrf(
'U', my_n, a(1, 1),
SIZE(a, 1), info)
106 IF (
PRESENT(info_out))
THEN
108 ELSE IF (info /= 0)
THEN
109 CALL cp_abort(__location__, &
110 "Cholesky decompose failed: the matrix is not positive definite or ill-conditioned.")
113 CALL timestop(handle)
129 INTEGER,
INTENT(IN),
OPTIONAL :: n
130 INTEGER,
INTENT(OUT),
OPTIONAL :: info_out
132 CHARACTER(len=*),
PARAMETER :: routinen =
'cp_fm_cholesky_solve'
134 INTEGER :: handle, info, my_n, nrhs
135 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: a, b
136#if defined(__parallel)
137 INTEGER,
DIMENSION(9) :: desca, descb
140 CALL timeset(routinen, handle)
142 my_n = min(matrix%matrix_struct%nrow_global, &
143 matrix%matrix_struct%ncol_global)
148 nrhs = matrixb%matrix_struct%ncol_global
150 a => matrix%local_data
151 b => matrixb%local_data
153#if defined(__parallel)
154 desca(:) = matrix%matrix_struct%descriptor(:)
155 descb(:) = matrixb%matrix_struct%descriptor(:)
156 CALL pdpotrs(
'U', my_n, nrhs, a(1, 1), 1, 1, desca, b(1, 1), 1, 1, descb, info)
158 CALL dpotrs(
'U', my_n, nrhs, a(1, 1),
SIZE(a, 1), b(1, 1),
SIZE(b, 1), info)
161 IF (
PRESENT(info_out))
THEN
163 ELSE IF (info /= 0)
THEN
164 CALL cp_abort(__location__, &
165 "Cholesky solve failed: "// &
166 "the matrix is not positive definite or ill-conditioned, info="//
cp_to_string(info))
169 CALL timestop(handle)
186 INTEGER,
INTENT(in),
OPTIONAL :: n
187 INTEGER,
INTENT(OUT),
OPTIONAL :: info_out
188 TYPE(
cp_fm_type),
INTENT(IN),
OPTIONAL :: work
190 CHARACTER(len=*),
PARAMETER :: routinen =
'cp_fm_cholesky_invert'
191 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: a
192 INTEGER :: info, handle, my_n
193#if defined(__parallel)
194 INTEGER,
DIMENSION(9) :: desca
197 CALL timeset(routinen, handle)
199 my_n = min(matrix%matrix_struct%nrow_global, &
200 matrix%matrix_struct%ncol_global)
206 a => matrix%local_data
208#if defined(__parallel)
210 desca(:) = matrix%matrix_struct%descriptor(:)
223 CALL pdpotri(
'U', my_n, a(1, 1), 1, 1, desca, info)
230 CALL dpotri(
'U', my_n, a(1, 1),
SIZE(a, 1), info)
234 IF (
PRESENT(info_out))
THEN
238 cpabort(
"Cholesky invert failed: the matrix is not positive definite or ill-conditioned.")
243 CALL timestop(handle)
261 TYPE(
cp_fm_type),
INTENT(IN) :: matrix, matrixb
262 INTEGER,
OPTIONAL :: itype
264 CHARACTER(len=*),
PARAMETER :: routinen =
'cp_fm_cholesky_reduce'
265 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: a, b
266 INTEGER :: info, handle
267 INTEGER :: n, my_itype
268#if defined(__parallel)
269 REAL(kind=
dp) :: scale
270 INTEGER,
DIMENSION(9) :: desca, descb
273 CALL timeset(routinen, handle)
275 n = matrix%matrix_struct%nrow_global
278 IF (
PRESENT(itype)) my_itype = itype
280 a => matrix%local_data
281 b => matrixb%local_data
283#if defined(__parallel)
285 desca(:) = matrix%matrix_struct%descriptor(:)
286 descb(:) = matrixb%matrix_struct%descriptor(:)
288 CALL pdsygst(my_itype,
'U', n, a(1, 1), 1, 1, desca, b(1, 1), 1, 1, descb, scale, info)
292 IF (scale /= 1.0_dp) &
293 cpabort(
"scale not equal 1 (scale="//
cp_to_string(scale)//
")")
296 CALL dsygst(my_itype,
'U', n, a(1, 1), n, b(1, 1), n, info)
302 CALL timestop(handle)
319 TYPE(
cp_fm_type),
INTENT(IN) :: fm_matrix, fm_matrixb, fm_matrixout
320 INTEGER,
INTENT(IN) :: neig
321 CHARACTER(LEN=*),
INTENT(IN) :: op
322 CHARACTER(LEN=*),
INTENT(IN),
OPTIONAL :: pos
323 CHARACTER(LEN=*),
INTENT(IN),
OPTIONAL :: transa
325 CHARACTER(len=*),
PARAMETER :: routinen =
'cp_fm_cholesky_restore'
326 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: a, b, outm
327 REAL(kind=
dp) :: alpha
328 INTEGER :: handle, mdim, n
329 CHARACTER :: chol_pos, chol_transa
330#if defined(__parallel)
332 INTEGER,
DIMENSION(9) :: desca, descb, descout
333#elif defined(__MKL) && (2025 <= __INTEL_MKL__)
334 REAL(kind=
dp) :: beta
337 CALL timeset(routinen, handle)
340 cpassert((op ==
"SOLVE") .OR. (op ==
"MULTIPLY"))
343 IF (
PRESENT(pos)) chol_pos = pos(1:1)
344 cpassert((chol_pos ==
'L') .OR. (chol_pos ==
'R'))
347 IF (
PRESENT(transa)) chol_transa = transa
350 a => fm_matrix%local_data
351 b => fm_matrixb%local_data
352 outm => fm_matrixout%local_data
353 n = fm_matrix%matrix_struct%nrow_global
354 mdim = merge(1, 2,
'L' == chol_pos)
357#if defined(__parallel)
358 desca(:) = fm_matrix%matrix_struct%descriptor(:)
359 descb(:) = fm_matrixb%matrix_struct%descriptor(:)
360 descout(:) = fm_matrixout%matrix_struct%descriptor(:)
362 CALL pdcopy(n, a(1, 1), 1, i, desca, 1, outm(1, 1), 1, i, descout, 1)
364 IF (op ==
"SOLVE")
THEN
365 CALL pdtrsm(chol_pos,
'U', chol_transa,
'N', n, neig, alpha, b(1, 1), 1, 1, descb, outm(1, 1), 1, 1, descout)
367 CALL pdtrmm(chol_pos,
'U', chol_transa,
'N', n, neig, alpha, b(1, 1), 1, 1, descb, outm(1, 1), 1, 1, descout)
369#elif defined(__MKL) && (2025 <= __INTEL_MKL__)
371 IF (op ==
"SOLVE")
THEN
372 CALL dtrsm_oop(chol_pos,
'U', chol_transa,
'N', n, neig, alpha, b(1, 1),
SIZE(b, mdim), a(1, 1), n, beta, outm(1, 1), n)
374 CALL dtrmm_oop(chol_pos,
'U', chol_transa,
'N', n, neig, alpha, b(1, 1),
SIZE(b, mdim), a(1, 1), n, beta, outm(1, 1), n)
377 CALL dcopy(neig*n, a(1, 1), 1, outm(1, 1), 1)
378 IF (op ==
"SOLVE")
THEN
379 CALL dtrsm(chol_pos,
'U', chol_transa,
'N', n, neig, alpha, b(1, 1),
SIZE(b, mdim), outm(1, 1), n)
381 CALL dtrmm(chol_pos,
'U', chol_transa,
'N', n, neig, alpha, b(1, 1),
SIZE(b, mdim), outm(1, 1), n)
385 CALL timestop(handle)