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 REAL(kind=
sp),
DIMENSION(:, :),
POINTER :: a_sp
71#if defined(__parallel)
72 INTEGER,
DIMENSION(9) :: desca
75 CALL timeset(routinen, handle)
77 my_n = min(matrix%matrix_struct%nrow_global, &
78 matrix%matrix_struct%ncol_global)
84 a => matrix%local_data
85 a_sp => matrix%local_data_sp
87#if defined(__parallel)
88 desca(:) = matrix%matrix_struct%descriptor(:)
97 IF (matrix%use_sp)
THEN
104 IF (matrix%use_sp)
THEN
105 CALL pspotrf(
'U', my_n, a_sp(1, 1), 1, 1, desca, info)
107 CALL pdpotrf(
'U', my_n, a(1, 1), 1, 1, desca, info)
113 IF (matrix%use_sp)
THEN
114 CALL spotrf(
'U', my_n, a_sp(1, 1),
SIZE(a_sp, 1), info)
116 CALL dpotrf(
'U', my_n, a(1, 1),
SIZE(a, 1), info)
120 IF (
PRESENT(info_out))
THEN
122 ELSE IF (info /= 0)
THEN
123 CALL cp_abort(__location__, &
124 "Cholesky decompose failed: the matrix is not positive definite or ill-conditioned.")
127 CALL timestop(handle)
142 INTEGER,
INTENT(in),
OPTIONAL :: n
143 INTEGER,
INTENT(OUT),
OPTIONAL :: info_out
145 CHARACTER(len=*),
PARAMETER :: routinen =
'cp_fm_cholesky_invert'
146 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: a
147 REAL(kind=
sp),
DIMENSION(:, :),
POINTER :: a_sp
148 INTEGER :: info, handle
150#if defined(__parallel)
151 INTEGER,
DIMENSION(9) :: desca
154 CALL timeset(routinen, handle)
156 my_n = min(matrix%matrix_struct%nrow_global, &
157 matrix%matrix_struct%ncol_global)
163 a => matrix%local_data
164 a_sp => matrix%local_data_sp
166#if defined(__parallel)
168 desca(:) = matrix%matrix_struct%descriptor(:)
170 IF (matrix%use_sp)
THEN
171 CALL pspotri(
'U', my_n, a_sp(1, 1), 1, 1, desca, info)
173 CALL pdpotri(
'U', my_n, a(1, 1), 1, 1, desca, info)
178 IF (matrix%use_sp)
THEN
179 CALL spotri(
'U', my_n, a_sp(1, 1),
SIZE(a_sp, 1), info)
181 CALL dpotri(
'U', my_n, a(1, 1),
SIZE(a, 1), info)
186 IF (
PRESENT(info_out))
THEN
190 cpabort(
"Cholesky invert failed: the matrix is not positive definite or ill-conditioned.")
193 CALL timestop(handle)
211 TYPE(
cp_fm_type),
INTENT(IN) :: matrix, matrixb
212 INTEGER,
OPTIONAL :: itype
214 CHARACTER(len=*),
PARAMETER :: routinen =
'cp_fm_cholesky_reduce'
215 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: a, b
216 INTEGER :: info, handle
217 INTEGER :: n, my_itype
218#if defined(__parallel)
219 REAL(kind=
dp) :: scale
220 INTEGER,
DIMENSION(9) :: desca, descb
223 CALL timeset(routinen, handle)
225 n = matrix%matrix_struct%nrow_global
228 IF (
PRESENT(itype)) my_itype = itype
230 a => matrix%local_data
231 b => matrixb%local_data
233#if defined(__parallel)
235 desca(:) = matrix%matrix_struct%descriptor(:)
236 descb(:) = matrixb%matrix_struct%descriptor(:)
238 CALL pdsygst(my_itype,
'U', n, a(1, 1), 1, 1, desca, b(1, 1), 1, 1, descb, scale, info)
242 IF (scale /= 1.0_dp) &
243 cpabort(
"scale not equal 1 (scale="//
cp_to_string(scale)//
")")
246 CALL dsygst(my_itype,
'U', n, a(1, 1), n, b(1, 1), n, info)
252 CALL timestop(handle)
273 TYPE(
cp_fm_type),
INTENT(IN) :: matrix, matrixb, matrixout
274 INTEGER,
INTENT(IN) :: neig
275 CHARACTER(LEN=*),
INTENT(IN) :: op
276 CHARACTER(LEN=*),
INTENT(IN),
OPTIONAL :: pos
277 CHARACTER(LEN=*),
INTENT(IN),
OPTIONAL :: transa
279 CHARACTER(len=*),
PARAMETER :: routinen =
'cp_fm_cholesky_restore'
280 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: a, b, out
281 REAL(kind=
sp),
DIMENSION(:, :),
POINTER :: a_sp, b_sp, out_sp
282 INTEGER :: itype, handle
284 REAL(kind=
dp) :: alpha
285 INTEGER :: myprow, mypcol
287 CHARACTER :: chol_pos, chol_transa
288#if defined(__parallel)
290 INTEGER,
DIMENSION(9) :: desca, descb, descout
293 CALL timeset(routinen, handle)
295 context => matrix%matrix_struct%context
296 myprow = context%mepos(1)
297 mypcol = context%mepos(2)
298 n = matrix%matrix_struct%nrow_global
300 IF (op /=
"SOLVE" .AND. op /=
"MULTIPLY") &
301 cpabort(
"wrong argument op")
303 IF (
PRESENT(pos))
THEN
310 cpabort(
"wrong argument pos")
317 IF (
PRESENT(transa)) chol_transa = transa
319 IF ((matrix%use_sp .NEQV. matrixb%use_sp) .OR. (matrix%use_sp .NEQV. matrixout%use_sp)) &
320 cpabort(
"not the same precision")
323 a => matrix%local_data
324 b => matrixb%local_data
325 out => matrixout%local_data
326 a_sp => matrix%local_data_sp
327 b_sp => matrixb%local_data_sp
328 out_sp => matrixout%local_data_sp
330#if defined(__parallel)
332 desca(:) = matrix%matrix_struct%descriptor(:)
333 descb(:) = matrixb%matrix_struct%descriptor(:)
334 descout(:) = matrixout%matrix_struct%descriptor(:)
337 IF (matrix%use_sp)
THEN
338 CALL pscopy(n, a_sp(1, 1), 1, i, desca, 1, out_sp(1, 1), 1, i, descout, 1)
340 CALL pdcopy(n, a(1, 1), 1, i, desca, 1, out(1, 1), 1, i, descout, 1)
343 IF (op .EQ.
"SOLVE")
THEN
344 IF (matrix%use_sp)
THEN
345 CALL pstrsm(chol_pos,
'U', chol_transa,
'N', n, neig, real(alpha,
sp), b_sp(1, 1), 1, 1, descb, &
346 out_sp(1, 1), 1, 1, descout)
348 CALL pdtrsm(chol_pos,
'U', chol_transa,
'N', n, neig, alpha, b(1, 1), 1, 1, descb, out(1, 1), 1, 1, descout)
351 IF (matrix%use_sp)
THEN
352 CALL pstrmm(chol_pos,
'U', chol_transa,
'N', n, neig, real(alpha,
sp), b_sp(1, 1), 1, 1, descb, &
353 out_sp(1, 1), 1, 1, descout)
355 CALL pdtrmm(chol_pos,
'U', chol_transa,
'N', n, neig, alpha, b(1, 1), 1, 1, descb, out(1, 1), 1, 1, descout)
361 IF (matrix%use_sp)
THEN
362 CALL scopy(neig*n, a_sp(1, 1), 1, out_sp(1, 1), 1)
364 CALL dcopy(neig*n, a(1, 1), 1, out(1, 1), 1)
366 IF (op .EQ.
"SOLVE")
THEN
367 IF (matrix%use_sp)
THEN
368 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)
370 CALL dtrsm(chol_pos,
'U', chol_transa,
'N', n, neig, alpha, b(1, 1),
SIZE(b, 1), out(1, 1), n)
373 IF (matrix%use_sp)
THEN
374 CALL strmm(chol_pos,
'U', chol_transa,
'N', n, neig, real(alpha,
sp), b_sp(1, 1), n, out_sp(1, 1), n)
376 CALL dtrmm(chol_pos,
'U', chol_transa,
'N', n, neig, alpha, b(1, 1), n, out(1, 1), n)
382 CALL timestop(handle)