(git:d18deda)
Loading...
Searching...
No Matches
cp_cfm_cholesky.F
Go to the documentation of this file.
1!--------------------------------------------------------------------------------------------------!
2! CP2K: A general program to perform molecular dynamics simulations !
3! Copyright 2000-2025 CP2K developers group <https://cp2k.org> !
4! !
5! SPDX-License-Identifier: GPL-2.0-or-later !
6!--------------------------------------------------------------------------------------------------!
7
8! **************************************************************************************************
9!> \brief various cholesky decomposition related routines
10!> \par History
11!> 12.2002 Moved routines from cp_cfm_basic_linalg to this new module [Rocco Meli]
12! **************************************************************************************************
14 USE cp_cfm_types, ONLY: cp_cfm_type
15 USE kinds, ONLY: dp
16
17#if defined(__DLAF)
19#endif
20
21#include "../base/base_uses.f90"
22
23 IMPLICIT NONE
24 PRIVATE
25
26 LOGICAL, PRIVATE, PARAMETER :: debug_this_module = .true.
27 CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'cp_cfm_cholesky'
28
29 PUBLIC :: cp_cfm_cholesky_decompose, &
31
32! **************************************************************************************************
33
34CONTAINS
35
36! **************************************************************************************************
37!> \brief Used to replace a symmetric positive definite matrix M with its Cholesky
38!> decomposition U: M = U^T * U, with U upper triangular.
39!> \param matrix the matrix to replace with its Cholesky decomposition
40!> \param n the number of row (and columns) of the matrix &
41!> (defaults to the min(size(matrix)))
42!> \param info_out if present, outputs info from (p)zpotrf
43!> \par History
44!> 05.2002 created [JVdV]
45!> 12.2002 updated, added n optional parm [fawzi]
46!> 09.2021 removed CPASSERT(info == 0) since there is already check of info [Jan Wilhelm]
47!> 12.2024 Added DLA-Future support [Rocco Meli]
48!> \author Joost
49! **************************************************************************************************
50 SUBROUTINE cp_cfm_cholesky_decompose(matrix, n, info_out)
51 TYPE(cp_cfm_type), INTENT(IN) :: matrix
52 INTEGER, INTENT(in), OPTIONAL :: n
53 INTEGER, INTENT(out), OPTIONAL :: info_out
54
55 CHARACTER(len=*), PARAMETER :: routinen = 'cp_cfm_cholesky_decompose'
56
57 COMPLEX(kind=dp), DIMENSION(:, :), POINTER :: a
58 INTEGER :: handle, info, my_n
59#if defined(__parallel)
60 INTEGER, DIMENSION(9) :: desca
61#else
62 INTEGER :: lda
63#endif
64
65 CALL timeset(routinen, handle)
66
67 my_n = min(matrix%matrix_struct%nrow_global, &
68 matrix%matrix_struct%ncol_global)
69 IF (PRESENT(n)) THEN
70 cpassert(n <= my_n)
71 my_n = n
72 END IF
73
74 a => matrix%local_data
75
76#if defined(__parallel)
77 desca(:) = matrix%matrix_struct%descriptor(:)
78
79#if defined(__DLAF)
80 CALL cp_cfm_pzpotrf_dlaf('U', my_n, a, 1, 1, desca, info)
81#else
82 CALL pzpotrf('U', my_n, a(1, 1), 1, 1, desca, info)
83#endif
84#else
85 lda = SIZE(a, 1)
86 CALL zpotrf('U', my_n, a(1, 1), lda, info)
87#endif
88
89 IF (PRESENT(info_out)) THEN
90 info_out = info
91 ELSE
92 IF (info /= 0) &
93 CALL cp_abort(__location__, &
94 "Cholesky decompose failed: matrix is not positive definite or ill-conditioned")
95 END IF
96
97 CALL timestop(handle)
98
99 END SUBROUTINE cp_cfm_cholesky_decompose
100
101! **************************************************************************************************
102!> \brief Used to replace Cholesky decomposition by the inverse.
103!> \param matrix : the matrix to invert (must be an upper triangular matrix),
104!> and is the output of Cholesky decomposition
105!> \param n : size of the matrix to invert (defaults to the min(size(matrix)))
106!> \param info_out : if present, outputs info of (p)zpotri
107!> \par History
108!> 05.2002 created Lianheng Tong, based on cp_fm_cholesky_invert
109!> \author Lianheng Tong
110! **************************************************************************************************
111 SUBROUTINE cp_cfm_cholesky_invert(matrix, n, info_out)
112 TYPE(cp_cfm_type), INTENT(IN) :: matrix
113 INTEGER, INTENT(in), OPTIONAL :: n
114 INTEGER, INTENT(out), OPTIONAL :: info_out
115
116 CHARACTER(len=*), PARAMETER :: routinen = 'cp_cfm_cholesky_invert'
117 COMPLEX(kind=dp), DIMENSION(:, :), POINTER :: aa
118 INTEGER :: info, handle
119 INTEGER :: my_n
120#if defined(__parallel)
121 INTEGER, DIMENSION(9) :: desca
122#endif
123
124 CALL timeset(routinen, handle)
125
126 my_n = min(matrix%matrix_struct%nrow_global, &
127 matrix%matrix_struct%ncol_global)
128 IF (PRESENT(n)) THEN
129 cpassert(n <= my_n)
130 my_n = n
131 END IF
132
133 aa => matrix%local_data
134
135#if defined(__parallel)
136 desca = matrix%matrix_struct%descriptor
137 CALL pzpotri('U', my_n, aa(1, 1), 1, 1, desca, info)
138#else
139 CALL zpotri('U', my_n, aa(1, 1), SIZE(aa, 1), info)
140#endif
141
142 IF (PRESENT(info_out)) THEN
143 info_out = info
144 ELSE
145 IF (info /= 0) &
146 CALL cp_abort(__location__, &
147 "Cholesky invert failed: the matrix is not positive definite or ill-conditioned.")
148 END IF
149
150 CALL timestop(handle)
151
152 END SUBROUTINE cp_cfm_cholesky_invert
153
154END MODULE cp_cfm_cholesky
various cholesky decomposition related routines
subroutine, public cp_cfm_cholesky_decompose(matrix, n, info_out)
Used to replace a symmetric positive definite matrix M with its Cholesky decomposition U: M = U^T * U...
subroutine, public cp_cfm_cholesky_invert(matrix, n, info_out)
Used to replace Cholesky decomposition by the inverse.
subroutine, public cp_cfm_pzpotrf_dlaf(uplo, n, a, ia, ja, desca, info)
Cholesky factorization using DLA-Future.
Represents a complex full matrix distributed on many processors.
Defines the basic variable types.
Definition kinds.F:23
integer, parameter, public dp
Definition kinds.F:34
Represent a complex full matrix.