(git:30099c3)
Loading...
Searching...
No Matches
hfx_communication.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 Routines for data exchange between MPI processes
10!> \par History
11!> 04.2008 created [Manuel Guidon]
12!> \author Manuel Guidon
13! **************************************************************************************************
26 USE hfx_types, ONLY: hfx_2d_map,&
29 USE kinds, ONLY: dp,&
30 int_8
37#include "./base/base_uses.f90"
38
39 IMPLICIT NONE
40 PRIVATE
41
42 PUBLIC :: get_full_density, &
46 CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'hfx_communication'
47
48!***
49
50CONTAINS
51
52! **************************************************************************************************
53!> \brief - Collects full density matrix from all CPUs
54!> \param para_env ...
55!> \param full_density The full Density matrix
56!> \param rho Distributed density
57!> \param number_of_p_entries Maximal buffer size
58!> \param block_offset ...
59!> \param kind_of ...
60!> \param basis_parameter ...
61!> \param get_max_vals_spin ...
62!> \param rho_beta ...
63!> \param antisymmetric ...
64!> \par History
65!> 11.2007 created [Manuel Guidon]
66!> \author Manuel Guidon
67!> \note
68!> - Communication with left/right node only
69!> added a mpi_sync before and after the ring of isendrecv. This *speed up* the
70!> communication, and might protect against idle neighbors flooding a busy node
71!> with messages [Joost]
72! **************************************************************************************************
73 SUBROUTINE get_full_density(para_env, full_density, rho, number_of_p_entries, &
74 block_offset, kind_of, basis_parameter, &
75 get_max_vals_spin, rho_beta, antisymmetric)
76
77 TYPE(mp_para_env_type), POINTER :: para_env
78 REAL(dp), DIMENSION(:) :: full_density
79 TYPE(dbcsr_type), POINTER :: rho
80 INTEGER, INTENT(IN) :: number_of_p_entries
81 INTEGER, DIMENSION(:), POINTER :: block_offset
82 INTEGER :: kind_of(*)
83 TYPE(hfx_basis_type), DIMENSION(:), POINTER :: basis_parameter
84 LOGICAL, INTENT(IN) :: get_max_vals_spin
85 TYPE(dbcsr_type), OPTIONAL, POINTER :: rho_beta
86 LOGICAL, INTENT(IN) :: antisymmetric
87
88 INTEGER :: block_size, data_from, dest, i, iatom, icpu, ikind, iset, jatom, jkind, jset, &
89 mepos, ncpu, nseta, nsetb, pa, pa1, pb, pb1, source, source_cpu
90 INTEGER, DIMENSION(:), POINTER :: nsgfa, nsgfb
91 LOGICAL :: found
92 REAL(dp) :: symmfac
93 REAL(dp), DIMENSION(:), POINTER :: recbuffer, sendbuffer, swapbuffer
94 REAL(dp), DIMENSION(:, :), POINTER :: sparse_block, sparse_block_beta
95 TYPE(dbcsr_iterator_type) :: iter
96 TYPE(mp_request_type), DIMENSION(2) :: req
97
98 full_density = 0.0_dp
99 ALLOCATE (sendbuffer(number_of_p_entries))
100 ALLOCATE (recbuffer(number_of_p_entries))
101 sendbuffer = 0.0_dp
102 recbuffer = 0.0_dp
103
104 i = 1
105 CALL dbcsr_iterator_start(iter, rho, shared=.false.)
106 DO WHILE (dbcsr_iterator_blocks_left(iter))
107 CALL dbcsr_iterator_next_block(iter, iatom, jatom, sparse_block)
108 ! the resulting vector will be only the upper triangle.
109 ! in case of antisymmetry take care to change signs if a lower block gets copied
110 symmfac = 1.0_dp
111 IF (antisymmetric .AND. iatom > jatom) symmfac = -1.0_dp
112 ikind = kind_of(iatom)
113 nseta = basis_parameter(ikind)%nset
114 nsgfa => basis_parameter(ikind)%nsgf
115 jkind = kind_of(jatom)
116 nsetb = basis_parameter(jkind)%nset
117 nsgfb => basis_parameter(jkind)%nsgf
118 IF (get_max_vals_spin) THEN
119 CALL dbcsr_get_block_p(rho_beta, &
120 row=iatom, col=jatom, block=sparse_block_beta, found=found)
121 pa = 0
122 DO iset = 1, nseta
123 pb = 0
124 DO jset = 1, nsetb
125 DO pa1 = pa + 1, pa + nsgfa(iset)
126 DO pb1 = pb + 1, pb + nsgfb(jset)
127 sendbuffer(i) = max(abs(sparse_block(pa1, pb1)), abs(sparse_block_beta(pa1, pb1)))
128 i = i + 1
129 END DO
130 END DO
131 pb = pb + nsgfb(jset)
132 END DO
133 pa = pa + nsgfa(iset)
134 END DO
135 ELSE
136 pa = 0
137 DO iset = 1, nseta
138 pb = 0
139 DO jset = 1, nsetb
140 DO pa1 = pa + 1, pa + nsgfa(iset)
141 DO pb1 = pb + 1, pb + nsgfb(jset)
142 sendbuffer(i) = sparse_block(pa1, pb1)*symmfac
143 i = i + 1
144 END DO
145 END DO
146 pb = pb + nsgfb(jset)
147 END DO
148 pa = pa + nsgfa(iset)
149 END DO
150 END IF
151 END DO
152 CALL dbcsr_iterator_stop(iter)
153
154 ! sync before/after a ring of isendrecv
155 CALL para_env%sync()
156 ncpu = para_env%num_pe
157 mepos = para_env%mepos
158 dest = modulo(mepos + 1, ncpu)
159 source = modulo(mepos - 1, ncpu)
160 DO icpu = 0, ncpu - 1
161 IF (icpu /= ncpu - 1) THEN
162 CALL para_env%isendrecv(sendbuffer, dest, recbuffer, source, &
163 req(1), req(2), 13)
164 END IF
165 data_from = modulo(mepos - icpu, ncpu)
166 source_cpu = modulo(data_from, ncpu) + 1
167 block_size = block_offset(source_cpu + 1) - block_offset(source_cpu)
168 full_density(block_offset(source_cpu):block_offset(source_cpu) + block_size - 1) = sendbuffer(1:block_size)
169
170 IF (icpu /= ncpu - 1) THEN
171 CALL mp_waitall(req)
172 END IF
173 swapbuffer => sendbuffer
174 sendbuffer => recbuffer
175 recbuffer => swapbuffer
176 END DO
177 DEALLOCATE (sendbuffer, recbuffer)
178 ! sync before/after a ring of isendrecv
179 CALL para_env%sync()
180
181 END SUBROUTINE get_full_density
182
183! **************************************************************************************************
184!> \brief - Distributes the local full Kohn-Sham matrix to all CPUS
185!> \param para_env ...
186!> \param full_ks The full Kohn-Sham matrix
187!> \param ks_matrix Distributed Kohn-Sham matrix
188!> \param number_of_p_entries Maximal buffer size
189!> \param block_offset ...
190!> \param kind_of ...
191!> \param basis_parameter ...
192!> \param off_diag_fac ...
193!> \param diag_fac ...
194!> \par History
195!> 11.2007 created [Manuel Guidon]
196!> \author Manuel Guidon
197!> \note
198!> - Communication with left/right node only
199! **************************************************************************************************
200 SUBROUTINE distribute_ks_matrix(para_env, full_ks, ks_matrix, number_of_p_entries, &
201 block_offset, kind_of, basis_parameter, &
202 off_diag_fac, diag_fac)
203
204 TYPE(mp_para_env_type), POINTER :: para_env
205 REAL(dp), DIMENSION(:) :: full_ks
206 TYPE(dbcsr_type), POINTER :: ks_matrix
207 INTEGER, INTENT(IN) :: number_of_p_entries
208 INTEGER, DIMENSION(:), POINTER :: block_offset
209 INTEGER :: kind_of(*)
210 TYPE(hfx_basis_type), DIMENSION(:), POINTER :: basis_parameter
211 REAL(dp), INTENT(IN), OPTIONAL :: off_diag_fac, diag_fac
212
213 INTEGER :: block_size, data_to, dest, dest_cpu, i, iatom, icpu, ikind, iset, jatom, jkind, &
214 jset, mepos, ncpu, nseta, nsetb, pa, pa1, pb, pb1, source
215 INTEGER, DIMENSION(:), POINTER :: nsgfa, nsgfb
216 REAL(dp) :: my_fac, myd_fac
217 REAL(dp), DIMENSION(:), POINTER :: recbuffer, sendbuffer, swapbuffer
218 REAL(dp), DIMENSION(:, :), POINTER :: sparse_block
219 TYPE(dbcsr_iterator_type) :: iter
220 TYPE(mp_request_type), DIMENSION(2) :: req
221
222 my_fac = 1.0_dp; myd_fac = 1.0_dp
223 IF (PRESENT(off_diag_fac)) my_fac = off_diag_fac
224 IF (PRESENT(diag_fac)) myd_fac = diag_fac
225
226 ALLOCATE (sendbuffer(number_of_p_entries))
227 sendbuffer = 0.0_dp
228 ALLOCATE (recbuffer(number_of_p_entries))
229 recbuffer = 0.0_dp
230
231 ncpu = para_env%num_pe
232 mepos = para_env%mepos
233 dest = modulo(mepos + 1, ncpu)
234 source = modulo(mepos - 1, ncpu)
235
236 ! sync before/after a ring of isendrecv
237 CALL para_env%sync()
238 DO icpu = 1, ncpu
239 i = 1
240 data_to = mepos - icpu
241 dest_cpu = modulo(data_to, ncpu) + 1
242 block_size = block_offset(dest_cpu + 1) - block_offset(dest_cpu)
243 sendbuffer(1:block_size) = sendbuffer(1:block_size) + full_ks(block_offset(dest_cpu):block_offset(dest_cpu) + block_size - 1)
244 IF (icpu == ncpu) EXIT
245 CALL para_env%isendrecv(sendbuffer, dest, recbuffer, source, &
246 req(1), req(2), 13)
247
248 CALL mp_waitall(req)
249 swapbuffer => sendbuffer
250 sendbuffer => recbuffer
251 recbuffer => swapbuffer
252 END DO
253 ! sync before/after a ring of isendrecv
254 CALL para_env%sync()
255
256 i = 1
257 CALL dbcsr_iterator_start(iter, ks_matrix, shared=.false.)
258 DO WHILE (dbcsr_iterator_blocks_left(iter))
259 CALL dbcsr_iterator_next_block(iter, iatom, jatom, sparse_block)
260
261 ikind = kind_of(iatom)
262 nseta = basis_parameter(ikind)%nset
263 nsgfa => basis_parameter(ikind)%nsgf
264 jkind = kind_of(jatom)
265 nsetb = basis_parameter(jkind)%nset
266 nsgfb => basis_parameter(jkind)%nsgf
267 pa = 0
268 DO iset = 1, nseta
269 pb = 0
270 DO jset = 1, nsetb
271 DO pa1 = pa + 1, pa + nsgfa(iset)
272 DO pb1 = pb + 1, pb + nsgfb(jset)
273 IF (iatom == jatom .AND. pa1 == pb1) THEN
274 sparse_block(pa1, pb1) = sendbuffer(i)*myd_fac + sparse_block(pa1, pb1)
275 ELSE
276 sparse_block(pa1, pb1) = sendbuffer(i)*my_fac + sparse_block(pa1, pb1)
277 END IF
278 i = i + 1
279 END DO
280 END DO
281 pb = pb + nsgfb(jset)
282 END DO
283 pa = pa + nsgfa(iset)
284 END DO
285 END DO
286 CALL dbcsr_iterator_stop(iter)
287
288 DEALLOCATE (sendbuffer, recbuffer)
289
290 END SUBROUTINE distribute_ks_matrix
291
292! **************************************************************************************************
293!> \brief - Distributes the local full Kohn-Sham matrix to all CPUS. Is called in
294!> case of adiabatic rescaling. This is just a refactored version of
295!> distribute_ks_matrix
296!> \param para_env ...
297!> \param qs_env ...
298!> \param ks_matrix Distributed Kohn-Sham matrix
299!> \param irep ...
300!> \param scaling_factor ...
301!> \par History
302!> 11.2007 created [Manuel Guidon]
303!> \author Manuel Guidon
304!> \note
305!> - Communication with left/right node only
306! **************************************************************************************************
307 SUBROUTINE scale_and_add_fock_to_ks_matrix(para_env, qs_env, ks_matrix, irep, &
308 scaling_factor)
309
310 TYPE(mp_para_env_type), POINTER :: para_env
311 TYPE(qs_environment_type), POINTER :: qs_env
312 TYPE(dbcsr_p_type), DIMENSION(:, :), POINTER :: ks_matrix
313 INTEGER, INTENT(IN) :: irep
314 REAL(dp), INTENT(IN) :: scaling_factor
315
316 INTEGER :: iatom, ikind, img, natom, nimages, nspins
317 INTEGER, ALLOCATABLE, DIMENSION(:) :: kind_of, last_sgf_global
318 REAL(dp), DIMENSION(:, :), POINTER :: full_ks
319 TYPE(atomic_kind_type), DIMENSION(:), POINTER :: atomic_kind_set
320 TYPE(dft_control_type), POINTER :: dft_control
321 TYPE(hfx_basis_type), DIMENSION(:), POINTER :: basis_parameter
322 TYPE(hfx_type), POINTER :: actual_x_data
323 TYPE(particle_type), DIMENSION(:), POINTER :: particle_set
324
325!! All shared data is saved in i_thread = 1!
326
327 NULLIFY (dft_control)
328 actual_x_data => qs_env%x_data(irep, 1)
329 basis_parameter => actual_x_data%basis_parameter
330
331 CALL get_qs_env(qs_env=qs_env, &
332 atomic_kind_set=atomic_kind_set, &
333 particle_set=particle_set, &
334 dft_control=dft_control)
335
336 nspins = dft_control%nspins
337 nimages = dft_control%nimages
338 cpassert(nimages == 1)
339
340 CALL get_atomic_kind_set(atomic_kind_set=atomic_kind_set, kind_of=kind_of)
341
342 natom = SIZE(particle_set, 1)
343 ALLOCATE (last_sgf_global(0:natom))
344 last_sgf_global(0) = 0
345 DO iatom = 1, natom
346 ikind = kind_of(iatom)
347 last_sgf_global(iatom) = last_sgf_global(iatom - 1) + basis_parameter(ikind)%nsgf_total
348 END DO
349 full_ks => actual_x_data%full_ks_alpha
350 IF (scaling_factor /= 1.0_dp) THEN
351 full_ks = full_ks*scaling_factor
352 END IF
353 DO img = 1, nimages
354 CALL distribute_ks_matrix(para_env, full_ks(:, img), ks_matrix(1, img)%matrix, actual_x_data%number_of_p_entries, &
355 actual_x_data%block_offset, kind_of, basis_parameter, &
356 off_diag_fac=0.5_dp)
357 END DO
358 DEALLOCATE (actual_x_data%full_ks_alpha)
359
360 IF (nspins == 2) THEN
361 full_ks => actual_x_data%full_ks_beta
362 IF (scaling_factor /= 1.0_dp) THEN
363 full_ks = full_ks*scaling_factor
364 END IF
365 DO img = 1, nimages
366 CALL distribute_ks_matrix(para_env, full_ks(:, img), ks_matrix(2, img)%matrix, actual_x_data%number_of_p_entries, &
367 actual_x_data%block_offset, kind_of, basis_parameter, &
368 off_diag_fac=0.5_dp)
369 END DO
370 DEALLOCATE (actual_x_data%full_ks_beta)
371 END IF
372
373 DEALLOCATE (last_sgf_global)
374
376
377! **************************************************************************************************
378!> \brief Given a 2d index pair, this function returns a 1d index pair for
379!> a symmetric upper triangle NxN matrix
380!> The compiler should inline this function, therefore it appears in
381!> several modules
382!> \param i 2d index
383!> \param j 2d index
384!> \param N matrix size
385!> \return ...
386!> \par History
387!> 03.2009 created [Manuel Guidon]
388!> \author Manuel Guidon
389! **************************************************************************************************
390 PURE FUNCTION get_1d_idx(i, j, N)
391 INTEGER, INTENT(IN) :: i, j
392 INTEGER(int_8), INTENT(IN) :: n
393 INTEGER(int_8) :: get_1d_idx
394
395 INTEGER(int_8) :: min_ij
396
397 min_ij = min(i, j)
398 get_1d_idx = min_ij*n + max(i, j) - (min_ij - 1)*min_ij/2 - n
399
400 END FUNCTION get_1d_idx
401
402! **************************************************************************************************
403!> \brief create a several maps array that reflects the ks matrix sparsity
404!> \param matrix ...
405!> \param basis_parameter ...
406!> \param kind_of ...
407!> \param is_assoc_atomic_block ...
408!> \param number_of_p_entries ...
409!> \param para_env ...
410!> \param atomic_block_offset ...
411!> \param set_offset ...
412!> \param block_offset ...
413!> \param map_atoms_to_cpus ...
414!> \param nkind ...
415!> \par History
416!> 11.2007 refactored [Joost VandeVondele]
417!> 07.2009 add new maps
418!> \author Manuel Guidon
419!> \notes
420!> is_assoc_atomic_block returns the mpi rank + 1 for associated blocks,
421!> zero for unassiated blocks
422! **************************************************************************************************
423 SUBROUTINE get_atomic_block_maps(matrix, basis_parameter, kind_of, &
424 is_assoc_atomic_block, number_of_p_entries, &
425 para_env, atomic_block_offset, set_offset, &
426 block_offset, map_atoms_to_cpus, nkind)
427
428 TYPE(dbcsr_type), POINTER :: matrix
429 TYPE(hfx_basis_type), DIMENSION(:) :: basis_parameter
430 INTEGER, DIMENSION(:) :: kind_of
431 INTEGER, DIMENSION(:, :), INTENT(OUT) :: is_assoc_atomic_block
432 INTEGER, INTENT(OUT) :: number_of_p_entries
433 TYPE(mp_para_env_type), POINTER :: para_env
434 INTEGER, DIMENSION(:, :), POINTER :: atomic_block_offset
435 INTEGER, DIMENSION(:, :, :, :), POINTER :: set_offset
436 INTEGER, DIMENSION(:), POINTER :: block_offset
437 TYPE(hfx_2d_map), DIMENSION(:), POINTER :: map_atoms_to_cpus
438 INTEGER :: nkind
439
440 CHARACTER(LEN=*), PARAMETER :: routinen = 'get_atomic_block_maps'
441
442 INTEGER :: handle, iatom, ibuf, icpu, ikind, ilist, iset, itask, jatom, jkind, jset, natom, &
443 ncpu, nseta, nsetb, number_of_p_blocks, offset, tmp(2)
444 INTEGER, ALLOCATABLE, DIMENSION(:) :: buffer_in, buffer_out, counter, rcount, &
445 rdispl
446 INTEGER, DIMENSION(:), POINTER :: iatom_list, jatom_list, nsgfa, nsgfb
447 REAL(kind=dp), DIMENSION(:, :), POINTER :: sparse_block
448 TYPE(dbcsr_iterator_type) :: iter
449
450 CALL timeset(routinen, handle)
451
452 is_assoc_atomic_block = 0
453 number_of_p_entries = 0
454 number_of_p_blocks = 0
455
456 !
457 ! count number_of_p_blocks and number_of_p_entries
458 !
459 CALL dbcsr_iterator_start(iter, matrix, shared=.false.)
460 DO WHILE (dbcsr_iterator_blocks_left(iter))
461 CALL dbcsr_iterator_next_block(iter, iatom, jatom, sparse_block)
462 ikind = kind_of(iatom)
463 jkind = kind_of(jatom)
464 number_of_p_blocks = number_of_p_blocks + 1
465 number_of_p_entries = number_of_p_entries + &
466 basis_parameter(ikind)%nsgf_total*basis_parameter(jkind)%nsgf_total
467 END DO
468 CALL dbcsr_iterator_stop(iter)
469
470 tmp = [number_of_p_entries, number_of_p_blocks]
471 CALL para_env%max(tmp)
472 number_of_p_entries = tmp(1)
473 number_of_p_blocks = tmp(2)
474 !
475 ! send this info around, so we can construct is_assoc_atomic_block
476 ! pack all data in buffers and use allgatherv
477 !
478 ALLOCATE (buffer_in(3*number_of_p_blocks))
479 ALLOCATE (buffer_out(3*number_of_p_blocks*para_env%num_pe))
480 ALLOCATE (rcount(para_env%num_pe), rdispl(para_env%num_pe))
481
482 buffer_in = 0
483 ibuf = 0
484
485 CALL dbcsr_iterator_start(iter, matrix, shared=.false.)
486 DO WHILE (dbcsr_iterator_blocks_left(iter))
487 CALL dbcsr_iterator_next_block(iter, iatom, jatom, sparse_block)
488
489 buffer_in(ibuf + 1) = iatom
490 buffer_in(ibuf + 2) = jatom
491 buffer_in(ibuf + 3) = para_env%mepos + 1
492 ibuf = ibuf + 3
493 END DO
494 CALL dbcsr_iterator_stop(iter)
495
496 rcount = SIZE(buffer_in)
497 rdispl(1) = 0
498 DO icpu = 2, para_env%num_pe
499 rdispl(icpu) = rdispl(icpu - 1) + rcount(icpu - 1)
500 END DO
501 CALL para_env%allgatherv(buffer_in, buffer_out, rcount, rdispl)
502
503 DO ibuf = 0, number_of_p_blocks*para_env%num_pe*3 - 3, 3
504 itask = buffer_out(ibuf + 3)
505 ! buffer_out can be 0 if buffer_in contained less elements than the max number of atom pairs
506 ! is_assoc_atomic_block is a map for atom pairs to a processor (assumes symmetry, i,j on the ame as j,i)
507 IF (itask /= 0) THEN
508 iatom = buffer_out(ibuf + 1)
509 jatom = buffer_out(ibuf + 2)
510 is_assoc_atomic_block(iatom, jatom) = itask
511 is_assoc_atomic_block(jatom, iatom) = itask
512 END IF
513 END DO
514
515 IF (ASSOCIATED(map_atoms_to_cpus)) THEN
516 DO icpu = 1, para_env%num_pe
517 DEALLOCATE (map_atoms_to_cpus(icpu)%iatom_list)
518 DEALLOCATE (map_atoms_to_cpus(icpu)%jatom_list)
519 END DO
520 DEALLOCATE (map_atoms_to_cpus)
521 END IF
522
523 natom = SIZE(is_assoc_atomic_block, 1)
524 ALLOCATE (map_atoms_to_cpus(para_env%num_pe))
525 ALLOCATE (counter(para_env%num_pe))
526 counter = 0
527
528 DO iatom = 1, natom
529 DO jatom = iatom, natom
530 icpu = is_assoc_atomic_block(jatom, iatom)
531 IF (icpu > 0) counter(icpu) = counter(icpu) + 1
532 END DO
533 END DO
534 DO icpu = 1, para_env%num_pe
535 ALLOCATE (map_atoms_to_cpus(icpu)%iatom_list(counter(icpu)))
536 ALLOCATE (map_atoms_to_cpus(icpu)%jatom_list(counter(icpu)))
537 END DO
538 counter = 0
539 DO iatom = 1, natom
540 DO jatom = iatom, natom
541 icpu = is_assoc_atomic_block(jatom, iatom)
542 IF (icpu > 0) THEN
543 counter(icpu) = counter(icpu) + 1
544 map_atoms_to_cpus(icpu)%jatom_list(counter(icpu)) = jatom
545 map_atoms_to_cpus(icpu)%iatom_list(counter(icpu)) = iatom
546 END IF
547 END DO
548 END DO
549
550 DEALLOCATE (counter)
551
552 ncpu = para_env%num_pe
553 offset = 1
554 atomic_block_offset = 0
555 block_offset = 0
556 DO icpu = 1, ncpu
557 iatom_list => map_atoms_to_cpus(icpu)%iatom_list
558 jatom_list => map_atoms_to_cpus(icpu)%jatom_list
559 block_offset(icpu) = offset
560 DO ilist = 1, SIZE(iatom_list)
561 iatom = iatom_list(ilist)
562 ikind = kind_of(iatom)
563 jatom = jatom_list(ilist)
564 jkind = kind_of(jatom)
565 atomic_block_offset(iatom, jatom) = offset
566 atomic_block_offset(jatom, iatom) = offset
567 offset = offset + basis_parameter(ikind)%nsgf_total*basis_parameter(jkind)%nsgf_total
568 END DO
569 END DO
570 block_offset(ncpu + 1) = offset
571 set_offset = 0
572 DO ikind = 1, nkind
573 nseta = basis_parameter(ikind)%nset
574 nsgfa => basis_parameter(ikind)%nsgf
575 DO jkind = 1, nkind
576 nsetb = basis_parameter(jkind)%nset
577 nsgfb => basis_parameter(jkind)%nsgf
578 offset = 1
579 DO iset = 1, nseta
580 DO jset = 1, nsetb
581 set_offset(jset, iset, jkind, ikind) = offset
582 offset = offset + nsgfa(iset)*nsgfb(jset)
583 END DO
584 END DO
585 END DO
586 END DO
587
588 CALL timestop(handle)
589
590 END SUBROUTINE get_atomic_block_maps
591
592END MODULE hfx_communication
static GRID_HOST_DEVICE int modulo(int a, int m)
Equivalent of Fortran's MODULO, which always return a positive number. https://gcc....
Define the atomic kind types and their sub types.
subroutine, public get_atomic_kind_set(atomic_kind_set, atom_of_kind, kind_of, natom_of_kind, maxatom, natom, nshell, fist_potential_present, shell_present, shell_adiabatic, shell_check_distance, damping_present)
Get attributes of an atomic kind set.
Defines control structures, which contain the parameters and the settings for the DFT-based calculati...
subroutine, public dbcsr_iterator_next_block(iterator, row, column, block, block_number_argument_has_been_removed, row_size, col_size, row_offset, col_offset)
...
logical function, public dbcsr_iterator_blocks_left(iterator)
...
subroutine, public dbcsr_iterator_stop(iterator)
...
subroutine, public dbcsr_get_block_p(matrix, row, col, block, found, row_size, col_size)
...
subroutine, public dbcsr_iterator_start(iterator, matrix, shared, dynamic, dynamic_byrows)
...
Routines for data exchange between MPI processes.
subroutine, public distribute_ks_matrix(para_env, full_ks, ks_matrix, number_of_p_entries, block_offset, kind_of, basis_parameter, off_diag_fac, diag_fac)
Distributes the local full Kohn-Sham matrix to all CPUS
subroutine, public get_atomic_block_maps(matrix, basis_parameter, kind_of, is_assoc_atomic_block, number_of_p_entries, para_env, atomic_block_offset, set_offset, block_offset, map_atoms_to_cpus, nkind)
create a several maps array that reflects the ks matrix sparsity
subroutine, public get_full_density(para_env, full_density, rho, number_of_p_entries, block_offset, kind_of, basis_parameter, get_max_vals_spin, rho_beta, antisymmetric)
Collects full density matrix from all CPUs
subroutine, public scale_and_add_fock_to_ks_matrix(para_env, qs_env, ks_matrix, irep, scaling_factor)
Distributes the local full Kohn-Sham matrix to all CPUS. Is called in case of adiabatic rescaling....
Types and set/get functions for HFX.
Definition hfx_types.F:15
Defines the basic variable types.
Definition kinds.F:23
integer, parameter, public int_8
Definition kinds.F:54
integer, parameter, public dp
Definition kinds.F:34
Interface to the message passing library MPI.
Define the data structure for the particle information.
subroutine, public get_qs_env(qs_env, atomic_kind_set, qs_kind_set, cell, super_cell, cell_ref, use_ref_cell, kpoints, dft_control, mos, sab_orb, sab_all, qmmm, qmmm_periodic, mimic, sac_ae, sac_ppl, sac_lri, sap_ppnl, sab_vdw, sab_scp, sap_oce, sab_lrc, sab_se, sab_xtbe, sab_tbe, sab_core, sab_xb, sab_xtb_pp, sab_xtb_nonbond, sab_almo, sab_kp, sab_kp_nosym, sab_cneo, particle_set, energy, force, matrix_h, matrix_h_im, matrix_ks, matrix_ks_im, matrix_vxc, run_rtp, rtp, matrix_h_kp, matrix_h_im_kp, matrix_ks_kp, matrix_ks_im_kp, matrix_vxc_kp, kinetic_kp, matrix_s_kp, matrix_w_kp, matrix_s_ri_aux_kp, matrix_s, matrix_s_ri_aux, matrix_w, matrix_p_mp2, matrix_p_mp2_admm, rho, rho_xc, pw_env, ewald_env, ewald_pw, active_space, mpools, input, para_env, blacs_env, scf_control, rel_control, kinetic, qs_charges, vppl, rho_core, rho_nlcc, rho_nlcc_g, ks_env, ks_qmmm_env, wf_history, scf_env, local_particles, local_molecules, distribution_2d, dbcsr_dist, molecule_kind_set, molecule_set, subsys, cp_subsys, oce, local_rho_set, rho_atom_set, task_list, task_list_soft, rho0_atom_set, rho0_mpole, rhoz_set, rhoz_cneo_set, ecoul_1c, rho0_s_rs, rho0_s_gs, rhoz_cneo_s_rs, rhoz_cneo_s_gs, do_kpoints, has_unit_metric, requires_mo_derivs, mo_derivs, mo_loc_history, nkind, natom, nelectron_total, nelectron_spin, efield, neighbor_list_id, linres_control, xas_env, virial, cp_ddapc_env, cp_ddapc_ewald, outer_scf_history, outer_scf_ihistory, x_data, et_coupling, dftb_potential, results, se_taper, se_store_int_env, se_nddo_mpole, se_nonbond_env, admm_env, lri_env, lri_density, exstate_env, ec_env, harris_env, dispersion_env, gcp_env, vee, rho_external, external_vxc, mask, mp2_env, bs_env, kg_env, wanniercentres, atprop, ls_scf_env, do_transport, transport_env, v_hartree_rspace, s_mstruct_changed, rho_changed, potential_changed, forces_up_to_date, mscfg_env, almo_scf_env, gradient_history, variable_history, embed_pot, spin_embed_pot, polar_env, mos_last_converged, eeq, rhs, do_rixs, tb_tblite)
Get the QUICKSTEP environment.
Provides all information about an atomic kind.
stores some data used in construction of Kohn-Sham matrix
Definition hfx_types.F:510
stores all the informations relevant to an mpi environment