(git:27c966b)
Loading...
Searching...
No Matches
bse_matvec.F
Go to the documentation of this file.
1!--------------------------------------------------------------------------------------------------!
2! CP2K: A general program to perform molecular dynamics simulations !
3! Copyright 2000-2026 CP2K developers group <https://cp2k.org> !
4! !
5! SPDX-License-Identifier: GPL-2.0-or-later !
6!--------------------------------------------------------------------------------------------------!
7
8! **************************************************************************************************
9!> \brief Matrix-free application of the BSE matrices A and B to trial vectors from RI slabs that
10!> are sliced along the RI index over all MPI ranks
11!> \par History
12!> 09.2026 created [Maximilian Graml]
13! **************************************************************************************************
15
16 USE bse_util, ONLY: ia_of_occ_virt,&
17 occ_of_ia,&
25 USE cp_fm_types, ONLY: cp_fm_create,&
33 USE kinds, ONLY: dp
37#include "./base/base_uses.f90"
38
39 IMPLICIT NONE
40
41 PRIVATE
42
43 CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'bse_matvec'
44
45 ! the detected MEMORY_PER_PROC claims this share of the free memory on top of the occupied memory,
46 ! the share resolve_memory_per_proc of the GW claims; the probe counts reclaimable cache
47 REAL(KIND=dp), PARAMETER :: detected_memory_fraction = 0.8_dp, &
48 fallback_memory_per_proc_gb = 2.0_dp
49
53
54! **************************************************************************************************
55!> \brief RI slabs of one spin channel, every rank holding n_ri_loc whole RI slices
56!> \param alpha prefactor of the exchange term (2 singlet, 0 triplet)
57!> \param w_fac prefactor of the screened term (0 switches it off)
58!> \param eps_diff ε_a - ε_i at the compound index ia = (i-1)*virt + a of bse_util's ia_of_occ_virt
59!> \param B_ia B^P_ia at (a, i, P)
60!> \param B_bar_ia \bar{B}^P_ia at (a, i, P), only for do_abba
61!> \param B_bar_ij \bar{B}^P_ij at (j, i, P)
62!> \param B_ab B^P_ab at (b, a, P)
63!> \param row_count rows of a trial vector owned by each rank, in rank order
64!> \param row_displ first row of each rank minus one, so that row_count and row_displ describe
65!> the contiguous ia range per rank that allgatherv and sum_scatter need
66!> \param blacs_env npe x 1 process grid of the slabs and of all trial vectors
67!> \param block_cols trial vectors per pass in bse_matvec_apply, -1 to size it from the memory left
68!> \param memory_per_proc_gb the resolved MEMORY_PER_PROC of the BSE, which block_cols -1 sizes the pass from
69! **************************************************************************************************
71 INTEGER :: homo = 0, virt = 0, n_ov = 0, &
72 n_ri_loc = 0, block_cols = -1
73 REAL(kind=dp) :: alpha = 0.0_dp, w_fac = 0.0_dp, &
74 memory_per_proc_gb = -1.0_dp
75 LOGICAL :: do_abba = .false.
76 INTEGER, ALLOCATABLE, DIMENSION(:) :: row_count, row_displ
77 REAL(kind=dp), ALLOCATABLE, DIMENSION(:) :: eps_diff
78 REAL(kind=dp), ALLOCATABLE, DIMENSION(:, :, :) :: b_ia, b_bar_ia, b_bar_ij, b_ab
79 TYPE(cp_blacs_env_type), POINTER :: blacs_env => null()
80 TYPE(mp_para_env_type), POINTER :: para_env => null()
81 END TYPE bse_matvec_env_type
82
83CONTAINS
84
85! **************************************************************************************************
86!> \brief MEMORY_PER_PROC of the BSE as a number: the keyword's value, or for -1 the memory the rank
87!> holds plus the share detected_memory_fraction of the free memory, read once at the first
88!> consumer; when the free memory cannot be read, the GW's fallback of 2 GB with a warning
89!> \param memory_per_proc_gb the keyword's value on entry, the memory per MPI rank for the BSE on exit
90!> \param para_env the ranks that share the node's memory
91!> \param unit_nr output unit, positive on the writing rank only
92! **************************************************************************************************
93 SUBROUTINE bse_resolve_memory_per_proc(memory_per_proc_gb, para_env, unit_nr)
94 REAL(kind=dp), INTENT(INOUT) :: memory_per_proc_gb
95 TYPE(mp_para_env_type), POINTER :: para_env
96 INTEGER, INTENT(IN) :: unit_nr
97
98 REAL(kind=dp) :: mem_free_gb, mem_occ_gb
99
100 IF (memory_per_proc_gb >= 0.0_dp) RETURN
101 CALL mp_mem_avail_per_rank_gb(para_env, mem_free_gb)
102 CALL mp_mem_used_per_rank_gb(para_env, mem_occ_gb)
103 IF (mem_free_gb > 0.0_dp) THEN
104 memory_per_proc_gb = mem_occ_gb + detected_memory_fraction*mem_free_gb
105 IF (unit_nr > 0) THEN
106 WRITE (unit_nr, '(T2,A4,T7,A,T67,F14.3)') 'BSE|', 'Memory per MPI rank for the BSE, detected (GB)', &
107 memory_per_proc_gb
108 END IF
109 ELSE
110 memory_per_proc_gb = fallback_memory_per_proc_gb
111 CALL cp_warn(__location__, &
112 "BSE: the free memory per MPI rank could not be detected; MEMORY_PER_PROC falls back "// &
113 "to 2 GB. Set MEMORY_PER_PROC in the BSE section for a run that fits the node.")
114 END IF
115
116 END SUBROUTINE bse_resolve_memory_per_proc
117
118! **************************************************************************************************
119!> \brief What MEMORY_PER_PROC leaves to a step: the resolved memory per MPI rank minus the memory the
120!> rank holds now, never negative; both probes reduce over the ranks, so every rank gets the same
121!> \param memory_per_proc_gb the resolved MEMORY_PER_PROC
122!> \param para_env the ranks that share the node's memory
123!> \return memory left per MPI rank in GB
124! **************************************************************************************************
125 FUNCTION bse_memory_left_gb(memory_per_proc_gb, para_env) RESULT(mem_left_GB)
126 REAL(kind=dp), INTENT(IN) :: memory_per_proc_gb
127 TYPE(mp_para_env_type), POINTER :: para_env
128 REAL(kind=dp) :: mem_left_gb
129
130 REAL(kind=dp) :: mem_occ_gb
131
132 ! a consumer before the resolution would size itself from the keyword's -1
133 cpassert(memory_per_proc_gb >= 0.0_dp)
134 CALL mp_mem_used_per_rank_gb(para_env, mem_occ_gb)
135 mem_left_gb = max(memory_per_proc_gb - mem_occ_gb, 0.0_dp)
136
137 END FUNCTION bse_memory_left_gb
138
139! **************************************************************************************************
140!> \brief Moves the RI slabs onto an npe x 1 process grid, such that every rank owns whole RI
141!> slices, and stores them as local 3-index arrays: the contraction over each P in
142!> bse_matvec_apply is then a local DGEMM and only the final sum over P crosses the ranks
143!> \param mv_env the environment created here
144!> \param fm_S_ia B^P_ia, N_RI x homo*virt
145!> \param fm_S_bar_ij \bar{B}^P_ij, the slab that enters W_ij,ab, N_RI x homo*homo
146!> \param fm_S_ab B^P_ab, N_RI x virt*virt
147!> \param fm_S_bar_ia \bar{B}^P_ia, the slab that enters W_ib,aj, N_RI x homo*virt
148!> \param eps_reduced quasiparticle energies of the homo+virt active levels
149!> \param homo occupied levels of the active window
150!> \param virt virtual levels of the active window
151!> \param alpha prefactor of the exchange term, 2 singlet, 0 triplet
152!> \param w_fac prefactor of the screened term, 0 switches it off
153!> \param do_abba slice \bar{B}^P_ia as well, for the application of B
154!> \param unit_nr output unit, positive on the writing rank only
155!> \param block_cols trial vectors per pass of bse_matvec_apply; absent or -1 sizes it from the memory left
156!> \param memory_per_proc_gb the resolved MEMORY_PER_PROC of the BSE, what block_cols -1 sizes the pass from
157! **************************************************************************************************
158 SUBROUTINE bse_matvec_create(mv_env, fm_S_ia, fm_S_bar_ij, fm_S_ab, fm_S_bar_ia, eps_reduced, &
159 homo, virt, alpha, w_fac, do_abba, unit_nr, block_cols, memory_per_proc_gb)
160
161 TYPE(bse_matvec_env_type), INTENT(OUT) :: mv_env
162 TYPE(cp_fm_type), INTENT(IN) :: fm_s_ia, fm_s_bar_ij, fm_s_ab, &
163 fm_s_bar_ia
164 REAL(kind=dp), DIMENSION(:), INTENT(IN) :: eps_reduced
165 INTEGER, INTENT(IN) :: homo, virt
166 REAL(kind=dp), INTENT(IN) :: alpha, w_fac
167 LOGICAL, INTENT(IN) :: do_abba
168 INTEGER, INTENT(IN) :: unit_nr
169 INTEGER, INTENT(IN), OPTIONAL :: block_cols
170 REAL(kind=dp), INTENT(IN), OPTIONAL :: memory_per_proc_gb
171
172 CHARACTER(LEN=*), PARAMETER :: routinen = 'bse_matvec_create'
173
174 CHARACTER(LEN=12) :: n_idle_str, n_ri_str, npe_str
175 INTEGER :: a, handle, i, n_ri, n_ri_slab, &
176 n_row_block
177 REAL(kind=dp) :: mem_slabs_gb, n_slab_entries
178
179 CALL timeset(routinen, handle)
180
181 mv_env%homo = homo
182 mv_env%virt = virt
183 IF (PRESENT(block_cols)) mv_env%block_cols = block_cols
184 IF (PRESENT(memory_per_proc_gb)) mv_env%memory_per_proc_gb = memory_per_proc_gb
185 mv_env%n_ov = homo*virt
186 mv_env%alpha = alpha
187 mv_env%w_fac = w_fac
188 mv_env%do_abba = do_abba
189 mv_env%para_env => fm_s_ia%matrix_struct%para_env
190
191 CALL cp_blacs_env_create(mv_env%blacs_env, mv_env%para_env, &
192 grid_2d=[mv_env%para_env%num_pe, 1])
193
194 ! one contiguous ia range per rank, so that a trial vector is gathered with allgatherv and
195 ! its image scattered back with sum_scatter, rather than replicated by two allreduces
196 n_row_block = contiguous_row_block(mv_env%n_ov, mv_env%para_env%num_pe)
197 ALLOCATE (mv_env%row_count(mv_env%para_env%num_pe), mv_env%row_displ(mv_env%para_env%num_pe))
198 DO i = 1, mv_env%para_env%num_pe
199 mv_env%row_displ(i) = min(mv_env%n_ov, (i - 1)*n_row_block)
200 mv_env%row_count(i) = min(mv_env%n_ov, i*n_row_block) - mv_env%row_displ(i)
201 END DO
202
203 ! eps_diff_ia = ε_a - ε_i at the compound index ia = (i-1)*virt + a, the row index of every trial vector
204 ALLOCATE (mv_env%eps_diff(mv_env%n_ov))
205 DO i = 1, homo
206 DO a = 1, virt
207 mv_env%eps_diff(ia_of_occ_virt(i, a, virt)) = eps_reduced(homo + a) - eps_reduced(i)
208 END DO
209 END DO
210
211 ! every slab is sliced on the same grid, so every rank owns the same RI indices of each slab
212 CALL slice_slab(mv_env, fm_s_ia, virt, homo, mv_env%B_ia, mv_env%n_ri_loc)
213 IF (w_fac /= 0.0_dp) THEN
214 CALL slice_slab(mv_env, fm_s_bar_ij, homo, homo, mv_env%B_bar_ij, n_ri_slab)
215 cpassert(n_ri_slab == mv_env%n_ri_loc)
216 CALL slice_slab(mv_env, fm_s_ab, virt, virt, mv_env%B_ab, n_ri_slab)
217 cpassert(n_ri_slab == mv_env%n_ri_loc)
218 IF (do_abba) THEN
219 CALL slice_slab(mv_env, fm_s_bar_ia, virt, homo, mv_env%B_bar_ia, n_ri_slab)
220 cpassert(n_ri_slab == mv_env%n_ri_loc)
221 END IF
222 END IF
223
224 CALL cp_fm_get_info(fm_s_ia, nrow_global=n_ri)
225 IF (mv_env%para_env%num_pe > n_ri .AND. unit_nr > 0) THEN
226 WRITE (npe_str, '(I0)') mv_env%para_env%num_pe
227 WRITE (n_ri_str, '(I0)') n_ri
228 WRITE (n_idle_str, '(I0)') mv_env%para_env%num_pe - n_ri
229 CALL cp_warn(__location__, &
230 "BSE iterative solver: more MPI ranks ("//trim(npe_str)// &
231 ") than RI basis functions ("//trim(n_ri_str)//"); "// &
232 trim(n_idle_str)//" ranks hold no RI slice and idle in the kernel application.")
233 END IF
234
235 IF (unit_nr > 0) THEN
236 ! pair entries of the sliced slabs per RI index
237 n_slab_entries = real(homo*virt, dp)
238 IF (w_fac /= 0.0_dp) THEN
239 n_slab_entries = n_slab_entries + real(homo, dp)**2 + real(virt, dp)**2
240 IF (do_abba) n_slab_entries = n_slab_entries + real(homo*virt, dp)
241 END IF
242 mem_slabs_gb = n_slab_entries*real(mv_env%n_ri_loc, dp)*8.0e-9_dp
243 WRITE (unit_nr, '(T2,A4,T7,A,T71,I10)') 'BSE|', &
244 'Max. number of RI functions per MPI rank', mv_env%n_ri_loc
245 WRITE (unit_nr, '(T2,A4,T7,A,T67,F14.3)') 'BSE|', &
246 'Memory of the RI slabs per MPI rank (GB)', mem_slabs_gb
247 END IF
248
249 CALL timestop(handle)
250
251 END SUBROUTINE bse_matvec_create
252
253! **************************************************************************************************
254!> \brief Rows of a trial vector per rank, the smallest block that leaves no rank beyond the last
255!> \param n_ov number of transitions, the global row count
256!> \param npe ranks of the npe x 1 grid
257!> \return rows of every full block; the last rank takes what remains, possibly none
258! **************************************************************************************************
259 PURE FUNCTION contiguous_row_block(n_ov, npe) RESULT(n_row_block)
260
261 INTEGER, INTENT(IN) :: n_ov, npe
262 INTEGER :: n_row_block
263
264 n_row_block = (n_ov + npe - 1)/npe
265
266 END FUNCTION contiguous_row_block
267
268! **************************************************************************************************
269!> \brief Redistributes one N_RI x n_fast*n_slow slab to whole RI rows per rank and copies the owned
270!> rows into a contiguous (n_fast, n_slow, n_ri_loc) array, slab_loc(x, y, p) = slab(P_p, (y-1)*n_fast + x)
271!> for the p-th owned RI index P_p, so that every slice slab_loc(:, :, p) is a n_fast x n_slow DGEMM operand
272!> \param mv_env process grid and communicator of the slices
273!> \param fm_slab the slab on the grid of the caller, N_RI x n_fast*n_slow
274!> \param n_fast fast index of the pair index of the slab
275!> \param n_slow slow index of the pair index of the slab
276!> \param slab_loc the owned slices, allocated here
277!> \param n_ri_loc RI indices owned by this rank, the third extent of slab_loc
278! **************************************************************************************************
279 SUBROUTINE slice_slab(mv_env, fm_slab, n_fast, n_slow, slab_loc, n_ri_loc)
280
281 TYPE(bse_matvec_env_type), INTENT(IN) :: mv_env
282 TYPE(cp_fm_type), INTENT(IN) :: fm_slab
283 INTEGER, INTENT(IN) :: n_fast, n_slow
284 REAL(kind=dp), ALLOCATABLE, DIMENSION(:, :, :), &
285 INTENT(OUT) :: slab_loc
286 INTEGER, INTENT(OUT) :: n_ri_loc
287
288 CHARACTER(LEN=*), PARAMETER :: routinen = 'slice_slab'
289
290 INTEGER :: handle, n_ri, npair, p
291 TYPE(cp_fm_struct_type), POINTER :: fm_struct
292 TYPE(cp_fm_type) :: fm_sliced
293
294 CALL timeset(routinen, handle)
295
296 ! row count from the struct: the slabs may carry fewer rows than the full RI basis
297 CALL cp_fm_get_info(fm_slab, nrow_global=n_ri, ncol_global=npair)
298 cpassert(npair == n_fast*n_slow)
299
300 ! one-row blocks on the npe x 1 grid spread the RI rows cyclically over the ranks; the copy
301 ! below turns each strided local_data row into a contiguous (n_fast, n_slow) slice
302 NULLIFY (fm_struct)
303 CALL cp_fm_struct_create(fm_struct, para_env=mv_env%para_env, context=mv_env%blacs_env, &
304 nrow_global=n_ri, ncol_global=npair, nrow_block=1, &
305 force_block=.true.)
306 CALL cp_fm_create(fm_sliced, fm_struct, name="fm_slab_ri_sliced")
307 CALL cp_fm_struct_release(fm_struct)
308 CALL cp_fm_to_fm_submat_general(fm_slab, fm_sliced, n_ri, npair, 1, 1, 1, 1, &
309 fm_slab%matrix_struct%context)
310
311 CALL cp_fm_get_info(fm_sliced, nrow_local=n_ri_loc)
312 ALLOCATE (slab_loc(n_fast, n_slow, n_ri_loc))
313 DO p = 1, n_ri_loc
314 slab_loc(:, :, p) = reshape(fm_sliced%local_data(p, 1:npair), [n_fast, n_slow])
315 END DO
316 CALL cp_fm_release(fm_sliced)
317
318 CALL timestop(handle)
319
320 END SUBROUTINE slice_slab
321
322! **************************************************************************************************
323!> \brief Frees the sliced slabs, the transition energies and the process grid of mv_env
324!> \param mv_env the environment released
325! **************************************************************************************************
326 SUBROUTINE bse_matvec_release(mv_env)
327
328 TYPE(bse_matvec_env_type), INTENT(INOUT) :: mv_env
329
330 IF (ALLOCATED(mv_env%row_count)) DEALLOCATE (mv_env%row_count)
331 IF (ALLOCATED(mv_env%row_displ)) DEALLOCATE (mv_env%row_displ)
332 IF (ALLOCATED(mv_env%eps_diff)) DEALLOCATE (mv_env%eps_diff)
333 IF (ALLOCATED(mv_env%B_ia)) DEALLOCATE (mv_env%B_ia)
334 IF (ALLOCATED(mv_env%B_bar_ia)) DEALLOCATE (mv_env%B_bar_ia)
335 IF (ALLOCATED(mv_env%B_bar_ij)) DEALLOCATE (mv_env%B_bar_ij)
336 IF (ALLOCATED(mv_env%B_ab)) DEALLOCATE (mv_env%B_ab)
337 IF (ASSOCIATED(mv_env%blacs_env)) CALL cp_blacs_env_release(mv_env%blacs_env)
338 NULLIFY (mv_env%para_env)
339
340 END SUBROUTINE bse_matvec_release
341
342! **************************************************************************************************
343!> \brief Matrix structure of a block of trial vectors: rows ia distributed, all columns local
344!> \param mv_env process grid and communicator of the trial vectors
345!> \param ncol_global number of trial vectors
346!> \param fm_struct created here, released by the caller
347! **************************************************************************************************
348 SUBROUTINE bse_matvec_vector_struct(mv_env, ncol_global, fm_struct)
349
350 TYPE(bse_matvec_env_type), INTENT(IN) :: mv_env
351 INTEGER, INTENT(IN) :: ncol_global
352 TYPE(cp_fm_struct_type), POINTER :: fm_struct
353
354 NULLIFY (fm_struct)
355 ! the row block matches mv_env%row_count, which bse_matvec_apply's collectives rely on
356 CALL cp_fm_struct_create(fm_struct, para_env=mv_env%para_env, context=mv_env%blacs_env, &
357 nrow_global=mv_env%n_ov, ncol_global=ncol_global, &
358 nrow_block=contiguous_row_block(mv_env%n_ov, mv_env%para_env%num_pe), &
359 force_block=.true.)
360
361 END SUBROUTINE bse_matvec_vector_struct
362
363! **************************************************************************************************
364!> \brief Applies A (and B) to ncol trial vectors without forming an N_ov x N_ov object,
365!> (A Z)_ia = (ε_a-ε_i) Z_ia + α sum_P B^P_ia sum_jb B^P_jb Z_jb - w sum_Pjb \bar{B}^P_ij B^P_ab Z_jb
366!> (B Z)_ia = α sum_P B^P_ia sum_jb B^P_jb Z_jb - w sum_Pjb \bar{B}^P_ib B^P_ja Z_jb
367!> α: exchange prefactor (2 singlet, 0 triplet), w: prefactor of the screened term,
368!> \bar{B}: slab bound by the caller of bse_matvec_create (B itself for TDHF and ALPHA
369!> screening, sum_Q [1+Q(0)]^-1_PQ B^Q otherwise); the sums over P run over the local RI
370!> slices and are completed by a sum over the ranks
371!> \param mv_env slabs, prefactors and transition energies
372!> \param fm_Z trial vectors, columns first_col .. first_col+ncol-1 are read
373!> \param first_col first trial vector read, and first column written
374!> \param ncol number of trial vectors
375!> \param fm_AZ receives A Z in the same columns
376!> \param fm_BZ receives B Z in the same columns, or from first_col_BZ on
377!> \param first_col_BZ first column of fm_BZ written, first_col by default
378! **************************************************************************************************
379 SUBROUTINE bse_matvec_apply(mv_env, fm_Z, first_col, ncol, fm_AZ, fm_BZ, first_col_BZ)
380
381 TYPE(bse_matvec_env_type), INTENT(IN), TARGET :: mv_env
382 TYPE(cp_fm_type), INTENT(IN) :: fm_z
383 INTEGER, INTENT(IN) :: first_col, ncol
384 TYPE(cp_fm_type), INTENT(IN) :: fm_az
385 TYPE(cp_fm_type), INTENT(IN), OPTIONAL :: fm_bz
386 INTEGER, INTENT(IN), OPTIONAL :: first_col_bz
387
388 CHARACTER(LEN=*), PARAMETER :: routinen = 'bse_matvec_apply'
389
390 INTEGER :: a, col, col_shift_b, first_row, handle, handle2, homo, i, ia, iloc, k, last_row, &
391 me, n_outputs, n_small, n_work_bufs, nb, nb_max, nrow_local, nvec, offset, p, peer, rows, &
392 virt
393 INTEGER, DIMENSION(:), POINTER :: row_indices
394 LOGICAL :: do_b, do_screened, has_exchange
395 REAL(kind=dp) :: mem_avail_gb
396 REAL(kind=dp), ALLOCATABLE, DIMENSION(:), TARGET :: result_buf, work_buf
397 REAL(kind=dp), ALLOCATABLE, DIMENSION(:, :) :: t_pk
398 REAL(kind=dp), CONTIGUOUS, DIMENSION(:, :), &
399 POINTER :: b_ia_2d, local_result, packed, ra, &
400 ra_virt, rb_occ, rb_virt, t_occ, &
401 t_small_cols, t_small_rows, t_virt, z, &
402 z_occ, z_virt
403 REAL(kind=dp), CONTIGUOUS, DIMENSION(:, :, :), &
404 POINTER :: ra_screen, rb_screen, z_screen
405 INTEGER :: displs(size(mv_env%row_displ)), &
406 counts(size(mv_env%row_count))
407
408 CALL timeset(routinen, handle)
409
410 homo = mv_env%homo
411 virt = mv_env%virt
412 n_small = min(homo, virt)
413 do_b = PRESENT(fm_bz)
414 do_screened = mv_env%w_fac /= 0.0_dp .AND. mv_env%n_ri_loc > 0
415 has_exchange = mv_env%alpha /= 0.0_dp .AND. mv_env%n_ri_loc > 0
416 IF (do_b) THEN
417 ! B Z needs the \bar{B}^P_ia slab, which is sliced for do_abba only
418 cpassert(mv_env%do_abba)
419 END IF
420 col_shift_b = 0
421 IF (PRESENT(first_col_bz)) col_shift_b = first_col_bz - first_col
422
423 CALL cp_fm_get_info(fm_z, nrow_local=nrow_local, row_indices=row_indices)
424 ! the collectives below read the rows of one rank as one range, as bse_matvec_vector_struct
425 ! lays them out; a vector built elsewhere would scatter into the wrong rows
426 me = mv_env%para_env%mepos + 1
427 cpassert(nrow_local == mv_env%row_count(me))
428 cpassert(nrow_local == 0 .OR. row_indices(1) == mv_env%row_displ(me) + 1)
429
430 ! columns per pass from three/four replicated blocks: trial vectors, scratch and A (and B)
431 n_outputs = 1
432 IF (do_b) n_outputs = 2
433 n_work_bufs = 2 + n_outputs
434 IF (mv_env%block_cols > 0) THEN
435 ! pinned by input: the replicated work arrays are then a known n_work_bufs*n_ov*nb doubles
436 nb_max = min(ncol, mv_env%block_cols)
437 ELSE
438 ! the pass takes what MEMORY_PER_PROC leaves after the solver's arrays
439 mem_avail_gb = bse_memory_left_gb(mv_env%memory_per_proc_gb, mv_env%para_env)
440 nb_max = int(min(real(ncol, dp), &
441 mem_avail_gb*1.0e9_dp/(8.0_dp*real(n_work_bufs, dp)*real(mv_env%n_ov, dp))))
442 END IF
443 nb_max = max(nb_max, 1)
444 ! The paired work buffer and all collective counts/displacements use default INTEGER.
445 nb_max = min(nb_max, (huge(0)/2)/mv_env%n_ov)
446 cpassert(nb_max >= 1)
447
448 ! Keep the same three/four full buffers, reused by communication, exchange and screening.
449 ! Canonical Z and the exchange image start in the first slots of work_buf and result_buf.
450 ALLOCATE (work_buf(2*mv_env%n_ov*nb_max), result_buf(n_outputs*mv_env%n_ov*nb_max))
451 ALLOCATE (t_pk(mv_env%n_ri_loc, nb_max))
452 b_ia_2d(1:mv_env%n_ov, 1:mv_env%n_ri_loc) => mv_env%B_ia
453
454 DO col = first_col, first_col + ncol - 1, nb_max
455 nb = min(nb_max, first_col + ncol - col)
456 nvec = mv_env%n_ov*nb
457 ! Canonical ia-by-k views for the exchange block GEMMs.
458 z(1:mv_env%n_ov, 1:nb) => work_buf(1:nvec)
459 ra(1:mv_env%n_ov, 1:nb) => result_buf(1:nvec)
460
461 ! Z_ia,k on every rank, by design: each rank contracts its whole RI slices against all of Z (header of
462 ! bse_matvec_create), so the trial vectors are the one replicated buffer, n_ov x nb per matvec at any rank
463 ! count. Gather the entire block in rank-major order, then unpack the contiguous row ranges.
464 ! result_buf is free until the exchange; the second work slot receives the gathered data.
465 CALL timeset(routinen//"_gather", handle2)
466 DO k = 1, nb
467 offset = (k - 1)*nrow_local
468 result_buf(offset + 1:offset + nrow_local) = fm_z%local_data(1:nrow_local, col + k - 1)
469 END DO
470 counts = mv_env%row_count*nb
471 displs = mv_env%row_displ*nb
472 CALL mv_env%para_env%allgatherv(result_buf(1:nrow_local*nb), work_buf(nvec + 1:2*nvec), counts, displs)
473 DO peer = 1, mv_env%para_env%num_pe
474 rows = mv_env%row_count(peer)
475 first_row = mv_env%row_displ(peer) + 1
476 last_row = mv_env%row_displ(peer) + rows
477 DO k = 1, nb
478 offset = nvec + displs(peer) + (k - 1)*rows
479 z(first_row:last_row, k) = work_buf(offset + 1:offset + rows)
480 END DO
481 END DO
482 CALL timestop(handle2)
483
484 ! exchange, identical in A Z and B Z: R_ia,k = α sum_P B^P_ia t_Pk, t_Pk = sum_jb B^P_jb Z_jb,k
485 CALL timeset(routinen//"_exchange", handle2)
486 IF (has_exchange) THEN
487 CALL dgemm('T', 'N', mv_env%n_ri_loc, nb, mv_env%n_ov, 1.0_dp, b_ia_2d, mv_env%n_ov, z, mv_env%n_ov, &
488 0.0_dp, t_pk, mv_env%n_ri_loc)
489 END IF
490 ! Without screening, Z is no longer needed after forming T_Pk. Reuse its slot
491 ! for the canonical exchange image, leaving result_buf free for the reduction.
492 IF (.NOT. do_screened) ra(1:mv_env%n_ov, 1:nb) => work_buf(1:nvec)
493 IF (has_exchange) THEN
494 CALL dgemm('N', 'N', mv_env%n_ov, nb, mv_env%n_ri_loc, mv_env%alpha, b_ia_2d, mv_env%n_ov, t_pk, mv_env%n_ri_loc, &
495 0.0_dp, ra, mv_env%n_ov)
496 ELSE IF (.NOT. do_screened) THEN
497 ra(:, :) = 0.0_dp
498 END IF
499 CALL timestop(handle2)
500
501 CALL timeset(routinen//"_pack", handle2)
502 IF (do_screened) THEN
503 ! Put the trial-vector index between the two orbital indices. One flat block then has
504 ! both (i, (k a)) and ((i k), a) views, so neither contraction needs a per-vector GEMM.
505 ! TDA keeps this Z in work slot 2; ABBA uses result slot 2, leaving both work slots for A/B.
506 IF (do_b) THEN
507 z_screen(1:homo, 1:nb, 1:virt) => result_buf(nvec + 1:2*nvec)
508 ELSE
509 z_screen(1:homo, 1:nb, 1:virt) => work_buf(nvec + 1:2*nvec)
510 END IF
511 z_occ(1:homo, 1:nb*virt) => z_screen
512 z_virt(1:homo*nb, 1:virt) => z_screen
513 DO a = 1, virt
514 DO k = 1, nb
515 DO i = 1, homo
516 z_screen(i, k, a) = z(ia_of_occ_virt(i, a, virt), k)
517 END DO
518 END DO
519 END DO
520
521 ! Copy the shared exchange image into the two screened output layouts, then its original
522 ! result slot is free for all RI-slice intermediates. These permutations happen once per pass.
523 ra_screen(1:homo, 1:nb, 1:virt) => work_buf(1:nvec)
524 ra_virt(1:homo*nb, 1:virt) => work_buf(1:nvec)
525 IF (do_b) THEN
526 rb_screen(1:virt, 1:nb, 1:homo) => work_buf(nvec + 1:2*nvec)
527 rb_occ(1:virt, 1:nb*homo) => work_buf(nvec + 1:2*nvec)
528 rb_virt(1:virt*nb, 1:homo) => work_buf(nvec + 1:2*nvec)
529 END IF
530 IF (has_exchange) THEN
531 DO a = 1, virt
532 DO k = 1, nb
533 DO i = 1, homo
534 ia = ia_of_occ_virt(i, a, virt)
535 ra_screen(i, k, a) = ra(ia, k)
536 IF (do_b) rb_screen(a, k, i) = ra(ia, k)
537 END DO
538 END DO
539 END DO
540 ELSE
541 ra_virt(:, :) = 0.0_dp
542 IF (do_b) rb_occ(:, :) = 0.0_dp
543 END IF
544 t_occ(1:homo, 1:nb*virt) => result_buf(1:nvec)
545 t_virt(1:homo*nb, 1:virt) => result_buf(1:nvec)
546 ! The B association chooses the smaller square intermediate: n_small^2*nb <= nvec.
547 t_small_cols(1:n_small, 1:nb*n_small) => result_buf(1:n_small*n_small*nb)
548 t_small_rows(1:n_small*nb, 1:n_small) => result_buf(1:n_small*n_small*nb)
549 END IF
550 CALL timestop(handle2)
551
552 CALL timeset(routinen//"_W", handle2)
553 IF (do_screened) THEN
554 DO p = 1, mv_env%n_ri_loc
555 ! A: T_ikb = sum_j \bar{B}^P_ji Z_bjk, R^A_ika -= w sum_b T_ikb B^P_ba.
556 ! Only the view of T changes between the occupied and virtual block GEMMs.
557 CALL dgemm('T', 'N', homo, nb*virt, homo, 1.0_dp, mv_env%B_bar_ij(:, :, p), homo, &
558 z_occ, homo, 0.0_dp, t_occ, homo)
559 CALL dgemm('N', 'N', homo*nb, virt, virt, -mv_env%w_fac, t_virt, homo*nb, &
560 mv_env%B_ab(:, :, p), virt, 1.0_dp, ra_virt, homo*nb)
561 IF (do_b) THEN
562 ! B: R^B_aik -= w sum_jb B^P_aj Z_bjk \bar{B}^P_bi.
563 ! Associate the products as B (Z^T \bar{B}) for homo <= virt, otherwise (B Z^T) \bar{B}.
564 IF (homo <= virt) THEN
565 CALL dgemm('N', 'N', homo*nb, homo, virt, 1.0_dp, z_virt, homo*nb, &
566 mv_env%B_bar_ia(:, :, p), virt, 0.0_dp, t_small_rows, homo*nb)
567 CALL dgemm('N', 'N', virt, nb*homo, homo, -mv_env%w_fac, mv_env%B_ia(:, :, p), virt, &
568 t_small_cols, homo, 1.0_dp, rb_occ, virt)
569 ELSE
570 CALL dgemm('N', 'N', virt, nb*virt, homo, 1.0_dp, mv_env%B_ia(:, :, p), virt, &
571 z_occ, homo, 0.0_dp, t_small_cols, virt)
572 CALL dgemm('N', 'N', virt*nb, homo, virt, -mv_env%w_fac, t_small_rows, virt*nb, &
573 mv_env%B_bar_ia(:, :, p), virt, 1.0_dp, rb_virt, virt*nb)
574 END IF
575 END IF
576 END DO
577 END IF
578 CALL timestop(handle2)
579
580 ! Pack by destination rank. Screening has distinct A/B layouts; without it,
581 ! both outputs share the canonical exchange image. result_buf is free in either case.
582 CALL timeset(routinen//"_reduce", handle2)
583 DO peer = 1, mv_env%para_env%num_pe
584 rows = mv_env%row_count(peer)
585 first_row = mv_env%row_displ(peer) + 1
586 DO k = 1, nb
587 offset = n_outputs*displs(peer) + (k - 1)*rows
588 IF (do_screened) THEN
589 DO iloc = 1, rows
590 ia = first_row + iloc - 1
591 i = occ_of_ia(ia, virt)
592 a = virt_of_ia(ia, virt)
593 result_buf(offset + iloc) = ra_screen(i, k, a)
594 IF (do_b) result_buf(offset + rows*nb + iloc) = rb_screen(a, k, i)
595 END DO
596 ELSE
597 last_row = first_row + rows - 1
598 result_buf(offset + 1:offset + rows) = ra(first_row:last_row, k)
599 IF (do_b) result_buf(offset + rows*nb + 1:offset + rows*nb + rows) = ra(first_row:last_row, k)
600 END IF
601 END DO
602 END DO
603 counts = counts*n_outputs
604 ! The wrapper's serial branch also expects a single-column flattened send buffer.
605 packed(1:n_outputs*nvec, 1:1) => result_buf(1:n_outputs*nvec)
606 CALL mv_env%para_env%sum_scatter(packed, work_buf(1:n_outputs*nrow_local*nb), counts)
607 local_result(1:nrow_local, 1:n_outputs*nb) => work_buf(1:n_outputs*nrow_local*nb)
608 DO k = 1, nb
609 DO iloc = 1, nrow_local
610 ia = row_indices(iloc)
611 fm_az%local_data(iloc, col + k - 1) = local_result(iloc, k) + &
612 mv_env%eps_diff(ia)*fm_z%local_data(iloc, col + k - 1)
613 END DO
614 IF (do_b) fm_bz%local_data(1:nrow_local, col + col_shift_b + k - 1) = local_result(:, nb + k)
615 END DO
616 CALL timestop(handle2)
617 END DO
618
619 DEALLOCATE (work_buf, result_buf, t_pk)
620
621 CALL timestop(handle)
622
623 END SUBROUTINE bse_matvec_apply
624
625! **************************************************************************************************
626!> \brief Diagonal used by the Davidson correction, either ε_a-ε_i or the full diagonal
627!> A_ia,ia = ε_a-ε_i + α sum_P (B^P_ia)^2 - w sum_P \bar{B}^P_ii B^P_aa
628!> with α, w and \bar{B} as in bse_matvec_apply
629!> \param mv_env slabs, prefactors and transition energies
630!> \param precond_kind bse_precond_full_diag or bse_precond_qp_diff
631!> \param diag replicated, size N_ov
632! **************************************************************************************************
633 SUBROUTINE bse_matvec_diagonal(mv_env, precond_kind, diag)
634
635 TYPE(bse_matvec_env_type), INTENT(IN) :: mv_env
636 INTEGER, INTENT(IN) :: precond_kind
637 REAL(kind=dp), DIMENSION(:), INTENT(OUT) :: diag
638
639 CHARACTER(LEN=*), PARAMETER :: routinen = 'bse_matvec_diagonal'
640
641 INTEGER :: a, handle, i, ia, p
642
643 CALL timeset(routinen, handle)
644
645 diag(:) = 0.0_dp
646 IF (precond_kind == bse_precond_full_diag) THEN
647 DO p = 1, mv_env%n_ri_loc
648 DO i = 1, mv_env%homo
649 DO a = 1, mv_env%virt
650 ia = ia_of_occ_virt(i, a, mv_env%virt)
651 diag(ia) = diag(ia) + mv_env%alpha*mv_env%B_ia(a, i, p)**2
652 IF (mv_env%w_fac /= 0.0_dp) THEN
653 diag(ia) = diag(ia) - mv_env%w_fac*mv_env%B_bar_ij(i, i, p)*mv_env%B_ab(a, a, p)
654 END IF
655 END DO
656 END DO
657 END DO
658 ! one n_ov vector, summed once per solve; replicated on every rank on purpose
659 CALL mv_env%para_env%sum(diag)
660 END IF
661 diag(:) = diag(:) + mv_env%eps_diff(:)
662
663 CALL timestop(handle)
664
665 END SUBROUTINE bse_matvec_diagonal
666
667! **************************************************************************************************
668!> \brief Exact A (and B) on a list of transitions, replicated on every rank,
669!> A_kl = δ_kl (ε_a-ε_i) + α sum_P B^P_ia B^P_jb - w sum_P \bar{B}^P_ij B^P_ab
670!> B_kl = α sum_P B^P_ia B^P_jb - w sum_P \bar{B}^P_ib B^P_ja
671!> with k = (i,a), l = (j,b) and α, w, \bar{B} as in bse_matvec_apply
672!> \param mv_env slabs, prefactors and transition energies
673!> \param ia_list global transition indices ia = (i-1)*virt + a of the block
674!> \param A_sub SIZE(ia_list) x SIZE(ia_list)
675!> \param B_sub same, only formed when present
676! **************************************************************************************************
677 SUBROUTINE bse_matvec_subblock(mv_env, ia_list, A_sub, B_sub)
678
679 TYPE(bse_matvec_env_type), INTENT(IN) :: mv_env
680 INTEGER, DIMENSION(:), INTENT(IN) :: ia_list
681 REAL(kind=dp), DIMENSION(:, :), INTENT(OUT) :: a_sub
682 REAL(kind=dp), DIMENSION(:, :), INTENT(OUT), &
683 OPTIONAL :: b_sub
684
685 CHARACTER(LEN=*), PARAMETER :: routinen = 'bse_matvec_subblock'
686
687 INTEGER :: handle, k, l, n_sub, p
688 INTEGER, ALLOCATABLE, DIMENSION(:) :: a_virt, i_occ
689 REAL(kind=dp), ALLOCATABLE, DIMENSION(:, :) :: b_pk
690
691 CALL timeset(routinen, handle)
692
693 n_sub = SIZE(ia_list)
694 ALLOCATE (i_occ(n_sub), a_virt(n_sub), b_pk(max(mv_env%n_ri_loc, 1), n_sub))
695 DO k = 1, n_sub
696 i_occ(k) = occ_of_ia(ia_list(k), mv_env%virt)
697 a_virt(k) = virt_of_ia(ia_list(k), mv_env%virt)
698 END DO
699
700 ! exchange, identical in A and B: α sum_P B_Pk B_Pl with B_Pk = B^P_ia at ia = ia_list(k)
701 a_sub(:, :) = 0.0_dp
702 IF (mv_env%alpha /= 0.0_dp .AND. mv_env%n_ri_loc > 0) THEN
703 ! P outermost: the gathered entries of one slice lie within one contiguous (a, i) block
704 DO p = 1, mv_env%n_ri_loc
705 DO k = 1, n_sub
706 b_pk(p, k) = mv_env%B_ia(a_virt(k), i_occ(k), p)
707 END DO
708 END DO
709 CALL dgemm('T', 'N', n_sub, n_sub, mv_env%n_ri_loc, mv_env%alpha, b_pk, SIZE(b_pk, 1), b_pk, SIZE(b_pk, 1), &
710 0.0_dp, a_sub, n_sub)
711 END IF
712 IF (PRESENT(b_sub)) b_sub(:, :) = a_sub(:, :)
713
714 IF (mv_env%w_fac /= 0.0_dp) THEN
715 DO p = 1, mv_env%n_ri_loc
716 DO l = 1, n_sub
717 DO k = 1, n_sub
718 a_sub(k, l) = a_sub(k, l) - mv_env%w_fac*mv_env%B_bar_ij(i_occ(l), i_occ(k), p)*mv_env%B_ab(a_virt(l), a_virt(k), p)
719 END DO
720 END DO
721 IF (PRESENT(b_sub)) THEN
722 DO l = 1, n_sub
723 DO k = 1, n_sub
724 b_sub(k, l) = b_sub(k, l) - mv_env%w_fac*mv_env%B_ia(a_virt(k), i_occ(l), p)*mv_env%B_bar_ia(a_virt(l), i_occ(k), p)
725 END DO
726 END DO
727 END IF
728 END DO
729 END IF
730
731 CALL mv_env%para_env%sum(a_sub)
732 IF (PRESENT(b_sub)) CALL mv_env%para_env%sum(b_sub)
733 DO k = 1, n_sub
734 a_sub(k, k) = a_sub(k, k) + mv_env%eps_diff(ia_list(k))
735 END DO
736
737 DEALLOCATE (i_occ, a_virt, b_pk)
738
739 CALL timestop(handle)
740
741 END SUBROUTINE bse_matvec_subblock
742
743! **************************************************************************************************
744!> \brief Debug check of the matrix-free application against the explicit matrices A (and B),
745!> dev = max_ia,k |(A Z)_ia,k - sum_jb A_ia,jb Z_jb,k| over up to eight unit vectors Z_ia,k = δ_ia,k
746!> and one dense vector Z_ia = sin(ia), the same for B, and max_ia |d_ia - A_ia,ia| for the diagonal
747!> \param mv_env the environment under test
748!> \param fm_A_explicit A from create_A_and_B, N_ov x N_ov on the grid of the caller
749!> \param unit_nr output unit, positive on the writing rank only
750!> \param fm_B_explicit B, present for an ABBA run
751! **************************************************************************************************
752 SUBROUTINE bse_matvec_selfcheck(mv_env, fm_A_explicit, unit_nr, fm_B_explicit)
753
754 TYPE(bse_matvec_env_type), INTENT(IN) :: mv_env
755 TYPE(cp_fm_type), INTENT(IN) :: fm_a_explicit
756 INTEGER, INTENT(IN) :: unit_nr
757 TYPE(cp_fm_type), INTENT(IN), OPTIONAL :: fm_b_explicit
758
759 CHARACTER(LEN=*), PARAMETER :: routinen = 'bse_matvec_selfcheck'
760
761 INTEGER :: handle, ia, iloc, k, n_ov, n_unit, ncol, &
762 nrow_local
763 INTEGER, DIMENSION(:), POINTER :: row_indices
764 REAL(kind=dp) :: dev_a, dev_b, dev_diag
765 REAL(kind=dp), ALLOCATABLE, DIMENSION(:) :: diag
766 REAL(kind=dp), ALLOCATABLE, DIMENSION(:, :) :: mv_result, ref_matrix, ref_result, z
767 TYPE(cp_fm_struct_type), POINTER :: fm_struct
768 TYPE(cp_fm_type) :: fm_az, fm_bz, fm_z
769
770 CALL timeset(routinen, handle)
771
772 n_ov = mv_env%n_ov
773 ! eight unit vectors read eight columns of the explicit matrix exactly; the dense column covers the whole contraction
774 n_unit = min(n_ov, 8)
775 dev_b = 0.0_dp
776 ncol = n_unit + 1
777
778 ! trial vectors: e_k for k <= n_unit, then one dense column Z_ia = sin(ia)
779 ALLOCATE (z(n_ov, ncol))
780 z(:, :) = 0.0_dp
781 DO k = 1, n_unit
782 z(k, k) = 1.0_dp
783 END DO
784 DO ia = 1, n_ov
785 z(ia, ncol) = sin(real(ia, dp))
786 END DO
787
788 CALL bse_matvec_vector_struct(mv_env, ncol, fm_struct)
789 CALL cp_fm_create(fm_z, fm_struct, name="fm_Z_selfcheck")
790 CALL cp_fm_create(fm_az, fm_struct, name="fm_AZ_selfcheck")
791 CALL cp_fm_set_all(fm_az, 0.0_dp)
792 IF (PRESENT(fm_b_explicit)) THEN
793 CALL cp_fm_create(fm_bz, fm_struct, name="fm_BZ_selfcheck")
794 CALL cp_fm_set_all(fm_bz, 0.0_dp)
795 END IF
796 CALL cp_fm_struct_release(fm_struct)
797
798 CALL cp_fm_get_info(fm_z, nrow_local=nrow_local, row_indices=row_indices)
799 DO k = 1, ncol
800 DO iloc = 1, nrow_local
801 fm_z%local_data(iloc, k) = z(row_indices(iloc), k)
802 END DO
803 END DO
804
805 IF (PRESENT(fm_b_explicit)) THEN
806 CALL bse_matvec_apply(mv_env, fm_z, 1, ncol, fm_az, fm_bz)
807 ELSE
808 CALL bse_matvec_apply(mv_env, fm_z, 1, ncol, fm_az)
809 END IF
810
811 ALLOCATE (ref_matrix(n_ov, n_ov), mv_result(n_ov, ncol), ref_result(n_ov, ncol), diag(n_ov))
812
813 CALL cp_fm_get_submatrix(fm_a_explicit, ref_matrix)
814 CALL cp_fm_get_submatrix(fm_az, mv_result)
815 ref_result(:, :) = matmul(ref_matrix, z)
816 dev_a = maxval(abs(mv_result - ref_result))
818 dev_diag = 0.0_dp
819 DO ia = 1, n_ov
820 dev_diag = max(dev_diag, abs(diag(ia) - ref_matrix(ia, ia)))
821 END DO
822
823 IF (PRESENT(fm_b_explicit)) THEN
824 CALL cp_fm_get_submatrix(fm_b_explicit, ref_matrix)
825 CALL cp_fm_get_submatrix(fm_bz, mv_result)
826 ref_result(:, :) = matmul(ref_matrix, z)
827 dev_b = maxval(abs(mv_result - ref_result))
828 END IF
829
830 IF (unit_nr > 0) THEN
831 WRITE (unit_nr, '(T2,A10,T13,A,T59,ES22.6)') 'BSE|DEBUG|', &
832 'Max deviation matvec vs explicit A', dev_a
833 IF (PRESENT(fm_b_explicit)) THEN
834 WRITE (unit_nr, '(T2,A10,T13,A,T59,ES22.6)') 'BSE|DEBUG|', &
835 'Max deviation matvec vs explicit B', dev_b
836 END IF
837 WRITE (unit_nr, '(T2,A10,T13,A,T59,ES22.6)') 'BSE|DEBUG|', &
838 'Max deviation diagonal vs explicit A', dev_diag
839 END IF
840
841 DEALLOCATE (z, ref_matrix, mv_result, ref_result, diag)
842 CALL cp_fm_release(fm_z)
843 CALL cp_fm_release(fm_az)
844 IF (PRESENT(fm_b_explicit)) CALL cp_fm_release(fm_bz)
845
846 CALL timestop(handle)
847
848 END SUBROUTINE bse_matvec_selfcheck
849
850END MODULE bse_matvec
static void dgemm(const char transa, const char transb, const int m, const int n, const int k, const double alpha, const double *a, const int lda, const double *b, const int ldb, const double beta, double *c, const int ldc)
Convenient wrapper to hide Fortran nature of dgemm_, swapping a and b.
Matrix-free application of the BSE matrices A and B to trial vectors from RI slabs that are sliced al...
Definition bse_matvec.F:14
subroutine, public bse_matvec_create(mv_env, fm_s_ia, fm_s_bar_ij, fm_s_ab, fm_s_bar_ia, eps_reduced, homo, virt, alpha, w_fac, do_abba, unit_nr, block_cols, memory_per_proc_gb)
Moves the RI slabs onto an npe x 1 process grid, such that every rank owns whole RI slices,...
Definition bse_matvec.F:160
real(kind=dp) function, public bse_memory_left_gb(memory_per_proc_gb, para_env)
What MEMORY_PER_PROC leaves to a step: the resolved memory per MPI rank minus the memory the rank hol...
Definition bse_matvec.F:126
subroutine, public bse_matvec_release(mv_env)
Frees the sliced slabs, the transition energies and the process grid of mv_env.
Definition bse_matvec.F:327
subroutine, public bse_resolve_memory_per_proc(memory_per_proc_gb, para_env, unit_nr)
MEMORY_PER_PROC of the BSE as a number: the keyword's value, or for -1 the memory the rank holds plus...
Definition bse_matvec.F:94
subroutine, public bse_matvec_subblock(mv_env, ia_list, a_sub, b_sub)
Exact A (and B) on a list of transitions, replicated on every rank, A_kl = δ_kl (ε_a-ε_i) + α sum_P B...
Definition bse_matvec.F:678
subroutine, public bse_matvec_apply(mv_env, fm_z, first_col, ncol, fm_az, fm_bz, first_col_bz)
Applies A (and B) to ncol trial vectors without forming an N_ov x N_ov object, (A Z)_ia = (ε_a-ε_i) Z...
Definition bse_matvec.F:380
subroutine, public bse_matvec_diagonal(mv_env, precond_kind, diag)
Diagonal used by the Davidson correction, either ε_a-ε_i or the full diagonal A_ia,...
Definition bse_matvec.F:634
subroutine, public bse_matvec_selfcheck(mv_env, fm_a_explicit, unit_nr, fm_b_explicit)
Debug check of the matrix-free application against the explicit matrices A (and B),...
Definition bse_matvec.F:753
subroutine, public bse_matvec_vector_struct(mv_env, ncol_global, fm_struct)
Matrix structure of a block of trial vectors: rows ia distributed, all columns local.
Definition bse_matvec.F:349
Auxiliary routines for GW + Bethe-Salpeter for computing electronic excitations.
Definition bse_util.F:13
pure integer function, public occ_of_ia(ia, virt)
Occupied level of the compound transition index ia = (i-1)*virt + a.
Definition bse_util.F:110
pure integer function, public ia_of_occ_virt(i_occ, a_virt, virt)
Compound transition index ia = (i-1)*virt + a of the pair (i, a): a is the fast index.
Definition bse_util.F:95
pure integer function, public virt_of_ia(ia, virt)
Virtual level of the compound transition index ia = (i-1)*virt + a.
Definition bse_util.F:125
methods related to the blacs parallel environment
subroutine, public cp_blacs_env_release(blacs_env)
releases the given blacs_env
subroutine, public cp_blacs_env_create(blacs_env, para_env, blacs_grid_layout, blacs_repeatable, row_major, grid_2d)
allocates and initializes a type that represent a blacs context
represent the structure of a full matrix
subroutine, public cp_fm_struct_create(fmstruct, para_env, context, nrow_global, ncol_global, nrow_block, ncol_block, descriptor, first_p_pos, local_leading_dimension, template_fmstruct, square_blocks, force_block)
allocates and initializes a full matrix structure
subroutine, public cp_fm_struct_release(fmstruct)
releases a full matrix structure
represent a full matrix distributed on many processors
Definition cp_fm_types.F:15
subroutine, public cp_fm_get_info(matrix, name, nrow_global, ncol_global, nrow_block, ncol_block, nrow_local, ncol_local, row_indices, col_indices, local_data, context, nrow_locals, ncol_locals, matrix_struct, para_env)
returns all kind of information about the full matrix
subroutine, public cp_fm_to_fm_submat_general(source, destination, nrows, ncols, s_firstrow, s_firstcol, d_firstrow, d_firstcol, global_context)
General copy of a submatrix of fm matrix to a submatrix of another fm matrix. The two matrices can ha...
subroutine, public cp_fm_set_all(matrix, alpha, beta)
set all elements of a matrix to the same value, and optionally the diagonal to a different one
subroutine, public cp_fm_create(matrix, matrix_struct, name, nrow, ncol, set_zero)
creates a new full matrix with the given structure
subroutine, public cp_fm_get_submatrix(fm, target_m, start_row, start_col, n_rows, n_cols, transpose)
gets a submatrix of a full matrix op(target_m)(1:n_rows,1:n_cols) =fm(start_row:start_row+n_rows,...
collects all constants needed in input so that they can be used without circular dependencies
integer, parameter, public bse_precond_full_diag
Defines the basic variable types.
Definition kinds.F:23
integer, parameter, public dp
Definition kinds.F:34
Interface to the message passing library MPI.
subroutine, public mp_mem_used_per_rank_gb(comm, mem_used_gb)
Memory that is currently occupied by this process, in GB, maximized over all ranks of comm,...
subroutine, public mp_mem_avail_per_rank_gb(comm, mem_avail_gb)
Memory that is currently free on the node, per MPI rank of that node, in GB.
RI slabs of one spin channel, every rank holding n_ri_loc whole RI slices.
Definition bse_matvec.F:70
represent a blacs multidimensional parallel environment (for the mpi corrispective see cp_paratypes/m...
keeps the information about the structure of a full matrix
represent a full matrix
stores all the informations relevant to an mpi environment