65 INTEGER,
INTENT(in),
OPTIONAL :: n
66 INTEGER,
INTENT(out),
OPTIONAL :: info_out
68 CHARACTER(len=*),
PARAMETER :: routinen =
'cp_fm_cholesky_decompose'
70 INTEGER :: handle, info, my_n
71 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: a
72 REAL(kind=
sp),
DIMENSION(:, :),
POINTER :: a_sp
73#if defined(__parallel)
74 INTEGER,
DIMENSION(9) :: desca
77 CALL timeset(routinen, handle)
79 my_n = min(matrix%matrix_struct%nrow_global, &
80 matrix%matrix_struct%ncol_global)
86 a => matrix%local_data
87 a_sp => matrix%local_data_sp
89#if defined(__parallel)
90 desca(:) = matrix%matrix_struct%descriptor(:)
99 IF (matrix%use_sp)
THEN
106 IF (matrix%use_sp)
THEN
107 CALL pspotrf(
'U', my_n, a_sp(1, 1), 1, 1, desca, info)
109 CALL pdpotrf(
'U', my_n, a(1, 1), 1, 1, desca, info)
115 IF (matrix%use_sp)
THEN
116 CALL spotrf(
'U', my_n, a_sp(1, 1),
SIZE(a_sp, 1), info)
118 CALL dpotrf(
'U', my_n, a(1, 1),
SIZE(a, 1), info)
122 IF (
PRESENT(info_out))
THEN
124 ELSE IF (info /= 0)
THEN
125 CALL cp_abort(__location__, &
126 "Cholesky decompose failed: the matrix is not positive definite or ill-conditioned.")
129 CALL timestop(handle)
144 INTEGER,
INTENT(in),
OPTIONAL :: n
145 INTEGER,
INTENT(OUT),
OPTIONAL :: info_out
147 CHARACTER(len=*),
PARAMETER :: routinen =
'cp_fm_cholesky_invert'
148 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: a
149 REAL(kind=
sp),
DIMENSION(:, :),
POINTER :: a_sp
150 INTEGER :: info, handle
152#if defined(__parallel)
153 INTEGER,
DIMENSION(9) :: desca
156 CALL timeset(routinen, handle)
158 my_n = min(matrix%matrix_struct%nrow_global, &
159 matrix%matrix_struct%ncol_global)
165 a => matrix%local_data
166 a_sp => matrix%local_data_sp
168#if defined(__parallel)
170 desca(:) = matrix%matrix_struct%descriptor(:)
180 IF (matrix%use_sp)
THEN
187 IF (matrix%use_sp)
THEN
188 CALL pspotri(
'U', my_n, a_sp(1, 1), 1, 1, desca, info)
190 CALL pdpotri(
'U', my_n, a(1, 1), 1, 1, desca, info)
198 IF (matrix%use_sp)
THEN
199 CALL spotri(
'U', my_n, a_sp(1, 1),
SIZE(a_sp, 1), info)
201 CALL dpotri(
'U', my_n, a(1, 1),
SIZE(a, 1), info)
206 IF (
PRESENT(info_out))
THEN
210 cpabort(
"Cholesky invert failed: the matrix is not positive definite or ill-conditioned.")
213 CALL timestop(handle)
231 TYPE(
cp_fm_type),
INTENT(IN) :: matrix, matrixb
232 INTEGER,
OPTIONAL :: itype
234 CHARACTER(len=*),
PARAMETER :: routinen =
'cp_fm_cholesky_reduce'
235 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: a, b
236 INTEGER :: info, handle
237 INTEGER :: n, my_itype
238#if defined(__parallel)
239 REAL(kind=
dp) :: scale
240 INTEGER,
DIMENSION(9) :: desca, descb
243 CALL timeset(routinen, handle)
245 n = matrix%matrix_struct%nrow_global
248 IF (
PRESENT(itype)) my_itype = itype
250 a => matrix%local_data
251 b => matrixb%local_data
253#if defined(__parallel)
255 desca(:) = matrix%matrix_struct%descriptor(:)
256 descb(:) = matrixb%matrix_struct%descriptor(:)
258 CALL pdsygst(my_itype,
'U', n, a(1, 1), 1, 1, desca, b(1, 1), 1, 1, descb, scale, info)
262 IF (scale /= 1.0_dp) &
263 cpabort(
"scale not equal 1 (scale="//
cp_to_string(scale)//
")")
266 CALL dsygst(my_itype,
'U', n, a(1, 1), n, b(1, 1), n, info)
272 CALL timestop(handle)
293 TYPE(
cp_fm_type),
INTENT(IN) :: matrix, matrixb, matrixout
294 INTEGER,
INTENT(IN) :: neig
295 CHARACTER(LEN=*),
INTENT(IN) :: op
296 CHARACTER(LEN=*),
INTENT(IN),
OPTIONAL :: pos
297 CHARACTER(LEN=*),
INTENT(IN),
OPTIONAL :: transa
299 CHARACTER(len=*),
PARAMETER :: routinen =
'cp_fm_cholesky_restore'
300 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: a, b, out
301 REAL(kind=
sp),
DIMENSION(:, :),
POINTER :: a_sp, b_sp, out_sp
302 INTEGER :: itype, handle
304 REAL(kind=
dp) :: alpha
305 INTEGER :: myprow, mypcol
307 CHARACTER :: chol_pos, chol_transa
308#if defined(__parallel)
310 INTEGER,
DIMENSION(9) :: desca, descb, descout
313 CALL timeset(routinen, handle)
315 context => matrix%matrix_struct%context
316 myprow = context%mepos(1)
317 mypcol = context%mepos(2)
318 n = matrix%matrix_struct%nrow_global
320 IF (op /=
"SOLVE" .AND. op /=
"MULTIPLY") &
321 cpabort(
"wrong argument op")
323 IF (
PRESENT(pos))
THEN
330 cpabort(
"wrong argument pos")
337 IF (
PRESENT(transa)) chol_transa = transa
339 IF ((matrix%use_sp .NEQV. matrixb%use_sp) .OR. (matrix%use_sp .NEQV. matrixout%use_sp)) &
340 cpabort(
"not the same precision")
343 a => matrix%local_data
344 b => matrixb%local_data
345 out => matrixout%local_data
346 a_sp => matrix%local_data_sp
347 b_sp => matrixb%local_data_sp
348 out_sp => matrixout%local_data_sp
350#if defined(__parallel)
352 desca(:) = matrix%matrix_struct%descriptor(:)
353 descb(:) = matrixb%matrix_struct%descriptor(:)
354 descout(:) = matrixout%matrix_struct%descriptor(:)
357 IF (matrix%use_sp)
THEN
358 CALL pscopy(n, a_sp(1, 1), 1, i, desca, 1, out_sp(1, 1), 1, i, descout, 1)
360 CALL pdcopy(n, a(1, 1), 1, i, desca, 1, out(1, 1), 1, i, descout, 1)
363 IF (op .EQ.
"SOLVE")
THEN
364 IF (matrix%use_sp)
THEN
365 CALL pstrsm(chol_pos,
'U', chol_transa,
'N', n, neig, real(alpha,
sp), b_sp(1, 1), 1, 1, descb, &
366 out_sp(1, 1), 1, 1, descout)
368 CALL pdtrsm(chol_pos,
'U', chol_transa,
'N', n, neig, alpha, b(1, 1), 1, 1, descb, out(1, 1), 1, 1, descout)
371 IF (matrix%use_sp)
THEN
372 CALL pstrmm(chol_pos,
'U', chol_transa,
'N', n, neig, real(alpha,
sp), b_sp(1, 1), 1, 1, descb, &
373 out_sp(1, 1), 1, 1, descout)
375 CALL pdtrmm(chol_pos,
'U', chol_transa,
'N', n, neig, alpha, b(1, 1), 1, 1, descb, out(1, 1), 1, 1, descout)
381 IF (matrix%use_sp)
THEN
382 CALL scopy(neig*n, a_sp(1, 1), 1, out_sp(1, 1), 1)
384 CALL dcopy(neig*n, a(1, 1), 1, out(1, 1), 1)
386 IF (op .EQ.
"SOLVE")
THEN
387 IF (matrix%use_sp)
THEN
388 CALL strsm(chol_pos,
'U', chol_transa,
'N', n, neig, real(alpha,
sp), b_sp(1, 1),
SIZE(b_sp, 1), out_sp(1, 1), n)
390 CALL dtrsm(chol_pos,
'U', chol_transa,
'N', n, neig, alpha, b(1, 1),
SIZE(b, 1), out(1, 1), n)
393 IF (matrix%use_sp)
THEN
394 CALL strmm(chol_pos,
'U', chol_transa,
'N', n, neig, real(alpha,
sp), b_sp(1, 1), n, out_sp(1, 1), n)
396 CALL dtrmm(chol_pos,
'U', chol_transa,
'N', n, neig, alpha, b(1, 1), n, out(1, 1), n)
402 CALL timestop(handle)