(git:d18deda)
Loading...
Searching...
No Matches
cp_fm_dlaf_api.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
9
11 USE cp_fm_types, ONLY: cp_fm_type
12 USE kinds, ONLY: dp
13#include "../base/base_uses.f90"
14
15#if defined(__DLAF)
16 USE dlaf_fortran, ONLY: dlaf_pdpotrf, &
17 dlaf_pdsyevd, &
18 dlaf_pdsygvd, &
19 dlaf_pspotrf
20#endif
21
22 IMPLICIT NONE
23
24 PRIVATE
25
26 CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'cp_fm_dlaf_api'
27
30
31CONTAINS
32
33!***************************************************************************************************
34!> \brief Cholesky factorization using DLA-Future
35!> \param uplo ...
36!> \param n Matrix size
37!> \param a Local matrix
38!> \param ia Row index of first row (has to be 1)
39!> \param ja Col index of first column ()
40!> \param desca ScaLAPACK matrix descriptor
41!> \param info 0 if factorization completed normally
42!> \author Rocco Meli
43!> \author Mikael Simberg
44!> \author Mathieu Taillefumier
45! **************************************************************************************************
46 SUBROUTINE cp_pdpotrf_dlaf(uplo, n, a, ia, ja, desca, info)
47 CHARACTER, INTENT(IN) :: uplo
48 INTEGER, INTENT(IN) :: n
49 REAL(kind=dp), DIMENSION(:, :), TARGET :: a
50 INTEGER, INTENT(IN) :: ia, ja
51 INTEGER, DIMENSION(9) :: desca
52 INTEGER, TARGET :: info
53
54 CHARACTER(len=*), PARAMETER :: routinen = 'cp_pdpotrf_dlaf'
55
56 INTEGER :: handle
57
58 CALL timeset(routinen, handle)
59#if defined(__DLAF)
60 CALL dlaf_pdpotrf(uplo, n, a, ia, ja, desca, info)
61#else
62 mark_used(uplo)
63 mark_used(n)
64 mark_used(a)
65 mark_used(ia)
66 mark_used(ja)
67 mark_used(desca)
68 mark_used(info)
69 cpabort("CP2K compiled without the DLA-Future library.")
70#endif
71 CALL timestop(handle)
72 END SUBROUTINE cp_pdpotrf_dlaf
73
74!***************************************************************************************************
75!> \brief Cholesky factorization using DLA-Future
76!> \param uplo ...
77!> \param n Matrix size
78!> \param a Local matrix
79!> \param ia Row index of first row (has to be 1)
80!> \param ja Col index of first column ()
81!> \param desca ScaLAPACK matrix descriptor
82!> \param info 0 if factorization completed normally
83!> \author Rocco Meli
84!> \author Mikael Simberg
85!> \author Mathieu Taillefumier
86! **************************************************************************************************
87 SUBROUTINE cp_pspotrf_dlaf(uplo, n, a, ia, ja, desca, info)
88 CHARACTER, INTENT(IN) :: uplo
89 INTEGER, INTENT(IN) :: n
90 REAL, DIMENSION(:, :), TARGET :: a
91 INTEGER, INTENT(IN) :: ia, ja
92 INTEGER, DIMENSION(9) :: desca
93 INTEGER, TARGET :: info
94
95 CHARACTER(len=*), PARAMETER :: routinen = 'cp_pspotrf_dlaf'
96
97 INTEGER :: handle
98
99 CALL timeset(routinen, handle)
100
101#if defined(__DLAF)
102 CALL dlaf_pspotrf(uplo, n, a, ia, ja, desca, info)
103#else
104 mark_used(uplo)
105 mark_used(n)
106 mark_used(a)
107 mark_used(ia)
108 mark_used(ja)
109 mark_used(desca)
110 mark_used(info)
111 cpabort("CP2K compiled without the DLA-Future library.")
112#endif
113 CALL timestop(handle)
114 END SUBROUTINE cp_pspotrf_dlaf
115
116! **************************************************************************************************
117!> \brief ...
118!> \param matrix ...
119!> \param eigenvectors ...
120!> \param eigenvalues ...
121! **************************************************************************************************
122 SUBROUTINE cp_fm_diag_dlaf(matrix, eigenvectors, eigenvalues)
123
124 TYPE(cp_fm_type), INTENT(IN) :: matrix, eigenvectors
125 REAL(kind=dp), DIMENSION(:), INTENT(OUT) :: eigenvalues
126
127 CHARACTER(LEN=*), PARAMETER :: routinen = 'cp_fm_diag_dlaf'
128
129 INTEGER :: handle, n, nmo
130 REAL(kind=dp), ALLOCATABLE, DIMENSION(:), TARGET :: eig
131
132 CALL timeset(routinen, handle)
133
134 n = matrix%matrix_struct%nrow_global
135 ALLOCATE (eig(n))
136
137 CALL cp_fm_diag_dlaf_base(matrix, eigenvectors, eig)
138
139 nmo = SIZE(eigenvalues, 1)
140 IF (nmo > n) THEN
141 eigenvalues(1:n) = eig(1:n)
142 ELSE
143 eigenvalues(1:nmo) = eig(1:nmo)
144 END IF
145
146 DEALLOCATE (eig)
147
148 CALL timestop(handle)
149
150 END SUBROUTINE cp_fm_diag_dlaf
151
152!***************************************************************************************************
153!> \brief DLA-Future eigensolver
154!> \param matrix ...
155!> \param eigenvectors ...
156!> \param eigenvalues ...
157!> \author Rocco Meli
158! **************************************************************************************************
159 SUBROUTINE cp_fm_diag_dlaf_base(matrix, eigenvectors, eigenvalues)
160 TYPE(cp_fm_type), INTENT(IN) :: matrix, eigenvectors
161 REAL(kind=dp), DIMENSION(:), INTENT(OUT), TARGET :: eigenvalues
162
163 CHARACTER(len=*), PARAMETER :: dlaf_name = 'pdsyevd_dlaf', routinen = 'cp_fm_diag_dlaf_base'
164 CHARACTER, PARAMETER :: uplo = 'L'
165
166 CHARACTER(LEN=100) :: message
167 INTEGER :: dlaf_handle, handle, n
168 INTEGER, DIMENSION(9) :: desca, descz
169 INTEGER, TARGET :: info
170 REAL(kind=dp), DIMENSION(:, :), POINTER :: a, z
171
172 CALL timeset(routinen, handle)
173
174#if defined(__DLAF)
175 ! DLAF needs the lower triangular part
176 ! Use eigenvectors matrix as workspace
177 CALL cp_fm_uplo_to_full(matrix, eigenvectors)
178
179 n = matrix%matrix_struct%nrow_global
180
181 a => matrix%local_data
182 z => eigenvectors%local_data
183
184 desca(:) = matrix%matrix_struct%descriptor(:)
185 descz(:) = eigenvectors%matrix_struct%descriptor(:)
186
187 info = -1
188 CALL timeset(dlaf_name, dlaf_handle)
189
190 CALL dlaf_pdsyevd(uplo, n, a, 1, 1, desca, eigenvalues, z, 1, 1, descz, info)
191
192 CALL timestop(dlaf_handle)
193
194 IF (info /= 0) THEN
195 WRITE (message, "(A,I0,A)") "ERROR in DLAF_PDSYEVD: Eigensolver failed (INFO = ", info, ")"
196 cpabort(trim(message))
197 END IF
198#else
199 mark_used(a)
200 mark_used(z)
201 mark_used(desca)
202 mark_used(descz)
203 mark_used(matrix)
204 mark_used(eigenvectors)
205 mark_used(eigenvalues)
206 mark_used(uplo)
207 mark_used(n)
208 mark_used(info)
209 mark_used(dlaf_handle)
210 mark_used(dlaf_name)
211 mark_used(message)
212 cpabort("CP2K compiled without DLA-Future-Fortran library.")
213#endif
214
215 CALL timestop(handle)
216
217 END SUBROUTINE cp_fm_diag_dlaf_base
218
219! **************************************************************************************************
220!> \brief ...
221!> \param a_matrix ...
222!> \param b_matrix ...
223!> \param eigenvectors ...
224!> \param eigenvalues ...
225!> \author Rocco Meli
226! **************************************************************************************************
227 SUBROUTINE cp_fm_diag_gen_dlaf(a_matrix, b_matrix, eigenvectors, eigenvalues)
228
229 TYPE(cp_fm_type), INTENT(IN) :: a_matrix, b_matrix, eigenvectors
230 REAL(kind=dp), DIMENSION(:), INTENT(OUT) :: eigenvalues
231
232 CHARACTER(LEN=*), PARAMETER :: routinen = 'cp_fm_diag_gen_dlaf'
233
234 INTEGER :: handle, n, nmo
235 REAL(kind=dp), ALLOCATABLE, DIMENSION(:), TARGET :: eig
236
237 CALL timeset(routinen, handle)
238
239 n = a_matrix%matrix_struct%nrow_global
240 ALLOCATE (eig(n))
241
242 CALL cp_fm_diag_gen_dlaf_base(a_matrix, b_matrix, eigenvectors, eig)
243
244 nmo = SIZE(eigenvalues, 1)
245 IF (nmo > n) THEN
246 eigenvalues(1:n) = eig(1:n)
247 ELSE
248 eigenvalues(1:nmo) = eig(1:nmo)
249 END IF
250
251 DEALLOCATE (eig)
252
253 CALL timestop(handle)
254
255 END SUBROUTINE cp_fm_diag_gen_dlaf
256
257!***************************************************************************************************
258!> \brief DLA-Future generalized eigensolver
259!> \param a_matrix ...
260!> \param b_matrix ...
261!> \param eigenvectors ...
262!> \param eigenvalues ...
263!> \author Rocco Meli
264! **************************************************************************************************
265 SUBROUTINE cp_fm_diag_gen_dlaf_base(a_matrix, b_matrix, eigenvectors, eigenvalues)
266 TYPE(cp_fm_type), INTENT(IN) :: a_matrix, b_matrix, eigenvectors
267 REAL(kind=dp), DIMENSION(:), INTENT(OUT), TARGET :: eigenvalues
268
269 CHARACTER(len=*), PARAMETER :: dlaf_name = 'pdsyevd_dlaf', &
270 routinen = 'cp_fm_diag_gen_dlaf_base'
271 CHARACTER, PARAMETER :: uplo = 'L'
272
273 CHARACTER(LEN=100) :: message
274 INTEGER :: dlaf_handle, handle, n
275 INTEGER, DIMENSION(9) :: desca, descb, descz
276 INTEGER, TARGET :: info
277 REAL(kind=dp), DIMENSION(:, :), POINTER :: a, b, z
278
279 CALL timeset(routinen, handle)
280
281#if defined(__DLAF)
282 ! DLAF needs the lower triangular part
283 ! Use eigenvectors matrix as workspace
284 CALL cp_fm_uplo_to_full(a_matrix, eigenvectors)
285 CALL cp_fm_uplo_to_full(b_matrix, eigenvectors)
286
287 n = a_matrix%matrix_struct%nrow_global
288
289 a => a_matrix%local_data
290 b => b_matrix%local_data
291 z => eigenvectors%local_data
292
293 desca(:) = a_matrix%matrix_struct%descriptor(:)
294 descb(:) = b_matrix%matrix_struct%descriptor(:)
295 descz(:) = eigenvectors%matrix_struct%descriptor(:)
296
297 info = -1
298 CALL timeset(dlaf_name, dlaf_handle)
299
300 CALL dlaf_pdsygvd(uplo, n, a, 1, 1, desca, b, 1, 1, descb, eigenvalues, z, 1, 1, descz, info)
301
302 CALL timestop(dlaf_handle)
303
304 IF (info /= 0) THEN
305 WRITE (message, "(A,I0,A)") "ERROR in DLAF_PDSYGVD: Generalized Eigensolver failed (INFO = ", info, ")"
306 cpabort(trim(message))
307 END IF
308#else
309 mark_used(a)
310 mark_used(b)
311 mark_used(z)
312 mark_used(desca)
313 mark_used(descb)
314 mark_used(descz)
315 mark_used(a_matrix)
316 mark_used(b_matrix)
317 mark_used(eigenvectors)
318 mark_used(eigenvalues)
319 mark_used(uplo)
320 mark_used(n)
321 mark_used(info)
322 mark_used(dlaf_handle)
323 mark_used(dlaf_name)
324 mark_used(message)
325 cpabort("CP2K compiled without DLA-Future-Fortran library.")
326#endif
327
328 CALL timestop(handle)
329
330 END SUBROUTINE cp_fm_diag_gen_dlaf_base
331
332END MODULE cp_fm_dlaf_api
basic linear algebra operations for full matrices
subroutine, public cp_fm_uplo_to_full(matrix, work, uplo)
given a triangular matrix according to uplo, computes the corresponding full matrix
subroutine, public cp_pdpotrf_dlaf(uplo, n, a, ia, ja, desca, info)
Cholesky factorization using DLA-Future.
subroutine, public cp_pspotrf_dlaf(uplo, n, a, ia, ja, desca, info)
Cholesky factorization using DLA-Future.
subroutine, public cp_fm_diag_dlaf(matrix, eigenvectors, eigenvalues)
...
subroutine, public cp_fm_diag_gen_dlaf(a_matrix, b_matrix, eigenvectors, eigenvalues)
...
represent a full matrix distributed on many processors
Definition cp_fm_types.F:15
Defines the basic variable types.
Definition kinds.F:23
integer, parameter, public dp
Definition kinds.F:34
represent a full matrix