62 INTEGER,
INTENT(in),
OPTIONAL :: n
63 INTEGER,
INTENT(out),
OPTIONAL :: info_out
65 CHARACTER(len=*),
PARAMETER :: routinen =
'cp_fm_cholesky_decompose'
67 INTEGER :: handle, info, my_n
68 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: a
69#if defined(__parallel)
70 INTEGER,
DIMENSION(9) :: desca
73 CALL timeset(routinen, handle)
75 my_n = min(matrix%matrix_struct%nrow_global, &
76 matrix%matrix_struct%ncol_global)
82 a => matrix%local_data
84#if defined(__parallel)
85 desca(:) = matrix%matrix_struct%descriptor(:)
97 CALL pdpotrf(
'U', my_n, a(1, 1), 1, 1, desca, info)
102 CALL dpotrf(
'U', my_n, a(1, 1),
SIZE(a, 1), info)
105 IF (
PRESENT(info_out))
THEN
107 ELSE IF (info /= 0)
THEN
108 CALL cp_abort(__location__, &
109 "Cholesky decompose failed: the matrix is not positive definite or ill-conditioned.")
112 CALL timestop(handle)
128 INTEGER,
INTENT(IN),
OPTIONAL :: n
129 INTEGER,
INTENT(OUT),
OPTIONAL :: info_out
131 CHARACTER(len=*),
PARAMETER :: routinen =
'cp_fm_cholesky_solve'
133 INTEGER :: handle, info, my_n, nrhs
134 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: a, b
135#if defined(__parallel)
136 INTEGER,
DIMENSION(9) :: desca, descb
139 CALL timeset(routinen, handle)
141 my_n = min(matrix%matrix_struct%nrow_global, &
142 matrix%matrix_struct%ncol_global)
147 nrhs = matrixb%matrix_struct%ncol_global
149 a => matrix%local_data
150 b => matrixb%local_data
152#if defined(__parallel)
153 desca(:) = matrix%matrix_struct%descriptor(:)
154 descb(:) = matrixb%matrix_struct%descriptor(:)
155 CALL pdpotrs(
'U', my_n, nrhs, a(1, 1), 1, 1, desca, b(1, 1), 1, 1, descb, info)
157 CALL dpotrs(
'U', my_n, nrhs, a(1, 1),
SIZE(a, 1), b(1, 1),
SIZE(b, 1), info)
160 IF (
PRESENT(info_out))
THEN
162 ELSE IF (info /= 0)
THEN
163 CALL cp_abort(__location__, &
164 "Cholesky solve failed: "// &
165 "the matrix is not positive definite or ill-conditioned, info="//
cp_to_string(info))
168 CALL timestop(handle)
183 INTEGER,
INTENT(in),
OPTIONAL :: n
184 INTEGER,
INTENT(OUT),
OPTIONAL :: info_out
186 CHARACTER(len=*),
PARAMETER :: routinen =
'cp_fm_cholesky_invert'
187 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: a
188 INTEGER :: info, handle, my_n
189#if defined(__parallel)
190 INTEGER,
DIMENSION(9) :: desca
193 CALL timeset(routinen, handle)
195 my_n = min(matrix%matrix_struct%nrow_global, &
196 matrix%matrix_struct%ncol_global)
202 a => matrix%local_data
204#if defined(__parallel)
206 desca(:) = matrix%matrix_struct%descriptor(:)
219 CALL pdpotri(
'U', my_n, a(1, 1), 1, 1, desca, info)
226 CALL dpotri(
'U', my_n, a(1, 1),
SIZE(a, 1), info)
230 IF (
PRESENT(info_out))
THEN
234 cpabort(
"Cholesky invert failed: the matrix is not positive definite or ill-conditioned.")
237 CALL timestop(handle)
255 TYPE(
cp_fm_type),
INTENT(IN) :: matrix, matrixb
256 INTEGER,
OPTIONAL :: itype
258 CHARACTER(len=*),
PARAMETER :: routinen =
'cp_fm_cholesky_reduce'
259 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: a, b
260 INTEGER :: info, handle
261 INTEGER :: n, my_itype
262#if defined(__parallel)
263 REAL(kind=
dp) :: scale
264 INTEGER,
DIMENSION(9) :: desca, descb
267 CALL timeset(routinen, handle)
269 n = matrix%matrix_struct%nrow_global
272 IF (
PRESENT(itype)) my_itype = itype
274 a => matrix%local_data
275 b => matrixb%local_data
277#if defined(__parallel)
279 desca(:) = matrix%matrix_struct%descriptor(:)
280 descb(:) = matrixb%matrix_struct%descriptor(:)
282 CALL pdsygst(my_itype,
'U', n, a(1, 1), 1, 1, desca, b(1, 1), 1, 1, descb, scale, info)
286 IF (scale /= 1.0_dp) &
287 cpabort(
"scale not equal 1 (scale="//
cp_to_string(scale)//
")")
290 CALL dsygst(my_itype,
'U', n, a(1, 1), n, b(1, 1), n, info)
296 CALL timestop(handle)
313 TYPE(
cp_fm_type),
INTENT(IN) :: fm_matrix, fm_matrixb, fm_matrixout
314 INTEGER,
INTENT(IN) :: neig
315 CHARACTER(LEN=*),
INTENT(IN) :: op
316 CHARACTER(LEN=*),
INTENT(IN),
OPTIONAL :: pos
317 CHARACTER(LEN=*),
INTENT(IN),
OPTIONAL :: transa
319 CHARACTER(len=*),
PARAMETER :: routinen =
'cp_fm_cholesky_restore'
320 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: a, b, outm
321 REAL(kind=
dp) :: alpha
322 INTEGER :: handle, mdim, n
323 CHARACTER :: chol_pos, chol_transa
324#if defined(__parallel)
326 INTEGER,
DIMENSION(9) :: desca, descb, descout
327#elif defined(__MKL) && (2025 <= __INTEL_MKL__)
328 REAL(kind=
dp) :: beta
331 CALL timeset(routinen, handle)
334 cpassert((op ==
"SOLVE") .OR. (op ==
"MULTIPLY"))
337 IF (
PRESENT(pos)) chol_pos = pos(1:1)
338 cpassert((chol_pos ==
'L') .OR. (chol_pos ==
'R'))
341 IF (
PRESENT(transa)) chol_transa = transa
344 a => fm_matrix%local_data
345 b => fm_matrixb%local_data
346 outm => fm_matrixout%local_data
347 n = fm_matrix%matrix_struct%nrow_global
348 mdim = merge(1, 2,
'L' == chol_pos)
351#if defined(__parallel)
352 desca(:) = fm_matrix%matrix_struct%descriptor(:)
353 descb(:) = fm_matrixb%matrix_struct%descriptor(:)
354 descout(:) = fm_matrixout%matrix_struct%descriptor(:)
356 CALL pdcopy(n, a(1, 1), 1, i, desca, 1, outm(1, 1), 1, i, descout, 1)
358 IF (op ==
"SOLVE")
THEN
359 CALL pdtrsm(chol_pos,
'U', chol_transa,
'N', n, neig, alpha, b(1, 1), 1, 1, descb, outm(1, 1), 1, 1, descout)
361 CALL pdtrmm(chol_pos,
'U', chol_transa,
'N', n, neig, alpha, b(1, 1), 1, 1, descb, outm(1, 1), 1, 1, descout)
363#elif defined(__MKL) && (2025 <= __INTEL_MKL__)
365 IF (op ==
"SOLVE")
THEN
366 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)
368 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)
371 CALL dcopy(neig*n, a(1, 1), 1, outm(1, 1), 1)
372 IF (op ==
"SOLVE")
THEN
373 CALL dtrsm(chol_pos,
'U', chol_transa,
'N', n, neig, alpha, b(1, 1),
SIZE(b, mdim), outm(1, 1), n)
375 CALL dtrmm(chol_pos,
'U', chol_transa,
'N', n, neig, alpha, b(1, 1),
SIZE(b, mdim), outm(1, 1), n)
379 CALL timestop(handle)