86#include "./base/base_uses.f90"
91 CHARACTER(len=*),
PARAMETER,
PRIVATE :: moduleN =
'gw_ri_rs_small_cell_full_kp_utils'
101 REAL(KIND=
dp),
PARAMETER :: eps_kpoint = 1.0e-8_dp
104 INTEGER,
PARAMETER :: column_block_cols = 32
105 INTEGER,
PARAMETER :: band_kpoints_per_pass = 64, pair_batch_size = 256
106 INTEGER,
PARAMETER :: w_chi = 1, w_metric = 2, w_tmp = 3, w_dielectric = 4, &
107 w_output = 5, n_w_matrices = 5
110 REAL(KIND=
dp),
PARAMETER :: bytes_per_mib = 1024.0_dp**2, bytes_per_gb = 1.0e9_dp
113 REAL(KIND=
dp),
PARAMETER :: stage_memory_share = 0.5_dp, reserve_share = 0.1_dp, &
114 min_reserve_gb = 1.0_dp, library_bytes = 256.0_dp*bytes_per_mib
116 REAL(KIND=
dp),
PARAMETER :: projection_workspace = 64.0_dp*bytes_per_mib, &
117 projection_round_bytes = 512.0_dp*bytes_per_mib
128 TYPE(
gwkp_type),
INTENT(INOUT) :: gwkp_env
130 CHARACTER(LEN=*),
PARAMETER :: routinen =
'prepare_ri_rs'
132 COMPLEX(dp),
ALLOCATABLE :: phi_lmu_k(:, :, :)
135 CALL timeset(routinen, handle)
138 bs_env%eps_filter, bs_env%unit_nr)
141 z_lp_q=gwkp_env%Z_lP_q, z_lp_zero=gwkp_env%Z_lP_zero)
142 CALL build_all_phi_k(bs_env, phi_lmu_k)
143 CALL build_all_psi_k(bs_env, phi_lmu_k, gwkp_env%psi_lm_k)
144 DEALLOCATE (phi_lmu_k)
145 IF (bs_env%gw_flavour ==
evgw0)
THEN
146 cpassert(
ALLOCATED(gwkp_env%eigenvalues_G))
147 cpassert(
ALLOCATED(bs_env%eigenval_evGW0))
148 cpassert(
SIZE(bs_env%eigenval_scf, 2) >= bs_env%nkp_scf_desymm)
149 bs_env%eigenval_evGW0(:, :, :) = bs_env%eigenval_scf
152 CALL timestop(handle)
165 TYPE(
gwkp_type),
INTENT(INOUT) :: gwkp_env
167 CHARACTER(LEN=*),
PARAMETER :: routinen =
'compute_G_and_chi'
171 CALL timeset(routinen, handle)
173 cpassert(.NOT.
ASSOCIATED(gwkp_env%group_env))
174 gwkp_env%group_env => bs_env%para_env
175 CALL gwkp_env%group_env%retain()
177 gwkp_env%my_group = 0
180 cpassert(.NOT.
ALLOCATED(gwkp_env%band_orbitals))
181 CALL compute_chi(bs_env, gwkp_env)
183 CALL timestop(handle)
196 TYPE(
gwkp_type),
INTENT(INOUT) :: gwkp_env
198 CHARACTER(LEN=*),
PARAMETER :: routinen =
'compute_W0'
200 COMPLEX(KIND=dp),
ALLOCATABLE :: chi_k_w(:, :), mwm_k_w(:, :)
201 INTEGER :: handle, i_batch, i_group_size, ikp, &
202 ikp_local, j_w, my_qgroup, n_qgroups, &
203 n_ri, nkp, nkp_local, q_group, &
205 INTEGER,
ALLOCATABLE :: group_load(:), q_batch(:, :), &
206 q_partner(:), q_roots(:)
207 LOGICAL,
ALLOCATABLE :: solves_q(:)
208 REAL(kind=
dp) :: available_gb, required_bytes, step_start
209 REAL(kind=
dp),
ALLOCATABLE :: frequency_elapsed(:)
215 CALL timeset(routinen, handle)
217 CALL compute_metric_coulomb_factor(bs_env, qs_env, gwkp_env)
219 DEALLOCATE (gwkp_env%psi_lm_k)
221 nkp = bs_env%nkp_scf_desymm
222 IF (bs_env%nkp_chi_eps_W_orig_plus_extra /= nkp)
THEN
223 cpabort(
"Periodic RI-RS GW requires the complete SCF transfer mesh")
225 IF (any(bs_env%nkp_grid_chi_eps_W_orig /= &
226 bs_env%kpoints_scf_desymm%nkp_grid))
THEN
227 cpabort(
"Periodic RI-RS GW requires the SCF mesh dimensions for W")
229 nkp_local =
SIZE(gwkp_env%metric_coulomb_factor, 3)
233 DO i_group_size = 1, bs_env%para_env%num_pe
234 IF (
modulo(bs_env%para_env%num_pe, i_group_size) /= 0) cycle
238 IF (required_bytes <= stage_memory_share*max(0.0_dp, available_gb)*bytes_per_gb)
EXIT
240 IF (i_group_size > bs_env%para_env%num_pe)
THEN
241 cpabort(
'Insufficient node memory for the distributed GW W(q) solver')
243 n_qgroups = bs_env%para_env%num_pe/i_group_size
244 CALL grouped_w_partition(bs_env%para_env, n_qgroups, my_qgroup, q_roots)
247 CALL minus_q_partners(bs_env%kpoints_chi_eps_W%xkp(1:3, 1:nkp), q_partner)
248 ALLOCATE (solves_q(nkp))
249 solves_q(:) = [(q_partner(ikp) >= ikp, ikp=1, nkp)]
250 ALLOCATE (group_load(0:n_qgroups - 1), source=0)
252 IF (solves_q(ikp)) group_load(
modulo(ikp, n_qgroups)) = group_load(
modulo(ikp, n_qgroups)) + 1
254 ALLOCATE (q_batch(maxval(group_load), 0:n_qgroups - 1), source=0)
257 IF (.NOT. solves_q(ikp)) cycle
258 q_group =
modulo(ikp, n_qgroups)
259 group_load(q_group) = group_load(q_group) + 1
260 q_batch(group_load(q_group), q_group) = ikp
262 ALLOCATE (gwkp_env%W_PQ_tau(nkp_local))
263 IF (nkp_local > 0 .OR. bs_env%para_env%mepos == q_roots(my_qgroup + 1))
THEN
264 ALLOCATE (chi_k_w(n_ri, n_ri), mwm_k_w(n_ri, n_ri))
266 ALLOCATE (chi_k_w(0, 0), mwm_k_w(0, 0))
269 ALLOCATE (w_group_env)
270 CALL w_group_env%from_split(bs_env%para_env, my_qgroup)
271 CALL grouped_w_create(w_matrices, w_blacs, w_matrix_struct, w_group_env, n_ri)
272 ALLOCATE (frequency_elapsed(bs_env%num_time_freq_points), source=0.0_dp)
276 DO i_batch = 1,
SIZE(q_batch, 1)
277 DO q_group = 0, n_qgroups - 1
278 ikp = q_batch(i_batch, q_group)
280 q_root = q_roots(q_group + 1)
281 q_owner =
modulo(ikp, bs_env%para_env%num_pe)
282 ikp_local = 1 + (ikp - 1)/bs_env%para_env%num_pe
283 IF (bs_env%para_env%mepos == q_owner)
THEN
284 CALL grouped_w_copy_matrix(bs_env%para_env, n_ri, q_owner, q_root, &
285 gwkp_env%metric_coulomb_factor(:, :, ikp_local), chi_k_w)
286 ALLOCATE (gwkp_env%W_PQ_tau(ikp_local)%values( &
287 n_ri, n_ri, bs_env%num_time_freq_points), source=
z_zero)
289 CALL grouped_w_copy_matrix(bs_env%para_env, n_ri, q_owner, q_root, mwm_k_w, chi_k_w)
291 IF (q_group == my_qgroup)
THEN
292 CALL set_owner_matrix(w_matrices(w_metric), chi_k_w, w_group_env, 0, n_ri)
295 DO j_w = 1, bs_env%num_time_freq_points
297 DO q_group = 0, n_qgroups - 1
298 ikp = q_batch(i_batch, q_group)
300 q_owner =
modulo(ikp, bs_env%para_env%num_pe)
301 ikp_local = 1 + (ikp - 1)/bs_env%para_env%num_pe
302 IF (bs_env%para_env%mepos == q_owner)
THEN
303 mwm_k_w(:, :) = gwkp_env%chi_q_frequency(ikp_local)%values(:, :, j_w)
309 CALL zgerc(n_ri, n_ri, cmplx(gwkp_env%leak_l0(j_w), 0.0_dp,
dp), &
310 gwkp_env%leak_e(:, ikp_local), 1, gwkp_env%leak_e(:, ikp_local), 1, &
312 CALL zgerc(n_ri, n_ri, -
z_one, gwkp_env%leak_e(:, ikp_local), 1, &
313 gwkp_env%leak_x(:, j_w, ikp_local), 1, mwm_k_w, n_ri)
314 CALL zgerc(n_ri, n_ri, -
z_one, gwkp_env%leak_x(:, j_w, ikp_local), 1, &
315 gwkp_env%leak_e(:, ikp_local), 1, mwm_k_w, n_ri)
317 CALL grouped_w_copy_matrix(bs_env%para_env, n_ri, q_owner, q_roots(q_group + 1), mwm_k_w, chi_k_w)
319 IF (q_batch(i_batch, my_qgroup) > 0)
THEN
320 CALL grouped_w_solve(w_matrices, w_group_env, n_ri, 0, chi_k_w, &
321 bs_env%eps_eigval_mat_RI, mwm_k_w)
323 DO q_group = 0, n_qgroups - 1
324 ikp = q_batch(i_batch, q_group)
326 q_owner =
modulo(ikp, bs_env%para_env%num_pe)
327 ikp_local = 1 + (ikp - 1)/bs_env%para_env%num_pe
328 CALL grouped_w_copy_matrix(bs_env%para_env, n_ri, q_roots(q_group + 1), q_owner, mwm_k_w, chi_k_w)
329 IF (bs_env%para_env%mepos == q_owner)
THEN
330 gwkp_env%W_PQ_tau(ikp_local)%values(:, :, j_w) = chi_k_w
331 IF (j_w == bs_env%num_time_freq_points)
DEALLOCATE (gwkp_env%chi_q_frequency(ikp_local)%values)
334 frequency_elapsed(j_w) = frequency_elapsed(j_w) +
m_walltime() - step_start
336 DO q_group = 0, n_qgroups - 1
337 ikp = q_batch(i_batch, q_group)
339 IF (bs_env%para_env%mepos /=
modulo(ikp, bs_env%para_env%num_pe)) cycle
340 CALL cosine_transform_ri_q(gwkp_env%W_PQ_tau(1 + (ikp - 1)/bs_env%para_env%num_pe), &
341 bs_env%time_frequency_grid%cosine_frequency_to_time)
344 CALL receive_minus_q_blocks(bs_env%para_env, q_partner, solves_q, n_ri, &
345 bs_env%num_time_freq_points, gwkp_env%W_PQ_tau)
346 DO j_w = 1, bs_env%num_time_freq_points
347 CALL bs_env%para_env%max(frequency_elapsed(j_w))
348 IF (bs_env%unit_nr > 0)
THEN
349 WRITE (bs_env%unit_nr,
'(T2,A,I3,A,I0,T56,A,T70,F10.1,A)') &
350 'GW W(iω) point ', j_w,
' / ', bs_env%num_time_freq_points, &
351 'Exec. time:', frequency_elapsed(j_w),
' s'
355 DEALLOCATE (frequency_elapsed)
357 CALL grouped_w_release(w_matrices, w_matrix_struct, w_blacs)
361 DEALLOCATE (chi_k_w, mwm_k_w)
363 cpassert(gwkp_env%ngroups == 1 .AND. gwkp_env%my_group == 0)
364 cpassert(gwkp_env%group_env%num_pe == bs_env%para_env%num_pe)
365 cpassert(gwkp_env%group_env%mepos == bs_env%para_env%mepos)
367 DEALLOCATE (group_load, q_batch, q_partner, solves_q, gwkp_env%leak_e, gwkp_env%leak_x, gwkp_env%leak_l0)
368 IF (
ALLOCATED(gwkp_env%chi_q_frequency))
DEALLOCATE (gwkp_env%chi_q_frequency)
370 CALL timestop(handle)
381 TYPE(
gwkp_type),
INTENT(INOUT) :: gwkp_env
383 CHARACTER(LEN=*),
PARAMETER :: routinen =
'compute_Sigma_x'
387 CALL timeset(routinen, handle)
389 CALL collect_band_bloch_orbitals(bs_env, gwkp_env%band_orbitals)
390 CALL compute_sigma_x_from_v(bs_env, gwkp_env)
391 CALL prepare_self_energy_groups(bs_env, gwkp_env)
392 IF (gwkp_env%ngroups > 1)
CALL band_orbitals_to_groups(bs_env, gwkp_env)
394 CALL timestop(handle)
407 SUBROUTINE prepare_self_energy_groups(bs_env, gwkp_env)
409 TYPE(
gwkp_type),
INTENT(INOUT) :: gwkp_env
411 CHARACTER(LEN=*),
PARAMETER :: routinen =
'prepare_self_energy_groups'
413 COMPLEX(KIND=dp),
ALLOCATABLE :: z_group(:, :, :)
414 INTEGER :: handle, i_dest, i_group_size, i_root, i_source, i_tag, iq, iq_local, it, &
415 it_local, n_ao, n_aux, n_grid, n_k, n_local_k, n_local_q, n_local_time, n_spin, &
416 n_stored_q, n_threads, n_time, n_world
417 REAL(kind=
dp) :: available_gb, block_bytes, budget_bytes, grid_bytes, input_bytes, n_pairs, &
418 peak_bytes, persistent_bytes, result_bytes
422 CALL timeset(routinen, handle)
426 n_world = bs_env%para_env%num_pe
427 n_grid = bs_env%ri_rs%n_grid_points
429 n_spin = bs_env%n_spin
431 n_k = bs_env%nkp_scf_desymm
432 n_time = bs_env%num_time_freq_points
434 CALL bs_env%para_env%min(available_gb)
436 REAL(ri_q_storage_elements(gwkp_env%w_pq_tau),
dp))
437 CALL bs_env%para_env%min(input_bytes)
440 budget_bytes = budget_after_reserve(available_gb)
442 result_bytes = 2.0_dp*
complex_bytes*real(n_ao,
dp)*real(
SIZE(bs_env%eigenval_scf, 2),
dp)* &
443 REAL(n_time*n_spin,
dp)
444 DO i_group_size = min(2, max(1, n_world/2)), n_world
445 IF (
modulo(n_world, i_group_size) /= 0) cycle
446 gwkp_env%ngroups = n_world/i_group_size
447 IF (gwkp_env%ngroups > n_time) cycle
448 n_local_k = (n_k + i_group_size - 1)/i_group_size
449 n_local_time = (n_time + gwkp_env%ngroups - 1)/gwkp_env%ngroups
450 n_stored_q = (n_k + i_group_size - 1)/i_group_size
451 persistent_bytes =
complex_bytes*(real(n_stored_q,
dp)*real(n_grid,
dp)*real(n_aux,
dp) + &
452 REAL(n_aux,
dp)**2*
REAL(n_stored_q*n_local_time,
dp))
453 n_pairs = real(ceiling(real(n_grid,
dp)**2/real(i_group_size,
dp), kind=
int_8),
dp)
459 REAL((bs_env%nkp_bs_and_dos + i_group_size - 1)/i_group_size,
dp) + &
463 projection_workspace_bytes(n_grid, i_group_size, &
464 product(bs_env%kpoints_scf_desymm%nkp_grid + 2), n_ao, n_threads)) + &
466 peak_bytes = max(persistent_bytes + block_bytes, &
467 persistent_bytes - input_bytes + grid_bytes + result_bytes)
468 IF (gwkp_env%ngroups == 1) peak_bytes = grid_bytes + result_bytes
469 IF (peak_bytes <= budget_bytes)
EXIT
471 IF (i_group_size > n_world)
THEN
472 cpabort(
'Insufficient memory per MPI rank for GW self-energy time groups')
474 gwkp_env%ngroups = n_world/i_group_size
475 gwkp_env%my_group = bs_env%para_env%mepos/i_group_size
477 ALLOCATE (gwkp_env%group_env)
478 CALL gwkp_env%group_env%from_split(bs_env%para_env, gwkp_env%my_group)
479 cpassert(gwkp_env%group_env%num_pe == i_group_size)
480 IF (gwkp_env%ngroups == 1)
THEN
481 CALL timestop(handle)
484 n_local_q = count([(
modulo(iq, i_group_size) == gwkp_env%group_env%mepos, iq=1, n_k)])
485 n_local_time = (n_time - gwkp_env%my_group + gwkp_env%ngroups - 1)/gwkp_env%ngroups
486 ALLOCATE (w_group(n_local_q))
489 CALL column_env%from_split(bs_env%para_env, gwkp_env%group_env%mepos)
490 CALL gather_group_columns(bs_env, gwkp_env, column_env, i_group_size, gwkp_env%group_env%mepos, z_group)
492 DO iq =
modulo(gwkp_env%group_env%mepos - 1, i_group_size) + 1, n_k, i_group_size
493 i_root =
modulo(iq, n_world)/i_group_size
494 iq_local = iq_local + 1
495 ALLOCATE (w_group(iq_local)%values(n_aux, n_aux, n_local_time))
497 i_dest =
modulo(it - 1, gwkp_env%ngroups)
498 IF (column_env%mepos == i_root)
THEN
499 IF (i_dest == i_root)
THEN
500 it_local = (it - 1)/gwkp_env%ngroups + 1
501 w_group(iq_local)%values(:, :, it_local) = gwkp_env%W_PQ_tau((iq - 1)/n_world + 1)%values(:, :, it)
503 CALL column_env%send(gwkp_env%W_PQ_tau((iq - 1)/n_world + 1)%values(:, :, it), i_dest, 0)
505 ELSE IF (column_env%mepos == i_dest)
THEN
508 it_local = (it - 1)/gwkp_env%ngroups + 1
509 CALL column_env%recv(w_group(iq_local)%values(:, :, it_local), i_source, i_tag)
512 IF (column_env%mepos == i_root)
DEALLOCATE (gwkp_env%W_PQ_tau((iq - 1)/n_world + 1)%values)
514 CALL column_env%free()
515 CALL move_alloc(z_group, gwkp_env%Z_lP_q)
516 CALL move_alloc(w_group, gwkp_env%W_PQ_tau)
518 CALL timestop(handle)
520 END SUBROUTINE prepare_self_energy_groups
536 SUBROUTINE gather_group_columns(bs_env, gwkp_env, column_env, group_size, group_rank, Z_group, psi_group)
540 INTEGER,
INTENT(IN) :: group_size, group_rank
541 COMPLEX(KIND=dp),
ALLOCATABLE,
INTENT(OUT) :: z_group(:, :, :)
542 COMPLEX(KIND=dp),
ALLOCATABLE,
INTENT(OUT), &
543 OPTIONAL :: psi_group(:, :, :, :)
545 CHARACTER(LEN=*),
PARAMETER :: routinen =
'gather_group_columns'
547 COMPLEX(KIND=dp),
ALLOCATABLE :: psi_block(:, :, :), z_block(:, :)
548 INTEGER :: handle, i_root, ik, ik_local, iq, &
549 iq_local, n_grid, n_k, n_world
551 CALL timeset(routinen, handle)
553 n_world = bs_env%para_env%num_pe
554 n_grid = bs_env%ri_rs%n_grid_points
555 n_k = bs_env%nkp_scf_desymm
556 IF (
PRESENT(psi_group))
THEN
557 ALLOCATE (psi_group(n_grid, bs_env%n_ao, count([(
modulo(ik - 1, group_size) == group_rank, ik=1, n_k)]), &
559 ALLOCATE (psi_block(n_grid, bs_env%n_ao, bs_env%n_spin))
561 DO ik = group_rank + 1, n_k, group_size
562 i_root =
modulo(ik - 1, n_world)/group_size
563 IF (column_env%mepos == i_root) psi_block(:, :, :) = gwkp_env%psi_lm_k(:, :, (ik - 1)/n_world + 1, :)
564 CALL column_env%bcast(psi_block, i_root)
565 ik_local = ik_local + 1
566 psi_group(:, :, ik_local, :) = psi_block
568 DEALLOCATE (psi_block)
570 ALLOCATE (z_group(n_grid, bs_env%n_RI, count([(
modulo(iq, group_size) == group_rank, iq=1, n_k)])))
571 ALLOCATE (z_block(n_grid, bs_env%n_RI))
573 DO iq =
modulo(group_rank - 1, group_size) + 1, n_k, group_size
574 i_root =
modulo(iq, n_world)/group_size
575 IF (column_env%mepos == i_root) z_block(:, :) = gwkp_env%Z_lP_q(:, :, (iq - 1)/n_world + 1)
576 CALL column_env%bcast(z_block, i_root)
577 iq_local = iq_local + 1
578 z_group(:, :, iq_local) = z_block
582 CALL timestop(handle)
584 END SUBROUTINE gather_group_columns
591 SUBROUTINE compute_chi(bs_env, gwkp_env)
593 TYPE(
gwkp_type),
INTENT(INOUT),
TARGET :: gwkp_env
595 CHARACTER(LEN=*),
PARAMETER :: routinen =
'compute_chi'
597 COMPLEX(KIND=dp),
ALLOCATABLE :: chi_grid_local_q(:, :, :), &
598 chi_grid_q(:, :, :), chi_q(:, :, :), &
599 g_grid_k(:, :, :), work(:, :)
600 COMPLEX(KIND=dp),
ALLOCATABLE,
TARGET :: psi_time(:, :, :, :), z_group(:, :, :)
601 COMPLEX(KIND=dp),
POINTER :: psi_values(:, :, :, :), z_time(:, :, :)
602 INTEGER :: first_pair, handle, i_group, i_needed, i_q_world, i_rank, i_root, i_size, &
603 i_source, i_t, i_tag, i_time_group, i_time_local, iq, iq_local, ispin, n_aux, n_cells, &
604 n_grid, n_groups, n_local, n_needed_local, n_pairs_local, n_q_local, n_threads, &
605 n_time_local, n_world
606 INTEGER,
ALLOCATABLE :: full_cells(:, :), needed_local(:), &
608 LOGICAL,
ALLOCATABLE :: needed(:)
609 REAL(kind=
dp) :: available_gb, budget, input_bytes, live_bytes, n_pair_max, n_q_max, peak, &
610 q_bytes, rows_bytes, step_start, tau, time_bytes
611 REAL(kind=
dp),
ALLOCATABLE :: chi_grid_r(:, :, :), g_occ_r(:, :, :), &
612 qpoints(:, :), step_times(:)
617 CALL timeset(routinen, handle)
619 cpassert(gwkp_env%ngroups == 1 .AND. gwkp_env%my_group == 0)
621 n_grid = bs_env%ri_rs%n_grid_points
623 n_world = gwkp_env%group_env%num_pe
624 ALLOCATE (qpoints(3, bs_env%nkp_scf_desymm))
625 qpoints(:, :) = bs_env%kpoints_chi_eps_W%xkp(:, 1:bs_env%nkp_scf_desymm)
627 CALL minus_q_partners(qpoints, q_partner)
628 ALLOCATE (needed(bs_env%nkp_scf_desymm))
629 needed(:) = [(q_partner(iq) >= iq, iq=1, bs_env%nkp_scf_desymm)]
631 budget = budget_after_reserve(available_gb)
632 n_cells =
SIZE(full_cells, 2)
635 DO i_size = min(2, max(1, n_world/2)), n_world
636 IF (
modulo(n_world, i_size) /= 0) cycle
637 n_groups = n_world/i_size
638 IF (n_groups > bs_env%num_time_freq_points) cycle
639 i_rank =
modulo(gwkp_env%group_env%mepos, i_size)
640 i_group = gwkp_env%group_env%mepos/i_size
641 n_time_local = (bs_env%num_time_freq_points + n_groups - 1 - i_group)/n_groups
642 n_pair_max = real(int(n_grid,
int_8)**2*(i_rank + 1)/i_size - int(n_grid,
int_8)**2*i_rank/i_size,
dp)
643 n_q_max = real(count([(
modulo(iq, i_size) == i_rank .AND. needed(iq), &
644 iq=1, bs_env%nkp_scf_desymm)]),
dp)
646 IF (n_groups > 1)
THEN
648 input_bytes = input_bytes + &
650 REAL((bs_env%nkp_scf_desymm + i_size - 1 - i_rank)/i_size,
dp)
655 rows_bytes = n_pair_max*
complex_bytes*real(bs_env%nkp_scf_desymm + n_cells,
dp)
658 live_bytes = max(rows_bytes + 2.0_dp*
complex_bytes*real(n_grid,
dp)**2 + &
663 max(1.0_dp, min(real(n_threads,
dp), n_q_max)))
664 peak = input_bytes + time_bytes +
complex_bytes*real(n_aux,
dp)**2*n_q_max + &
665 max(live_bytes,
complex_bytes*real(n_aux,
dp)**2*real(bs_env%num_time_freq_points,
dp)) + &
666 2.0_dp*
complex_bytes*real(n_threads*bs_env%nkp_scf_desymm,
dp) + library_bytes
667 CALL gwkp_env%group_env%max(peak)
668 IF (peak <= budget)
EXIT
670 IF (i_size > n_world)
THEN
671 cpabort(
"Insufficient memory per MPI rank for GW time groups")
673 n_groups = n_world/i_size
674 i_group = gwkp_env%group_env%mepos/i_size
676 CALL chi_env%from_split(gwkp_env%group_env, i_group)
677 CALL column_env%from_split(gwkp_env%group_env, chi_env%mepos)
678 IF (n_groups > 1)
THEN
679 CALL gather_group_columns(bs_env, gwkp_env, column_env, i_size, chi_env%mepos, z_group, psi_time)
680 psi_values => psi_time
683 psi_values => gwkp_env%psi_lm_k
684 z_time => gwkp_env%Z_lP_q
686 n_time_local = (bs_env%num_time_freq_points + n_groups - 1 - i_group)/n_groups
687 CALL block_range(n_grid**2, chi_env%mepos, chi_env%num_pe, first_pair, n_pairs_local)
688 n_q_local = count([(
modulo(iq, chi_env%num_pe) == chi_env%mepos, iq=1, bs_env%nkp_scf_desymm)])
689 ALLOCATE (chi_q(n_aux, n_aux, n_q_local), needed_local(n_q_local))
690 ALLOCATE (chi_partial(n_q_local))
693 DO iq =
modulo(chi_env%mepos - 1, i_size) + 1,
SIZE(qpoints, 2), i_size
694 iq_local = iq_local + 1
695 IF (.NOT. needed(iq)) cycle
696 n_needed_local = n_needed_local + 1
697 needed_local(n_needed_local) = iq_local
698 ALLOCATE (chi_partial(iq_local)%values(n_aux, n_aux, n_time_local), source=
z_zero)
701 ALLOCATE (step_times(bs_env%num_time_freq_points), source=0.0_dp)
702 DO i_t = i_group + 1, bs_env%num_time_freq_points, n_groups
704 tau = bs_env%time_frequency_grid%imaginary_time(i_t)
706 DO ispin = 1, bs_env%n_spin
707 ALLOCATE (g_grid_k(n_pairs_local, 1, bs_env%nkp_scf_desymm))
708 ALLOCATE (g_occ_r(n_pairs_local, 1, n_cells))
709 ALLOCATE (chi_grid_r, mold=g_occ_r)
710 CALL build_green_pairs(bs_env, psi_values(:, :, :, ispin), chi_env, tau, ispin, .true., g_grid_k)
711 CALL gw_k_grid_to_real_cells(g_grid_k, bs_env%kpoints_scf_desymm%xkp, &
712 bs_env%kpoints_scf_desymm%nkp_grid, full_cells, &
714 CALL build_green_pairs(bs_env, psi_values(:, :, :, ispin), chi_env, tau, ispin, .false., g_grid_k)
715 CALL gw_k_grid_to_real_cells(g_grid_k, bs_env%kpoints_scf_desymm%xkp, &
716 bs_env%kpoints_scf_desymm%nkp_grid, full_cells, &
718 CALL filter_full_green_cells(bs_env, chi_env, g_occ_r)
719 CALL filter_full_green_cells(bs_env, chi_env, chi_grid_r)
720 DEALLOCATE (g_grid_k)
721 chi_grid_r(:, :, :) = bs_env%spin_degeneracy*g_occ_r*chi_grid_r
723 ALLOCATE (chi_grid_q(n_pairs_local, 1, bs_env%nkp_scf_desymm))
724 CALL product_to_k_pair_centered(bs_env, full_cells, qpoints, chi_grid_r, &
725 chi_grid_q, first_pair)
726 DEALLOCATE (chi_grid_r)
728 ALLOCATE (chi_grid_local_q(n_grid, n_grid, n_needed_local))
729 CALL fft_pairs_to_q_matrices(chi_grid_q, chi_env, needed, chi_grid_local_q)
730 DEALLOCATE (chi_grid_q)
736 ALLOCATE (work(n_grid, n_aux))
738 DO i_needed = 1, n_needed_local
739 iq_local = needed_local(i_needed)
740 CALL zgemm(
'N',
'N', n_grid, n_aux, n_grid,
z_one, &
741 chi_grid_local_q(:, :, i_needed), n_grid, &
742 z_time(:, :, iq_local), n_grid,
z_zero, work, n_grid)
743 CALL zgemm(
'C',
'N', n_aux, n_aux, n_grid,
z_one, &
744 z_time(:, :, iq_local), n_grid, work, n_grid,
z_one, &
745 chi_q(:, :, iq_local), n_aux)
750 DEALLOCATE (chi_grid_local_q)
752 i_time_local = (i_t - 1)/n_groups + 1
753 DO i_needed = 1, n_needed_local
754 iq_local = needed_local(i_needed)
755 chi_partial(iq_local)%values(:, :, i_time_local) = chi_q(:, :, iq_local)
757 IF (chi_env%mepos == 0) step_times(i_t) =
m_walltime() - step_start
760 CALL bs_env%para_env%sum(step_times)
761 IF (bs_env%unit_nr > 0)
THEN
762 WRITE (bs_env%unit_nr,
'(A)')
' '
763 DO i_t = 1, bs_env%num_time_freq_points
764 WRITE (bs_env%unit_nr,
'(T2,A,I3,A,I0,T57,A,T71,F10.1,A)') &
765 'GW χ(iτ) point ', i_t,
' / ', bs_env%num_time_freq_points, &
766 'Exec. time:', step_times(i_t),
' s'
770 DEALLOCATE (step_times)
772 IF (
ALLOCATED(psi_time))
DEALLOCATE (psi_time)
773 n_local = count([(
modulo(iq, n_world) == gwkp_env%group_env%mepos, iq=1, bs_env%nkp_scf_desymm)])
774 ALLOCATE (gwkp_env%chi_q_frequency(n_local))
776 DO iq =
modulo(chi_env%mepos - 1, i_size) + 1, bs_env%nkp_scf_desymm, i_size
777 iq_local = iq_local + 1
778 IF (.NOT. needed(iq)) cycle
779 i_root =
modulo(iq, n_world)/i_size
780 i_q_world = (iq - 1)/n_world + 1
781 IF (column_env%mepos == i_root)
THEN
782 ALLOCATE (gwkp_env%chi_q_frequency(i_q_world)%values(n_aux, n_aux, &
783 bs_env%num_time_freq_points))
787 DO i_t = 1, bs_env%num_time_freq_points
788 i_time_group =
modulo(i_t - 1, n_groups)
789 i_time_local = (i_t - 1)/n_groups + 1
790 IF (column_env%mepos == i_root)
THEN
791 IF (i_time_group == i_root)
THEN
792 gwkp_env%chi_q_frequency(i_q_world)%values(:, :, i_t) = &
793 chi_partial(iq_local)%values(:, :, i_time_local)
795 i_source = i_time_group
797 CALL column_env%recv(gwkp_env%chi_q_frequency(i_q_world)%values(:, :, i_t), i_source, i_tag)
799 ELSE IF (column_env%mepos == i_time_group)
THEN
800 CALL column_env%send(chi_partial(iq_local)%values(:, :, i_time_local), i_root, 0)
803 IF (column_env%mepos == i_root)
THEN
804 CALL cosine_transform_ri_q(gwkp_env%chi_q_frequency(i_q_world), &
805 bs_env%time_frequency_grid%cosine_time_to_frequency)
807 DEALLOCATE (chi_partial(iq_local)%values)
809 DEALLOCATE (chi_partial)
811 IF (
ALLOCATED(z_group))
DEALLOCATE (z_group)
812 CALL column_env%free()
814 DEALLOCATE (chi_q, full_cells, needed, needed_local, q_partner, qpoints)
816 CALL timestop(handle)
818 END SUBROUTINE compute_chi
828 SUBROUTINE compute_metric_coulomb_factor(bs_env, qs_env, gwkp_env)
831 TYPE(
gwkp_type),
INTENT(INOUT) :: gwkp_env
833 CHARACTER(LEN=*),
PARAMETER :: routinen =
'compute_metric_coulomb_factor'
835 COMPLEX(KIND=dp),
ALLOCATABLE :: charge(:), charge_hat(:), m_inv(:, :), m_ref(:, :, :), &
836 m_zero(:, :), u_pp(:, :), v_ref(:, :, :), v_sqrt(:, :), x0(:, :), x_coef(:, :)
837 INTEGER :: handle, ikp, ilocal, n_ref, n_ri, nkp, &
839 INTEGER,
ALLOCATABLE :: metric_cells(:, :)
842 CALL timeset(routinen, handle)
846 IF (bs_env%auto_ri%enabled) n_ref = sum(bs_env%auto_ri%sizes_ref_RI)
847 nkp = bs_env%nkp_scf_desymm
848 cpassert(bs_env%nkp_chi_eps_W_orig == nkp)
849 nkp_local = count([(
modulo(ikp, bs_env%para_env%num_pe) == &
850 bs_env%para_env%mepos, ikp=1, nkp)])
851 ALLOCATE (m_ref(n_ref, n_ref, nkp_local), v_ref(n_ref, n_ref, nkp_local), source=
z_zero)
852 ALLOCATE (gwkp_env%metric_coulomb_factor(n_ri, n_ri, nkp_local), m_inv(n_ri, n_ri), v_sqrt(n_ri, n_ri))
854 0.0_dp, bs_env, qs_env, reference_basis=bs_env%auto_ri%enabled)
855 CALL ri_2c_lattice_to_owned_q(fm_metric, metric_cells, &
856 bs_env%kpoints_chi_eps_W%xkp(1:3, 1:nkp), &
857 bs_env%kpoints_chi_eps_W%nkp_grid, m_ref)
860 v_ref(:, :, :) = m_ref
862 bs_env%ri_metric%omega, 1, nkp)
863 ALLOCATE (m_zero(n_ref, n_ref), charge(n_ref), charge_hat(n_ri))
867 DEALLOCATE (metric_cells)
869 IF (bs_env%auto_ri%enabled)
THEN
870 m_inv(:, :) = matmul(conjg(transpose(u_pp)), matmul(m_zero, u_pp))
871 charge_hat(:) = matmul(conjg(transpose(u_pp)), charge)
874 charge_hat(:) = charge
876 DEALLOCATE (m_zero, charge)
877 charge_hat(:) = charge_hat/sqrt(real(dot_product(charge_hat, charge_hat),
dp))
882 CALL compute_charge_leak_q0(bs_env, gwkp_env, matmul(m_inv, charge_hat), x0)
883 ALLOCATE (x_coef(n_ri,
SIZE(x0, 2)))
884 x_coef(:, :) = matmul(m_inv, x0)
886 ALLOCATE (gwkp_env%leak_e(n_ri, nkp_local), gwkp_env%leak_x(n_ri,
SIZE(x_coef, 2), nkp_local))
887 DO ilocal = 1, nkp_local
888 IF (bs_env%auto_ri%enabled)
THEN
889 m_inv(:, :) = matmul(conjg(transpose(u_pp)), matmul(m_ref(:, :, ilocal), u_pp))
890 v_sqrt(:, :) = matmul(conjg(transpose(u_pp)), matmul(v_ref(:, :, ilocal), u_pp))
892 m_inv(:, :) = m_ref(:, :, ilocal)
893 v_sqrt(:, :) = v_ref(:, :, ilocal)
895 gwkp_env%leak_e(:, ilocal) = matmul(m_inv, charge_hat)
896 gwkp_env%leak_x(:, :, ilocal) = matmul(m_inv, x_coef)
899 gwkp_env%metric_coulomb_factor(:, :, ilocal) = matmul(m_inv, v_sqrt)
901 DEALLOCATE (m_ref, v_ref, m_inv, v_sqrt, charge_hat, x_coef)
902 IF (
ALLOCATED(u_pp))
DEALLOCATE (u_pp)
904 CALL timestop(handle)
906 END SUBROUTINE compute_metric_coulomb_factor
918 SUBROUTINE compute_charge_leak_q0(bs_env, gwkp_env, v0, X0)
920 TYPE(
gwkp_type),
INTENT(INOUT) :: gwkp_env
921 COMPLEX(KIND=dp),
INTENT(IN) :: v0(:)
922 COMPLEX(KIND=dp),
ALLOCATABLE,
INTENT(OUT) :: x0(:, :)
924 CHARACTER(LEN=*),
PARAMETER :: routinen =
'compute_charge_leak_q0'
926 COMPLEX(KIND=dp),
ALLOCATABLE :: cross(:, :), g0(:), m(:, :), psi(:, :), &
927 t_tau(:, :), work(:, :), x_tau(:, :), &
929 INTEGER :: a, handle, i, ikp, ispin, j_w, n_ao, &
930 n_grid, n_occ, n_t, n_vir, nkp, &
932 REAL(kind=
dp) :: prefactor, x
933 REAL(kind=
dp),
ALLOCATABLE :: l_tau(:)
935 CALL timeset(routinen, handle)
937 n_grid = bs_env%ri_rs%n_grid_points
938 n_ao =
SIZE(gwkp_env%psi_lm_k, 2)
939 nkp = bs_env%nkp_scf_desymm
940 n_t = bs_env%num_time_freq_points
941 num_pe = bs_env%para_env%num_pe
942 ALLOCATE (g0(n_grid), psi(n_grid, n_ao), work(n_grid, n_ao), t_tau(n_grid, n_t), l_tau(n_t))
943 g0(:) = matmul(gwkp_env%Z_lP_zero(:, 2:, 1), v0)
946 DO ispin = 1, bs_env%n_spin
947 n_occ = bs_env%n_occ(ispin)
949 IF (n_occ == 0 .OR. n_vir == 0) cycle
950 ALLOCATE (m(n_occ, n_vir), cross(n_occ, n_vir), y(n_grid, n_occ))
952 IF (
modulo(ikp - 1, num_pe) /= bs_env%para_env%mepos) cycle
953 psi(:, :) = gwkp_env%psi_lm_k(:, :, (ikp - 1)/num_pe + 1, ispin)
955 work(:, i) = conjg(g0)*psi(:, i)
957 m(:, :) = matmul(transpose(work(:, 1:n_occ)), conjg(psi(:, n_occ + 1:n_ao)))
962 x = bs_env%time_frequency_grid%imaginary_time(t)* &
963 (gwkp_env%eigenvalues_G(n_occ + a, ikp, ispin) - gwkp_env%eigenvalues_G(i, ikp, ispin))
964 IF (x < 700.0_dp)
THEN
965 cross(i, a) = conjg(m(i, a))*exp(-x)
966 l_tau(t) = l_tau(t) + abs(m(i, a))**2*exp(-x)
970 y(:, :) = matmul(conjg(psi(:, n_occ + 1:n_ao)), transpose(cross))
971 t_tau(:, t) = t_tau(:, t) + sum(psi(:, 1:n_occ)*y, dim=2)
974 DEALLOCATE (m, cross, y)
976 CALL bs_env%para_env%sum(t_tau)
977 CALL bs_env%para_env%sum(l_tau)
978 prefactor = bs_env%spin_degeneracy/real(nkp,
dp)
979 ALLOCATE (x_tau(bs_env%n_RI, n_t))
980 x_tau(:, :) = prefactor*matmul(conjg(transpose(gwkp_env%Z_lP_zero(:, 2:, 1))), t_tau)
981 ALLOCATE (x0(bs_env%n_RI, n_t), source=
z_zero)
982 ALLOCATE (gwkp_env%leak_l0(n_t), source=0.0_dp)
985 x0(:, j_w) = x0(:, j_w) + bs_env%time_frequency_grid%cosine_time_to_frequency(j_w, t)*x_tau(:, t)
986 gwkp_env%leak_l0(j_w) = gwkp_env%leak_l0(j_w) + &
987 bs_env%time_frequency_grid%cosine_time_to_frequency(j_w, t)*prefactor*l_tau(t)
990 DEALLOCATE (g0, psi, work, l_tau, t_tau, x_tau)
992 CALL timestop(handle)
994 END SUBROUTINE compute_charge_leak_q0
1001 SUBROUTINE compute_sigma_x_from_v(bs_env, gwkp_env)
1003 TYPE(
gwkp_type),
INTENT(INOUT),
TARGET :: gwkp_env
1005 CHARACTER(LEN=*),
PARAMETER :: routinen =
'compute_Sigma_x_from_V'
1007 COMPLEX(KIND=dp),
ALLOCATABLE :: g_grid_k(:, :, :), head_cell_factor(:), &
1008 q_matrices(:, :, :), zk(:, :)
1009 INTEGER :: first_pair, handle, iq, iq_local, ispin, &
1010 n_grid, n_pairs_local, n_q_local, n_ri
1011 INTEGER,
ALLOCATABLE :: full_cells(:, :)
1012 REAL(kind=
dp) :: head_metric_zero
1013 REAL(kind=
dp),
ALLOCATABLE :: qpoints(:, :), sigma_grid_r(:, :, :), &
1016 CALL timeset(routinen, handle)
1018 ALLOCATE (gwkp_env%sigma_x_bands(bs_env%n_ao, bs_env%nkp_bs_and_DOS, bs_env%n_spin))
1019 n_grid = bs_env%ri_rs%n_grid_points
1021 CALL block_range(n_grid**2, bs_env%para_env%mepos, bs_env%para_env%num_pe, first_pair, n_pairs_local)
1022 n_q_local =
SIZE(gwkp_env%Z_lP_q, 3)
1023 IF (
SIZE(gwkp_env%Z_lP_zero, 2) /= bs_env%n_RI + 1 .OR.
SIZE(gwkp_env%Z_lP_zero, 3) /= 1)
THEN
1024 cpabort(
"Periodic RI-RS GW requires the direct Gamma auxiliary fit")
1026 ALLOCATE (qpoints(3, bs_env%nkp_scf_desymm))
1027 qpoints(:, :) = bs_env%kpoints_chi_eps_W%xkp(:, 1:bs_env%nkp_scf_desymm)
1028 cpassert(
SIZE(gwkp_env%Z_lP_q, 2) == bs_env%n_RI)
1029 cpassert(
ALLOCATED(gwkp_env%metric_coulomb_factor))
1031 ALLOCATE (q_matrices(n_grid, n_grid, n_q_local))
1035 ALLOCATE (zk(n_grid, n_ri))
1037 DO iq_local = 1, n_q_local
1038 CALL zgemm(
'N',
'N', n_grid, n_ri, n_ri,
z_one, gwkp_env%Z_lP_q(:, :, iq_local), n_grid, &
1039 gwkp_env%metric_coulomb_factor(:, :, iq_local), n_ri,
z_zero, zk, n_grid)
1040 CALL zgemm(
'N',
'C', n_grid, n_grid, n_ri,
z_one, zk, n_grid, zk, n_grid, &
1041 z_zero, q_matrices(:, :, iq_local), n_grid)
1046 DEALLOCATE (gwkp_env%metric_coulomb_factor)
1047 ALLOCATE (g_grid_k(n_pairs_local, 1, bs_env%nkp_scf_desymm))
1048 CALL q_matrices_to_fft_pairs(q_matrices, bs_env%para_env, g_grid_k)
1049 DEALLOCATE (q_matrices)
1051 ALLOCATE (v_grid_r(n_pairs_local, 1,
SIZE(full_cells, 2)))
1052 CALL gw_k_grid_to_real_cells(g_grid_k, qpoints, bs_env%kpoints_scf_desymm%nkp_grid, &
1053 full_cells, v_grid_r)
1056 DO iq = 1,
SIZE(full_cells, 2)
1057 IF (all(bs_env%periodic == [1, 1, 0]))
THEN
1059 twopi/head_metric_zero**2*head_cell_factor(iq), &
1060 gwkp_env%Z_lP_zero(:, 1, 1), first_pair, v_grid_r)
1063 fourpi/head_metric_zero**2*head_cell_factor(iq), &
1064 gwkp_env%Z_lP_zero(:, 1, 1), first_pair, v_grid_r)
1067 DEALLOCATE (head_cell_factor)
1069 ALLOCATE (sigma_grid_r, mold=v_grid_r)
1070 DO ispin = 1, bs_env%n_spin
1071 CALL build_green_pairs(bs_env, gwkp_env%band_orbitals(:, :, :, ispin), bs_env%para_env, &
1072 0.0_dp, ispin, .true., g_grid_k)
1073 CALL gw_k_grid_to_real_cells(g_grid_k, bs_env%kpoints_scf_desymm%xkp, &
1074 bs_env%kpoints_scf_desymm%nkp_grid, full_cells, sigma_grid_r)
1075 sigma_grid_r(:, :, :) = -sigma_grid_r*v_grid_r
1076 CALL self_energy_on_mesh(bs_env, full_cells, sigma_grid_r, first_pair, g_grid_k)
1078 CALL self_energy_pairs_to_bloch(bs_env, g_grid_k, sigma_grid_r, first_pair, bs_env%para_env, &
1079 gwkp_env%band_orbitals(:, :, :, ispin), &
1080 gwkp_env%sigma_x_bands(:, :, ispin))
1083 DEALLOCATE (full_cells, g_grid_k, qpoints, sigma_grid_r, v_grid_r)
1085 CALL timestop(handle)
1087 END SUBROUTINE compute_sigma_x_from_v
1096 TYPE(
gwkp_type),
INTENT(INOUT),
TARGET :: gwkp_env
1098 CHARACTER(LEN=*),
PARAMETER :: routinen =
'compute_Sigma_c_from_W_PQ'
1100 COMPLEX(KIND=dp),
ALLOCATABLE :: g_grid_k(:, :, :)
1101 INTEGER :: first_pair, handle, i_group, i_t, ispin, &
1102 n_grid, n_pairs_local
1103 INTEGER,
ALLOCATABLE :: full_cells(:, :)
1104 REAL(kind=
dp) :: step_elapsed, step_start, tau
1105 REAL(kind=
dp),
ALLOCATABLE :: qpoints(:, :), sigma_band(:, :), sigma_grid_r(:, :, :), &
1106 sigma_result_buffer(:), step_times(:), w_grid_r(:, :, :)
1108 CALL timeset(routinen, handle)
1110 cpassert(
ALLOCATED(gwkp_env%band_orbitals))
1111 IF (
ALLOCATED(gwkp_env%sigma_c_bands))
DEALLOCATE (gwkp_env%sigma_c_bands)
1113 n_grid = bs_env%ri_rs%n_grid_points
1114 CALL block_range(n_grid**2, gwkp_env%group_env%mepos, gwkp_env%group_env%num_pe, &
1115 first_pair, n_pairs_local)
1116 ALLOCATE (g_grid_k(n_pairs_local, 1, bs_env%nkp_scf_desymm))
1117 ALLOCATE (w_grid_r(n_pairs_local, 1,
SIZE(full_cells, 2)))
1118 ALLOCATE (sigma_grid_r, mold=w_grid_r)
1119 ALLOCATE (qpoints(3, bs_env%nkp_scf_desymm))
1120 qpoints(:, :) = bs_env%kpoints_chi_eps_W%xkp(:, 1:bs_env%nkp_scf_desymm)
1121 ALLOCATE (sigma_band(bs_env%n_ao, bs_env%nkp_bs_and_DOS))
1122 ALLOCATE (gwkp_env%sigma_c_bands(bs_env%n_ao, bs_env%nkp_bs_and_DOS, &
1123 bs_env%num_time_freq_points, 2, bs_env%n_spin))
1124 ALLOCATE (step_times(bs_env%num_time_freq_points), source=0.0_dp)
1125 gwkp_env%sigma_c_bands = 0.0_dp
1127 DO i_t = gwkp_env%my_group + 1, bs_env%num_time_freq_points, gwkp_env%ngroups
1129 i_group = (i_t - gwkp_env%my_group - 1)/gwkp_env%ngroups + 1
1130 CALL project_auxiliary_time_q_to_fft_pairs(gwkp_env%Z_lP_q, &
1131 gwkp_env%W_PQ_tau, i_group, &
1132 gwkp_env%group_env, g_grid_k)
1134 CALL gw_k_grid_to_real_cells(g_grid_k, qpoints, &
1135 bs_env%kpoints_scf_desymm%nkp_grid, full_cells, &
1138 gwkp_env%Z_lP_zero(:, 1, 1), first_pair, w_grid_r)
1139 CALL truncate_grid_w_by_pair_distance_pairs(bs_env, full_cells, first_pair, w_grid_r)
1140 tau = bs_env%time_frequency_grid%imaginary_time(i_t)
1141 DO ispin = 1, bs_env%n_spin
1142 CALL build_green_pairs(bs_env, gwkp_env%band_orbitals(:, :, :, ispin), gwkp_env%group_env, &
1143 tau, ispin, .true., g_grid_k)
1144 CALL gw_k_grid_to_real_cells(g_grid_k, bs_env%kpoints_scf_desymm%xkp, &
1145 bs_env%kpoints_scf_desymm%nkp_grid, full_cells, sigma_grid_r)
1146 CALL filter_full_green_cells(bs_env, gwkp_env%group_env, sigma_grid_r)
1147 sigma_grid_r(:, :, :) = -sigma_grid_r*w_grid_r
1148 CALL self_energy_on_mesh(bs_env, full_cells, sigma_grid_r, first_pair, g_grid_k)
1149 CALL self_energy_pairs_to_bloch(bs_env, g_grid_k, sigma_grid_r, first_pair, gwkp_env%group_env, &
1150 gwkp_env%band_orbitals(:, :, :, ispin), sigma_band)
1151 IF (gwkp_env%group_env%mepos == 0) gwkp_env%sigma_c_bands(:, :, i_t, 2, ispin) = sigma_band
1153 CALL build_green_pairs(bs_env, gwkp_env%band_orbitals(:, :, :, ispin), gwkp_env%group_env, &
1154 tau, ispin, .false., g_grid_k)
1155 CALL gw_k_grid_to_real_cells(g_grid_k, bs_env%kpoints_scf_desymm%xkp, &
1156 bs_env%kpoints_scf_desymm%nkp_grid, full_cells, sigma_grid_r)
1157 CALL filter_full_green_cells(bs_env, gwkp_env%group_env, sigma_grid_r)
1158 sigma_grid_r(:, :, :) = sigma_grid_r*w_grid_r
1159 CALL self_energy_on_mesh(bs_env, full_cells, sigma_grid_r, first_pair, g_grid_k)
1160 CALL self_energy_pairs_to_bloch(bs_env, g_grid_k, sigma_grid_r, first_pair, gwkp_env%group_env, &
1161 gwkp_env%band_orbitals(:, :, :, ispin), sigma_band)
1162 IF (gwkp_env%group_env%mepos == 0) gwkp_env%sigma_c_bands(:, :, i_t, 1, ispin) = sigma_band
1165 IF (gwkp_env%group_env%mepos == 0) step_times(i_t) = step_elapsed
1168 CALL bs_env%para_env%sum(step_times)
1169 IF (bs_env%unit_nr > 0)
THEN
1170 DO i_t = 1, bs_env%num_time_freq_points
1171 WRITE (bs_env%unit_nr,
'(T2,A,I3,A,I0,T57,A,T71,F10.1,A)') &
1172 'GW Σ_c(iτ) point ', i_t,
' / ', bs_env%num_time_freq_points, &
1173 'Exec. time:', step_times(i_t),
' s'
1178 ALLOCATE (sigma_result_buffer(
SIZE(gwkp_env%sigma_c_bands)))
1179 sigma_result_buffer(:) = reshape(gwkp_env%sigma_c_bands, [
SIZE(gwkp_env%sigma_c_bands)])
1180 CALL bs_env%para_env%sum(sigma_result_buffer)
1181 gwkp_env%sigma_c_bands(:, :, :, :, :) = reshape(sigma_result_buffer, shape(gwkp_env%sigma_c_bands))
1183 DEALLOCATE (full_cells, g_grid_k, qpoints, &
1184 sigma_band, sigma_result_buffer, sigma_grid_r, &
1185 step_times, w_grid_r)
1187 CALL timestop(handle)
1198 SUBROUTINE filter_full_green_cells(bs_env, para_env, G_R)
1201 REAL(kind=
dp),
INTENT(INOUT) :: g_r(:, :, :)
1203 INTEGER :: i_cell, n_cells
1204 REAL(kind=
dp) :: atom_block_count
1205 REAL(kind=
dp),
ALLOCATABLE :: norm_squared(:)
1207 cpassert(bs_env%n_atom > 0)
1208 n_cells =
SIZE(g_r, 3)
1209 atom_block_count = real(bs_env%n_atom,
dp)**2
1210 ALLOCATE (norm_squared(n_cells))
1211 DO i_cell = 1, n_cells
1212 norm_squared(i_cell) = sum(g_r(:, :, i_cell)**2)
1214 CALL para_env%sum(norm_squared)
1215 DO i_cell = 1, n_cells
1216 IF (sqrt(norm_squared(i_cell))/atom_block_count < bs_env%eps_filter)
THEN
1217 g_r(:, :, i_cell) = 0.0_dp
1220 DEALLOCATE (norm_squared)
1221 END SUBROUTINE filter_full_green_cells
1230 SUBROUTINE truncate_grid_w_by_pair_distance_pairs(bs_env, cells, first_pair, W_grid_R)
1232 INTEGER,
DIMENSION(:, :),
INTENT(IN) :: cells
1233 INTEGER,
INTENT(IN) :: first_pair
1234 REAL(kind=
dp),
DIMENSION(:, :, :),
INTENT(INOUT) :: w_grid_r
1236 INTEGER :: i_l, i_local, i_lp, i_pair, i_r, n_grid
1237 REAL(kind=
dp) :: cell_index(3), cutoff_squared, &
1238 displacement(3), lattice_vector(3)
1240 IF (bs_env%ri_rs%cutoff_radius_v_w <= 0.0_dp)
RETURN
1241 cpassert(
ALLOCATED(bs_env%ri_rs%grid_points))
1242 cpassert(
SIZE(w_grid_r, 2) == 1)
1243 cpassert(
SIZE(cells, 2) ==
SIZE(w_grid_r, 3))
1244 cutoff_squared = bs_env%ri_rs%cutoff_radius_v_w**2
1245 n_grid = bs_env%ri_rs%n_grid_points
1249 DO i_r = 1,
SIZE(cells, 2)
1250 cell_index(:) = real(cells(:, i_r),
dp)
1251 lattice_vector(:) = matmul(bs_env%hmat, cell_index)
1252 DO i_local = 1,
SIZE(w_grid_r, 1)
1253 i_pair = first_pair + i_local - 1
1254 i_l =
modulo(i_pair - 1, n_grid) + 1
1255 i_lp = (i_pair - 1)/n_grid + 1
1256 displacement = bs_env%ri_rs%grid_points(:, i_l) - &
1257 bs_env%ri_rs%grid_points(:, i_lp) - lattice_vector
1258 IF (sum(displacement**2) > cutoff_squared) w_grid_r(i_local, 1, i_r) = 0.0_dp
1263 END SUBROUTINE truncate_grid_w_by_pair_distance_pairs
1277 SUBROUTINE build_green_pairs(bs_env, orbitals, env, tau, ispin, occupied, G_pairs)
1279 COMPLEX(KIND=dp),
INTENT(IN) :: orbitals(:, :, :)
1281 REAL(kind=
dp),
INTENT(IN) :: tau
1282 INTEGER,
INTENT(IN) :: ispin
1283 LOGICAL,
INTENT(IN) :: occupied
1284 COMPLEX(KIND=dp),
INTENT(OUT) :: g_pairs(:, :, :)
1286 CHARACTER(LEN=*),
PARAMETER :: routinen =
'build_green_pairs'
1288 COMPLEX(KIND=dp),
ALLOCATABLE :: green(:), received(:), scaled_coeff(:, :)
1289 INTEGER :: first_band, handle, i_band, i_col, &
1290 i_first, i_rank, ikp, n_bands, n_grid, &
1291 n_k, n_local, n_rank
1292 INTEGER,
ALLOCATABLE :: pair_counts(:), pair_displs(:), &
1293 recv_counts(:), recv_displs(:), &
1295 REAL(kind=
dp) :: tau_e
1298 CALL timeset(routinen, handle)
1300 gwkp_env => bs_env%gwkp_env
1302 n_grid = bs_env%ri_rs%n_grid_points
1303 n_k = bs_env%nkp_scf_desymm
1304 n_local =
SIZE(g_pairs, 1)
1307 n_bands = bs_env%n_occ(ispin)
1308 IF (.NOT. occupied)
THEN
1309 first_band = n_bands + 1
1310 n_bands = bs_env%n_ao - n_bands
1312 cpassert(n_bands >= 0 .AND. n_bands <= bs_env%n_ao)
1313 IF (n_bands == 0)
THEN
1315 CALL timestop(handle)
1318 CALL grid_pair_blocks(n_grid, n_rank, pair_counts, pair_displs)
1319 ALLOCATE (green(n_grid**2), received(n_local*n_rank), scaled_coeff(n_grid, n_bands), &
1320 recv_counts(0:n_rank - 1), recv_displs(0:n_rank - 1), send_counts(0:n_rank - 1))
1321 recv_displs(:) = [(i_rank*n_local, i_rank=0, n_rank - 1)]
1324 DO i_first = 1, n_k, n_rank
1325 ikp = i_first + env%mepos
1327 IF (ikp <= n_k)
THEN
1328 scaled_coeff(:, :) = orbitals(:, first_band:first_band + n_bands - 1, (ikp - 1)/n_rank + 1)
1329 DO i_band = 1, n_bands
1330 tau_e = abs(0.5_dp*tau*(gwkp_env%eigenvalues_G(first_band + i_band - 1, ikp, ispin) - &
1331 bs_env%e_fermi(ispin)))
1332 IF (tau_e < bs_env%stabilize_exp)
THEN
1333 scaled_coeff(:, i_band) = scaled_coeff(:, i_band)*exp(-tau_e)
1335 scaled_coeff(:, i_band) =
z_zero
1340 DO i_col = 1, n_grid, column_block_cols
1341 CALL zgemm(
'N',
'C', n_grid, min(column_block_cols, n_grid - i_col + 1), n_bands,
z_one, &
1342 scaled_coeff, n_grid, scaled_coeff(i_col, 1), n_grid,
z_zero, &
1343 green(1 + (i_col - 1)*n_grid), n_grid)
1346 send_counts(:) = pair_counts
1348 DO i_rank = 0, n_rank - 1
1349 recv_counts(i_rank) = merge(n_local, 0, i_first + i_rank <= n_k)
1351 CALL env%alltoall(green, send_counts, pair_displs, received, recv_counts, recv_displs)
1352 DO i_rank = 0, min(n_rank, n_k - i_first + 1) - 1
1353 g_pairs(:, 1, i_first + i_rank) = received(i_rank*n_local + 1:(i_rank + 1)*n_local)
1357 CALL timestop(handle)
1359 END SUBROUTINE build_green_pairs
1369 SUBROUTINE grid_pair_blocks(n_grid, n_rank, counts, displs)
1370 INTEGER,
INTENT(IN) :: n_grid, n_rank
1371 INTEGER,
ALLOCATABLE,
INTENT(OUT) :: counts(:), displs(:)
1375 ALLOCATE (counts(0:n_rank - 1), displs(0:n_rank - 1))
1376 DO i_rank = 0, n_rank - 1
1377 CALL block_range(n_grid**2, i_rank, n_rank, displs(i_rank), counts(i_rank))
1379 displs(:) = displs - 1
1381 END SUBROUTINE grid_pair_blocks
1389 SUBROUTINE build_all_psi_k(bs_env, phi_lmu_k, psi_lm_k)
1391 COMPLEX(KIND=dp),
DIMENSION(:, :, :),
INTENT(IN) :: phi_lmu_k
1392 COMPLEX(KIND=dp),
ALLOCATABLE,
INTENT(OUT) :: psi_lm_k(:, :, :, :)
1394 CHARACTER(LEN=*),
PARAMETER :: routinen =
'build_all_psi_k'
1396 COMPLEX(KIND=dp),
ALLOCATABLE :: mo_coeff(:, :, :, :)
1397 INTEGER :: handle, ikp_local, ispin
1399 CALL timeset(routinen, handle)
1402 ALLOCATE (psi_lm_k(bs_env%ri_rs%n_grid_points, bs_env%n_ao,
SIZE(phi_lmu_k, 3), &
1403 bs_env%n_spin), source=
z_zero)
1404 DO ispin = 1, bs_env%n_spin
1405 DO ikp_local = 1,
SIZE(mo_coeff, 3)
1406 psi_lm_k(:, :, ikp_local, ispin) = matmul(phi_lmu_k(:, :, ikp_local), mo_coeff(:, :, ikp_local, ispin))
1409 DEALLOCATE (mo_coeff)
1411 CALL timestop(handle)
1413 END SUBROUTINE build_all_psi_k
1420 SUBROUTINE build_all_phi_k(bs_env, phi_lmu_k)
1422 COMPLEX(dp),
ALLOCATABLE,
INTENT(OUT) :: phi_lmu_k(:, :, :)
1424 CHARACTER(LEN=*),
PARAMETER :: routinen =
'build_all_phi_k'
1426 INTEGER :: handle, i_r, ikp, ikp_local, n_k_local
1427 REAL(
dp),
ALLOCATABLE :: phi_r(:, :)
1429 CALL timeset(routinen, handle)
1431 n_k_local = (bs_env%nkp_scf_desymm + bs_env%para_env%num_pe - 1 - &
1432 bs_env%para_env%mepos)/bs_env%para_env%num_pe
1433 ALLOCATE (phi_lmu_k(bs_env%ri_rs%n_grid_points, bs_env%n_ao, n_k_local))
1435 IF (n_k_local > 0)
THEN
1436 ALLOCATE (phi_r(bs_env%ri_rs%n_grid_points, bs_env%n_ao))
1437 DO i_r = 1,
SIZE(bs_env%index_to_cell_3c, 2)
1440 DO ikp = bs_env%para_env%mepos + 1, bs_env%nkp_scf_desymm, bs_env%para_env%num_pe
1441 ikp_local = ikp_local + 1
1442 phi_lmu_k(:, :, ikp_local) = phi_lmu_k(:, :, ikp_local) + phi_r* &
1443 exp(
gaussi*
twopi*sum(bs_env%kpoints_scf_desymm%xkp(:, ikp)* &
1444 REAL(bs_env%index_to_cell_3c(:, i_r),
dp)))
1449 CALL timestop(handle)
1451 END SUBROUTINE build_all_phi_k
1464 SUBROUTINE ri_2c_lattice_to_owned_q(fm_R, cells, qpoints, nkp_grid, matrices_q)
1466 INTEGER,
INTENT(IN) :: cells(:, :)
1467 REAL(kind=
dp),
INTENT(IN) :: qpoints(:, :)
1468 INTEGER,
INTENT(IN) :: nkp_grid(3)
1469 COMPLEX(KIND=dp),
INTENT(OUT) :: matrices_q(:, :, :)
1471 CHARACTER(LEN=*),
PARAMETER :: routinen =
'ri_2c_lattice_to_owned_q'
1473 COMPLEX(KIND=dp),
ALLOCATABLE :: recv_buffer(:)
1474 COMPLEX(KIND=dp),
ALLOCATABLE,
TARGET :: send_buffer(:)
1475 COMPLEX(KIND=dp),
CONTIGUOUS,
POINTER :: values_q(:, :, :)
1476 INTEGER :: dest, handle, icell, icol, iq, iq_local, &
1477 irow, n_q, n_q_local, n_ri, ncols, &
1478 nprocs, nrecv, nrows, nsend, pos, &
1480 INTEGER,
ALLOCATABLE :: block_metadata(:), q_order(:), recv_counts(:), recv_displs(:), &
1481 send_counts(:), send_displs(:), source_cols(:, :), source_rows(:, :), source_sizes(:, :)
1482 INTEGER,
POINTER :: cols(:), rows(:)
1483 REAL(kind=
dp),
ALLOCATABLE :: values_r(:, :, :)
1486 CALL timeset(routinen, handle)
1488 cpassert(
SIZE(fm_r) > 0)
1489 cpassert(
SIZE(cells, 1) == 3 .AND.
SIZE(cells, 2) ==
SIZE(fm_r))
1490 cpassert(
SIZE(qpoints, 1) == 3)
1491 n_q =
SIZE(qpoints, 2)
1492 n_ri =
SIZE(matrices_q, 1)
1493 cpassert(
SIZE(matrices_q, 2) == n_ri)
1494 para_env => fm_r(1)%matrix_struct%para_env
1495 nprocs = para_env%num_pe
1496 n_q_local = count([(
modulo(iq, nprocs) == para_env%mepos, iq=1, n_q)])
1497 cpassert(
SIZE(matrices_q, 3) == n_q_local)
1498 CALL cp_fm_get_info(fm_r(1), nrow_local=nrows, ncol_local=ncols, &
1499 row_indices=rows, col_indices=cols)
1501 ALLOCATE (block_metadata(2 + 2*n_ri), source_sizes(2, 0:nprocs - 1), &
1502 source_rows(n_ri, 0:nprocs - 1), source_cols(n_ri, 0:nprocs - 1))
1503 DO source = 0, nprocs - 1
1505 IF (para_env%mepos == source)
THEN
1506 block_metadata(1:2) = [nrows, ncols]
1507 block_metadata(3:2 + nrows) = rows(1:nrows)
1508 block_metadata(3 + n_ri:2 + n_ri + ncols) = cols(1:ncols)
1510 CALL para_env%bcast(block_metadata, source)
1511 source_sizes(:, source) = block_metadata(1:2)
1512 source_rows(:, source) = block_metadata(3:2 + n_ri)
1513 source_cols(:, source) = block_metadata(3 + n_ri:2 + 2*n_ri)
1517 ALLOCATE (q_order(n_q), send_counts(0:nprocs - 1), recv_counts(0:nprocs - 1), &
1518 send_displs(0:nprocs - 1), recv_displs(0:nprocs - 1))
1520 DO dest = 0, nprocs - 1
1521 send_displs(dest) = pos*nrows*ncols
1523 IF (
modulo(iq, nprocs) /= dest) cycle
1527 send_counts(dest) = pos*nrows*ncols - send_displs(dest)
1529 nsend = n_q*nrows*ncols
1530 CALL para_env%alltoall(send_counts, recv_counts, 1)
1532 DO source = 1, nprocs - 1
1533 recv_displs(source) = recv_displs(source - 1) + recv_counts(source - 1)
1535 nrecv = recv_displs(nprocs - 1) + recv_counts(nprocs - 1)
1536 ALLOCATE (send_buffer(max(1, nsend)), recv_buffer(max(1, nrecv)))
1538 ALLOCATE (values_r(nrows, ncols,
SIZE(fm_r)))
1539 DO icell = 1,
SIZE(fm_r)
1540 values_r(:, :, icell) = fm_r(icell)%local_data(1:nrows, 1:ncols)
1542 values_q(1:nrows, 1:ncols, 1:n_q) => send_buffer(1:nsend)
1544 selected_kpoints=q_order)
1545 DEALLOCATE (values_r)
1547 CALL para_env%alltoall(send_buffer, send_counts, send_displs, &
1548 recv_buffer, recv_counts, recv_displs)
1550 DO source = 0, nprocs - 1
1551 nrows = source_sizes(1, source)
1552 ncols = source_sizes(2, source)
1553 cpassert(recv_counts(source) == nrows*ncols*n_q_local)
1554 pos = recv_displs(source)
1555 DO iq_local = 1, n_q_local
1558 matrices_q(source_rows(irow, source), source_cols(icol, source), iq_local) = &
1559 recv_buffer(pos + (icol - 1)*nrows + irow)
1562 pos = pos + nrows*ncols
1566 CALL timestop(handle)
1568 END SUBROUTINE ri_2c_lattice_to_owned_q
1576 SUBROUTINE collect_band_bloch_orbitals(bs_env, orbitals)
1578 COMPLEX(dp),
ALLOCATABLE,
INTENT(OUT) :: orbitals(:, :, :, :)
1580 CHARACTER(LEN=*),
PARAMETER :: routinen =
'collect_band_bloch_orbitals'
1582 COMPLEX(dp),
ALLOCATABLE :: coefficients(:, :, :, :), phi_k(:, :)
1583 INTEGER :: handle, i_kp, i_local, i_r, ispin, &
1585 REAL(
dp) :: available_gb, orbital_bytes
1586 REAL(
dp),
ALLOCATABLE :: phi_r(:, :)
1589 CALL timeset(routinen, handle)
1591 env => bs_env%para_env
1592 n_grid = bs_env%ri_rs%n_grid_points
1593 n_own = (bs_env%nkp_bs_and_DOS - env%mepos + env%num_pe - 1)/env%num_pe
1594 CALL collect_band_mo_coefficients(bs_env, coefficients)
1595 orbital_bytes = real(n_grid,
dp)*real(bs_env%n_ao,
dp)* &
1598 CALL env%min(available_gb)
1599 CALL env%max(orbital_bytes)
1600 IF (orbital_bytes > stage_memory_share*max(0.0_dp, available_gb)*bytes_per_gb)
THEN
1601 cpabort(
"Insufficient memory for GW band-path orbitals")
1603 ALLOCATE (phi_r(n_grid, bs_env%n_ao))
1604 ALLOCATE (orbitals(n_grid, bs_env%n_ao, n_own, bs_env%n_spin))
1606 DO i_r = 1,
SIZE(bs_env%index_to_cell_3c, 2)
1607 IF (n_own == 0)
EXIT
1611 DO i_local = 1, n_own
1612 i_kp = env%mepos + 1 + (i_local - 1)*env%num_pe
1613 orbitals(:, :, i_local, 1) = orbitals(:, :, i_local, 1) + phi_r* &
1614 exp(
gaussi*
twopi*sum(bs_env%kpoints_DOS%xkp(:, i_kp)* &
1615 REAL(bs_env%index_to_cell_3c(:, i_r),
dp)))
1621 ALLOCATE (phi_k(n_grid, bs_env%n_ao))
1623 DO i_local = 1, n_own
1624 phi_k(:, :) = orbitals(:, :, i_local, 1)
1625 DO ispin = 1, bs_env%n_spin
1626 CALL zgemm(
'N',
'N', n_grid, bs_env%n_ao, bs_env%n_ao,
z_one, &
1627 phi_k, n_grid, coefficients(:, :, i_local, ispin), &
1628 bs_env%n_ao,
z_zero, orbitals(:, :, i_local, ispin), n_grid)
1635 CALL timestop(handle)
1637 END SUBROUTINE collect_band_bloch_orbitals
1646 SUBROUTINE band_orbitals_to_groups(bs_env, gwkp_env)
1648 TYPE(
gwkp_type),
INTENT(INOUT) :: gwkp_env
1650 CHARACTER(LEN=*),
PARAMETER :: routinen =
'band_orbitals_to_groups'
1652 COMPLEX(dp),
ALLOCATABLE :: group_orbitals(:, :, :, :)
1653 INTEGER :: handle, i_kp, i_local, i_root, ispin, &
1654 n_group, n_own, n_rank
1657 CALL timeset(routinen, handle)
1659 n_rank = bs_env%para_env%num_pe
1660 n_group = gwkp_env%group_env%num_pe
1661 n_own = (bs_env%nkp_bs_and_DOS - gwkp_env%group_env%mepos + n_group - 1)/n_group
1662 ALLOCATE (group_orbitals(
SIZE(gwkp_env%band_orbitals, 1),
SIZE(gwkp_env%band_orbitals, 2), &
1663 n_own, bs_env%n_spin))
1664 CALL column_env%from_split(bs_env%para_env, gwkp_env%group_env%mepos)
1665 DO i_local = 1, n_own
1666 i_kp = gwkp_env%group_env%mepos + 1 + (i_local - 1)*n_group
1667 i_root =
modulo(i_kp - 1, n_rank)/n_group
1668 DO ispin = 1, bs_env%n_spin
1669 IF (column_env%mepos == i_root)
THEN
1670 group_orbitals(:, :, i_local, ispin) = gwkp_env%band_orbitals(:, :, (i_kp - 1)/n_rank + 1, ispin)
1672 CALL column_env%bcast(group_orbitals(:, :, i_local, ispin), i_root)
1675 CALL column_env%free()
1676 CALL move_alloc(group_orbitals, gwkp_env%band_orbitals)
1678 CALL timestop(handle)
1680 END SUBROUTINE band_orbitals_to_groups
1689 FUNCTION native_q_index(bs_env, i_kp_eval)
RESULT(native_iq)
1691 INTEGER,
INTENT(IN) :: i_kp_eval
1692 INTEGER :: native_iq
1695 REAL(kind=
dp) :: delta_k(3)
1698 DO iq = 1, bs_env%nkp_scf_desymm
1699 IF (i_kp_eval <= bs_env%nkp_scf_desymm .AND. iq /= i_kp_eval) cycle
1700 delta_k = bs_env%kpoints_DOS%xkp(:, i_kp_eval) - bs_env%kpoints_scf_desymm%xkp(:, iq)
1701 IF (maxval(abs(delta_k - anint(delta_k))) <= 64.0_dp*epsilon(1.0_dp))
THEN
1707 END FUNCTION native_q_index
1714 SUBROUTINE collect_band_mo_coefficients(bs_env, band_coefficients)
1716 COMPLEX(KIND=dp),
ALLOCATABLE,
INTENT(OUT) :: band_coefficients(:, :, :, :)
1718 CHARACTER(LEN=*),
PARAMETER :: routinen =
'collect_band_mo_coefficients'
1720 COMPLEX(KIND=dp),
ALLOCATABLE :: coefficients(:, :)
1721 INTEGER :: handle, i_kp_eval, ispin
1724 CALL timeset(routinen, handle)
1726 env => bs_env%para_env
1727 ALLOCATE (coefficients(bs_env%n_ao, bs_env%n_ao))
1728 ALLOCATE (band_coefficients(bs_env%n_ao, bs_env%n_ao, &
1729 (bs_env%nkp_bs_and_DOS - env%mepos + env%num_pe - 1)/env%num_pe, &
1731 DO ispin = 1, bs_env%n_spin
1732 DO i_kp_eval = 1, bs_env%nkp_bs_and_DOS
1734 IF (
modulo(i_kp_eval - 1, env%num_pe) == env%mepos)
THEN
1735 band_coefficients(:, :, (i_kp_eval - 1)/env%num_pe + 1, ispin) = coefficients
1740 CALL timestop(handle)
1742 END SUBROUTINE collect_band_mo_coefficients
1754 SUBROUTINE self_energy_on_mesh(bs_env, cells, sigma_R, first_pair, sigma_mesh)
1756 INTEGER,
INTENT(IN) :: cells(:, :)
1757 REAL(kind=
dp),
INTENT(IN) :: sigma_r(:, :, :)
1758 INTEGER,
INTENT(IN) :: first_pair
1759 COMPLEX(KIND=dp),
INTENT(OUT) :: sigma_mesh(:, :, :)
1761 INTEGER :: i_first, n_chunk, n_pairs
1762 REAL(kind=
dp),
ALLOCATABLE :: chunk(:, :, :)
1764 n_chunk = max(1, min(
SIZE(sigma_r, 1), int(64.0_dp*bytes_per_mib/
real_bytes)/
SIZE(cells, 2)))
1765 ALLOCATE (chunk(n_chunk, 1,
SIZE(cells, 2)))
1766 DO i_first = 1,
SIZE(sigma_r, 1), n_chunk
1767 n_pairs = min(n_chunk,
SIZE(sigma_r, 1) - i_first + 1)
1768 chunk(1:n_pairs, :, :) = sigma_r(i_first:i_first + n_pairs - 1, :, :)
1769 CALL product_to_k_pair_centered(bs_env, cells, bs_env%kpoints_scf_desymm%xkp, chunk(1:n_pairs, :, :), &
1770 sigma_mesh(i_first:i_first + n_pairs - 1, :, :), &
1771 first_pair + i_first - 1)
1774 END SUBROUTINE self_energy_on_mesh
1791 SUBROUTINE self_energy_pairs_to_bloch(bs_env, sigma_mesh, sigma_R, first_pair, env, orbitals, sigma_band)
1793 COMPLEX(KIND=dp),
INTENT(IN) :: sigma_mesh(:, :, :)
1794 REAL(kind=
dp),
INTENT(IN) :: sigma_r(:, :, :)
1795 INTEGER,
INTENT(IN) :: first_pair
1797 COMPLEX(KIND=dp),
CONTIGUOUS,
INTENT(IN) :: orbitals(:, :, :)
1798 REAL(kind=
dp),
INTENT(OUT) :: sigma_band(:, :)
1800 CHARACTER(LEN=*),
PARAMETER :: routinen =
'self_energy_pairs_to_Bloch'
1802 COMPLEX(KIND=dp),
ALLOCATABLE :: sigma_k(:, :), work(:, :)
1803 COMPLEX(KIND=dp),
ALLOCATABLE,
TARGET :: send_buffer(:)
1804 COMPLEX(KIND=dp),
CONTIGUOUS,
POINTER :: sigma_columns(:, :)
1805 INTEGER :: handle, i_band, i_batch, i_first, i_kp, &
1806 i_rank, j, m, n_batch, n_grid, n_kp, &
1807 n_local, n_rank, n_round
1808 INTEGER,
ALLOCATABLE :: pair_counts(:), pair_displs(:), &
1809 recv_counts(:), send_counts(:), &
1812 CALL timeset(routinen, handle)
1814 n_grid = bs_env%ri_rs%n_grid_points
1815 n_kp = bs_env%nkp_bs_and_DOS
1816 n_local =
SIZE(sigma_mesh, 1)
1818 n_batch = min(16, bs_env%n_ao)
1819 m = projection_round_kpoints(n_grid, n_rank)
1820 CALL grid_pair_blocks(n_grid, n_rank, pair_counts, pair_displs)
1821 ALLOCATE (send_buffer(n_local*n_rank*m), sigma_k(n_grid**2, m), recv_counts(0:n_rank - 1), &
1822 send_counts(0:n_rank - 1), send_displs(0:n_rank - 1))
1823 sigma_columns(1:n_local, 1:n_rank*m) => send_buffer
1824 send_displs(:) = [(i_rank*n_local, i_rank=0, n_rank - 1)]
1827 DO i_first = 1, n_kp, n_rank*m
1828 n_round = min(n_rank*m, n_kp - i_first + 1)
1829 CALL band_self_energy(bs_env, sigma_mesh, sigma_r, first_pair, i_first, sigma_columns(:, 1:n_round))
1831 DO i_rank = 0, n_rank - 1
1832 send_counts(i_rank) = merge(n_local, 0, (j - 1)*n_rank + i_rank < n_round)
1834 i_kp = i_first + (j - 1)*n_rank + env%mepos
1835 recv_counts(:) = merge(pair_counts, 0, i_kp <= n_kp)
1836 CALL env%alltoall(send_buffer((j - 1)*n_rank*n_local + 1:j*n_rank*n_local), send_counts, &
1837 send_displs, sigma_k(:, j), recv_counts, pair_displs)
1842 ALLOCATE (work(n_grid, n_batch))
1845 DO i_batch = 1, bs_env%n_ao, n_batch
1846 i_kp = i_first + (j - 1)*n_rank + env%mepos
1847 IF (i_kp > n_kp) cycle
1848 CALL zgemm(
'N',
'N', n_grid, min(n_batch, bs_env%n_ao - i_batch + 1), n_grid,
z_one, &
1849 sigma_k(1, j), n_grid, &
1850 orbitals(:, i_batch:min(i_batch + n_batch - 1, bs_env%n_ao), (i_kp - 1)/n_rank + 1), n_grid, &
1852 DO i_band = i_batch, min(i_batch + n_batch - 1, bs_env%n_ao)
1853 sigma_band(i_band, i_kp) = real(sum(conjg(orbitals(:, i_band, (i_kp - 1)/n_rank + 1))* &
1854 work(:, i_band - i_batch + 1)),
dp)
1862 CALL env%sum(sigma_band)
1864 CALL timestop(handle)
1866 END SUBROUTINE self_energy_pairs_to_bloch
1878 PURE REAL(KIND=dp) FUNCTION image_weight(c, n_mesh, tie, boundary)
RESULT(weight)
1879 INTEGER,
INTENT(IN) :: c, n_mesh
1880 LOGICAL,
INTENT(IN) :: tie
1881 REAL(kind=
dp),
INTENT(IN) :: boundary
1883 INTEGER :: i_center, n_centers
1885 n_centers = merge(2, 1, tie)
1887 DO i_center = 0, n_centers - 1
1888 IF (2*abs(c - i_center) < n_mesh)
THEN
1889 weight = weight + 1.0_dp/real(n_centers,
dp)
1890 ELSE IF (2*abs(c - i_center) == n_mesh)
THEN
1891 weight = weight + boundary/real(n_centers,
dp)
1894 END FUNCTION image_weight
1909 FUNCTION projection_workspace_bytes(n_grid, n_rank, n_images, n_ao, n_threads)
RESULT(bytes)
1910 INTEGER,
INTENT(IN) :: n_grid, n_rank, n_images, n_ao, n_threads
1913 REAL(
dp) :: m, n_round
1915 m = real(projection_round_kpoints(n_grid, n_rank),
dp)
1916 n_round = m*real(n_rank,
dp)
1918 projection_workspace + &
1920 real_bytes*
REAL(pair_batch_size,
dp)*
REAL(n_images, dp) + &
1922 bytes = max(bytes,
complex_bytes*real(n_grid,
dp)*(2.0_dp*real(n_grid,
dp) + real(n_ao,
dp)))
1923 END FUNCTION projection_workspace_bytes
1932 PURE INTEGER FUNCTION projection_round_kpoints(n_grid, n_rank)
RESULT(m)
1933 INTEGER,
INTENT(IN) :: n_grid, n_rank
1935 m = max(1, min(band_kpoints_per_pass/n_rank, int(projection_round_bytes/(2.0_dp*
complex_bytes*real(n_grid,
dp)**2))))
1936 END FUNCTION projection_round_kpoints
1943 PURE REAL(KIND=dp) FUNCTION budget_after_reserve(available_GB)
RESULT(budget)
1944 REAL(kind=
dp),
INTENT(IN) :: available_gb
1946 budget = max(0.0_dp, available_gb - max(min_reserve_gb, reserve_share*available_gb))*bytes_per_gb
1947 END FUNCTION budget_after_reserve
1965 SUBROUTINE band_self_energy(bs_env, sigma_mesh, sigma_R, first_pair, first_kp_eval, sigma_k)
1967 COMPLEX(KIND=dp),
INTENT(IN) :: sigma_mesh(:, :, :)
1968 REAL(kind=
dp),
INTENT(IN) :: sigma_r(:, :, :)
1969 INTEGER,
INTENT(IN) :: first_pair, first_kp_eval
1970 COMPLEX(KIND=dp),
INTENT(OUT) :: sigma_k(:, :)
1972 COMPLEX(KIND=dp) :: phase
1973 INTEGER :: c1, c2, c3, first_c(3), i_c, i_col, i_first, i_local, i_off, i_pair, last_c(3), &
1974 lower(3), n_c, n_grid, n_off, n_pairs, native_iq, nmesh(3), shift(3), wrapped(3)
1975 INTEGER,
ALLOCATABLE :: offmesh_col(:), pair_shift(:, :)
1976 LOGICAL :: any_tie(3), tie(3)
1977 REAL(kind=
dp) :: angle, boundary(3)
1978 REAL(kind=
dp),
ALLOCATABLE :: cos_c(:, :), fractional_grid(:, :), images(:, :), sin_c(:, :), &
1979 sum_im(:, :), sum_re(:, :), weight_1(:), weight_2(:), weight_3(:), xk(:, :)
1981 ALLOCATE (offmesh_col(
SIZE(sigma_k, 2)))
1983 DO i_col = 1,
SIZE(sigma_k, 2)
1984 native_iq = native_q_index(bs_env, first_kp_eval + i_col - 1)
1985 IF (native_iq > 0)
THEN
1986 sigma_k(:, i_col) = sigma_mesh(:, 1, native_iq)
1989 offmesh_col(n_off) = i_col
1992 IF (n_off == 0)
RETURN
1994 n_grid = bs_env%ri_rs%n_grid_points
1995 nmesh = bs_env%kpoints_scf_desymm%nkp_grid
1997 ALLOCATE (fractional_grid(3, n_grid))
1998 fractional_grid(:, :) = matmul(bs_env%ri_rs%cell%h_inv, bs_env%ri_rs%grid_points)
2000 IF (bs_env%periodic(i_c) == 0) fractional_grid(i_c, :) = 0.0_dp
2003 DO i_local = 1,
SIZE(sigma_r, 1)
2004 CALL product_pair_shift(first_pair + i_local - 1, n_grid, fractional_grid, shift, tie)
2005 any_tie = any_tie .OR. tie
2007 boundary = 0.25_dp*(1.0_dp + cos(
twopi*bs_env%kpoints_scf_desymm%xkp(:, 1)*nmesh))
2009 last_c = nmesh/2 + merge(1, 0, any_tie)
2010 n_c = product(last_c - first_c + 1)
2011 ALLOCATE (xk(3, n_off), cos_c(n_c, n_off), sin_c(n_c, n_off))
2013 xk(:, i_off) = bs_env%kpoints_DOS%xkp(:, first_kp_eval + offmesh_col(i_off) - 1)
2020 DO c3 = first_c(3), last_c(3)
2021 DO c2 = first_c(2), last_c(2)
2022 DO c1 = first_c(1), last_c(1)
2024 phase = exp(cmplx(0.0_dp,
twopi*(xk(1, i_off)*c1 + xk(2, i_off)*c2 + xk(3, i_off)*c3), kind=
dp))
2025 cos_c(i_c, i_off) = real(phase, kind=
dp)
2026 sin_c(i_c, i_off) = aimag(phase)
2038 ALLOCATE (images(n_c, pair_batch_size), pair_shift(3, pair_batch_size), &
2039 sum_re(pair_batch_size, n_off), sum_im(pair_batch_size, n_off), &
2040 weight_1(first_c(1):last_c(1)), weight_2(first_c(2):last_c(2)), weight_3(first_c(3):last_c(3)))
2042 DO i_first = 1,
SIZE(sigma_r, 1), pair_batch_size
2043 n_pairs = min(pair_batch_size,
SIZE(sigma_r, 1) - i_first + 1)
2044 DO i_pair = 1, n_pairs
2045 CALL product_pair_shift(first_pair + i_first + i_pair - 2, n_grid, fractional_grid, shift, tie)
2046 pair_shift(:, i_pair) = shift
2047 weight_1(:) = [(image_weight(c1, nmesh(1), tie(1), boundary(1)), c1=first_c(1), last_c(1))]
2048 weight_2(:) = [(image_weight(c2, nmesh(2), tie(2), boundary(2)), c2=first_c(2), last_c(2))]
2049 weight_3(:) = [(image_weight(c3, nmesh(3), tie(3), boundary(3)), c3=first_c(3), last_c(3))]
2051 DO c3 = first_c(3), last_c(3)
2052 DO c2 = first_c(2), last_c(2)
2053 DO c1 = first_c(1), last_c(1)
2055 IF (weight_1(c1)*weight_2(c2)*weight_3(c3) == 0.0_dp)
THEN
2056 images(i_c, i_pair) = 0.0_dp
2058 wrapped =
modulo(shift + [c1, c2, c3] - lower, nmesh) + lower
2059 images(i_c, i_pair) = weight_1(c1)*weight_2(c2)*weight_3(c3)* &
2060 sigma_r(i_first + i_pair - 1, 1, 1 + wrapped(3) - lower(3) + &
2061 nmesh(3)*(wrapped(2) - lower(2) + nmesh(2)*(wrapped(1) - lower(1))))
2067 CALL dgemm(
'T',
'N', n_pairs, n_off, n_c, 1.0_dp, images, n_c, cos_c, n_c, 0.0_dp, sum_re, pair_batch_size)
2068 CALL dgemm(
'T',
'N', n_pairs, n_off, n_c, 1.0_dp, images, n_c, sin_c, n_c, 0.0_dp, sum_im, pair_batch_size)
2070 DO i_pair = 1, n_pairs
2071 angle =
twopi*dot_product(xk(:, i_off), real(pair_shift(:, i_pair),
dp))
2072 sigma_k(i_first + i_pair - 1, offmesh_col(i_off)) = &
2073 exp(cmplx(0.0_dp, angle, kind=
dp))*cmplx(sum_re(i_pair, i_off), sum_im(i_pair, i_off), kind=
dp)
2078 DEALLOCATE (images, pair_shift, sum_re, sum_im, weight_1, weight_2, weight_3)
2080 DEALLOCATE (cos_c, fractional_grid, offmesh_col, sin_c, xk)
2081 END SUBROUTINE band_self_energy
2098 SUBROUTINE product_to_k_pair_centered(bs_env, cells, xkp, values_R, values_k, first_pair)
2100 INTEGER,
INTENT(IN) :: cells(:, :)
2101 REAL(kind=
dp),
INTENT(IN) :: xkp(:, :)
2102 REAL(kind=
dp),
INTENT(INOUT) :: values_r(:, :, :)
2103 COMPLEX(KIND=dp),
INTENT(OUT) :: values_k(:, :, :)
2104 INTEGER,
INTENT(IN) :: first_pair
2106 CHARACTER(LEN=*),
PARAMETER :: routinen =
'product_to_k_pair_centered'
2108 INTEGER :: handle, icell, idir, ik, ilocal, &
2109 isource, lower(3), ngrid, nmesh(3), &
2110 shift(3), wrapped(3)
2112 REAL(kind=
dp) :: endpoint(3), weight
2113 REAL(kind=
dp),
ALLOCATABLE :: fractional_grid(:, :), scratch(:)
2115 CALL timeset(routinen, handle)
2117 ngrid = bs_env%ri_rs%n_grid_points
2118 nmesh = bs_env%kpoints_scf_desymm%nkp_grid
2120 endpoint = cos(
twopi*xkp(1:3, 1)*real(nmesh,
dp))
2121 ALLOCATE (fractional_grid(3, ngrid))
2122 fractional_grid(:, :) = matmul(bs_env%ri_rs%cell%h_inv, bs_env%ri_rs%grid_points)
2124 IF (bs_env%periodic(idir) == 0) fractional_grid(idir, :) = 0.0_dp
2126 cpassert(
SIZE(values_r, 2) == 1)
2130 ALLOCATE (scratch(
SIZE(cells, 2)))
2132 DO ilocal = 1,
SIZE(values_r, 1)
2133 CALL product_pair_shift(first_pair + ilocal - 1, ngrid, fractional_grid, shift, tie)
2134 scratch(:) = values_r(ilocal, 1, :)
2135 DO icell = 1,
SIZE(cells, 2)
2136 wrapped =
modulo(cells(:, icell) + shift - lower, nmesh) + lower
2137 isource = 1 + wrapped(3) - lower(3) + &
2138 nmesh(3)*(wrapped(2) - lower(2) + nmesh(2)*(wrapped(1) - lower(1)))
2141 IF (
modulo(nmesh(idir), 2) == 0)
THEN
2142 IF (cells(idir, icell) == lower(idir))
THEN
2144 weight = weight*(1.0_dp + 3.0_dp*endpoint(idir))/4.0_dp
2146 weight = weight*(1.0_dp + endpoint(idir))/2.0_dp
2148 ELSE IF (tie(idir) .AND. cells(idir, icell) == lower(idir) + 1)
THEN
2149 weight = weight*(3.0_dp + endpoint(idir))/4.0_dp
2151 ELSE IF (tie(idir) .AND. cells(idir, icell) == lower(idir))
THEN
2152 weight = weight*(1.0_dp + endpoint(idir))/2.0_dp
2155 values_r(ilocal, 1, icell) = weight*scratch(isource)
2159 DEALLOCATE (scratch)
2165 DO ilocal = 1,
SIZE(values_k, 1)
2166 CALL product_pair_shift(first_pair + ilocal - 1, ngrid, fractional_grid, shift, tie)
2167 DO ik = 1,
SIZE(xkp, 2)
2168 values_k(ilocal, 1, ik) = values_k(ilocal, 1, ik)* &
2169 exp(cmplx(0.0_dp,
twopi*dot_product(xkp(1:3, ik), real(shift,
dp)),
dp))
2174 CALL timestop(handle)
2176 END SUBROUTINE product_to_k_pair_centered
2186 SUBROUTINE product_pair_shift(ipair, ngrid, fractional_grid, pair_shift, pair_tie)
2187 INTEGER,
INTENT(IN) :: ipair, ngrid
2188 REAL(kind=
dp),
INTENT(IN) :: fractional_grid(:, :)
2189 INTEGER,
INTENT(OUT) :: pair_shift(3)
2190 LOGICAL,
INTENT(OUT) :: pair_tie(3)
2192 INTEGER :: idir, il, ilp
2193 REAL(kind=
dp) :: delta(3), half_boundary, tolerance
2195 il =
modulo(ipair - 1, ngrid) + 1
2196 ilp = (ipair - 1)/ngrid + 1
2197 delta = fractional_grid(:, il) - fractional_grid(:, ilp)
2198 pair_shift = nint(delta)
2201 half_boundary = anint(delta(idir) - 0.5_dp) + 0.5_dp
2202 tolerance = 64.0_dp*epsilon(1.0_dp)*max(1.0_dp, abs(delta(idir)))
2203 IF (abs(delta(idir) - half_boundary) <= tolerance)
THEN
2204 pair_shift(idir) = nint(half_boundary - 0.5_dp)
2205 pair_tie(idir) = .true.
2208 END SUBROUTINE product_pair_shift
2216 SUBROUTINE cosine_transform_ri_q(block, transform)
2218 REAL(kind=
dp),
INTENT(IN) :: transform(:, :)
2220 CHARACTER(LEN=*),
PARAMETER :: routinen =
'cosine_transform_ri_q'
2222 COMPLEX(KIND=dp),
ALLOCATABLE :: values(:, :, :)
2223 INTEGER :: handle, n_elements
2225 CALL timeset(routinen, handle)
2227 cpassert(
SIZE(transform, 2) ==
SIZE(block%values, 3))
2228 n_elements =
SIZE(block%values, 1)*
SIZE(block%values, 2)
2229 ALLOCATE (values(
SIZE(block%values, 1),
SIZE(block%values, 2),
SIZE(transform, 1)))
2230 CALL zgemm(
'N',
'T', n_elements,
SIZE(transform, 1),
SIZE(transform, 2),
z_one, block%values, &
2231 n_elements, cmplx(transform, kind=
dp),
SIZE(transform, 1),
z_zero, values, n_elements)
2232 CALL move_alloc(values, block%values)
2234 CALL timestop(handle)
2236 END SUBROUTINE cosine_transform_ri_q
2243 FUNCTION ri_q_storage_elements(blocks)
RESULT(nelements)
2245 INTEGER(KIND=int_8) :: nelements
2250 DO iq = 1,
SIZE(blocks)
2251 IF (
ALLOCATED(blocks(iq)%values))
THEN
2252 nelements = nelements +
SIZE(blocks(iq)%values, kind=
int_8)
2255 END FUNCTION ri_q_storage_elements
2268 SUBROUTINE gw_k_grid_to_real_cells(values_k, xkp, nkp_grid, cells, values_R)
2269 COMPLEX(KIND=dp),
INTENT(IN) :: values_k(:, :, :)
2270 REAL(kind=
dp),
INTENT(IN) :: xkp(:, :)
2271 INTEGER,
INTENT(IN) :: nkp_grid(3), cells(:, :)
2272 REAL(kind=
dp),
INTENT(OUT) :: values_r(:, :, :)
2274 CHARACTER(LEN=*),
PARAMETER :: routinen =
'gw_k_grid_to_real_cells'
2276 TYPE fft_buffer_type
2277 COMPLEX(KIND=dp),
CONTIGUOUS,
POINTER :: zin(:, :, :), zout(:, :, :)
2278 END TYPE fft_buffer_type
2280 COMPLEX(KIND=dp),
ALLOCATABLE :: cell_phase(:), row_r(:, :, :)
2281 COMPLEX(KIND=dp),
CONTIGUOUS,
POINTER :: fft_in(:, :, :), fft_out(:, :, :)
2282 INTEGER :: d, handle, i, icell, ik, irow, ithread, &
2283 j, local_stat, nfft(3), nthreads, stat
2284 INTEGER,
ALLOCATABLE :: cell_index(:, :), grid_index(:, :)
2286 REAL(kind=
dp) :: k_offset(3), weight
2287 TYPE(fft_buffer_type),
ALLOCATABLE :: buffers(:)
2291 CALL timeset(routinen, handle)
2292 ALLOCATE (grid_index(3,
SIZE(xkp, 2)))
2297 weight = 1.0_dp/real(
SIZE(xkp, 2),
dp)
2298 ALLOCATE (cell_index(3,
SIZE(cells, 2)), cell_phase(
SIZE(cells, 2)))
2299 DO icell = 1,
SIZE(cells, 2)
2301 cell_index(d, icell) =
modulo(cells(d, icell), nkp_grid(d))*(nfft(d)/nkp_grid(d)) + 1
2303 cell_phase(icell) = exp(-
gaussi*
twopi*sum(k_offset*real(cells(1:3, icell),
dp)))
2306 ALLOCATE (buffers(nthreads))
2307 DO ithread = 1, nthreads
2308 CALL fft_alloc(buffers(ithread)%zin, nfft)
2309 CALL fft_alloc(buffers(ithread)%zout, nfft)
2322 fft_in => buffers(ithread)%zin
2323 fft_out => buffers(ithread)%zout
2325 DO j = 1,
SIZE(values_r, 2)
2326 DO i = 1,
SIZE(values_r, 1)
2328 DO ik = 1,
SIZE(values_k, 3)
2329 fft_in(grid_index(1, ik), grid_index(2, ik), grid_index(3, ik)) = weight*values_k(i, j, ik)
2331 CALL fft_3d(plan, 1.0_dp, fft_in, fft_out, local_stat)
2332 stat = max(stat, local_stat)
2333 IF (local_stat /= 0) cycle
2334 DO icell = 1,
SIZE(values_r, 3)
2335 values_r(i, j, icell) = real(cell_phase(icell)* &
2336 fft_out(cell_index(1, icell), cell_index(2, icell), &
2337 cell_index(3, icell)),
dp)
2344 DO ithread = 1, nthreads
2345 CALL fft_dealloc(buffers(ithread)%zin)
2346 CALL fft_dealloc(buffers(ithread)%zout)
2348 DEALLOCATE (buffers, cell_index, cell_phase)
2351 ALLOCATE (row_r(1,
SIZE(values_r, 2),
SIZE(values_r, 3)))
2353 DO irow = 1,
SIZE(values_r, 1)
2355 values_r(irow, :, :) = real(row_r(1, :, :),
dp)
2360 DEALLOCATE (grid_index)
2361 CALL timestop(handle)
2363 END SUBROUTINE gw_k_grid_to_real_cells
2373 SUBROUTINE q_matrices_to_fft_pairs(q_matrices, para_env, fft_pairs)
2374 COMPLEX(KIND=dp),
INTENT(IN) :: q_matrices(:, :, :)
2376 COMPLEX(KIND=dp),
INTENT(OUT) :: fft_pairs(:, :, :)
2378 CHARACTER(LEN=*),
PARAMETER :: routinen =
'q_matrices_to_fft_pairs'
2380 COMPLEX(KIND=dp),
ALLOCATABLE :: received(:), sent(:)
2381 INTEGER :: handle, i_first, i_rank, i_round, &
2382 n_grid, n_local, n_q, n_rank, n_round
2383 INTEGER,
ALLOCATABLE :: pair_counts(:), pair_displs(:), &
2384 recv_counts(:), recv_displs(:), &
2387 CALL timeset(routinen, handle)
2389 n_rank = para_env%num_pe
2390 n_grid =
SIZE(q_matrices, 1)
2391 n_local =
SIZE(fft_pairs, 1)
2392 n_q =
SIZE(fft_pairs, 3)
2393 cpassert(
SIZE(fft_pairs, 2) == 1)
2394 CALL grid_pair_blocks(n_grid, n_rank, pair_counts, pair_displs)
2395 ALLOCATE (sent(n_grid**2), received(n_local*n_rank), recv_counts(0:n_rank - 1), &
2396 recv_displs(0:n_rank - 1), send_counts(0:n_rank - 1))
2397 recv_displs(:) = [(
modulo(i_rank - 1, n_rank)*n_local, i_rank=0, n_rank - 1)]
2398 DO i_round = 1, (n_q + n_rank - 1)/n_rank
2399 i_first = (i_round - 1)*n_rank
2400 n_round = min(n_rank, n_q - i_first)
2401 DO i_rank = 0, n_rank - 1
2402 recv_counts(i_rank) = merge(n_local, 0,
modulo(i_rank - 1, n_rank) < n_round)
2405 IF (
modulo(para_env%mepos - 1, n_rank) < n_round)
THEN
2406 sent(:) = reshape(q_matrices(:, :, i_round), [n_grid**2])
2407 send_counts(:) = pair_counts
2409 CALL para_env%alltoall(sent, send_counts, pair_displs, received, recv_counts, recv_displs)
2410 fft_pairs(:, 1, i_first + 1:i_first + n_round) = reshape(received(1:n_local*n_round), [n_local, n_round])
2413 CALL timestop(handle)
2415 END SUBROUTINE q_matrices_to_fft_pairs
2425 SUBROUTINE fft_pairs_to_q_matrices(fft_pairs, para_env, needed, q_matrices)
2426 COMPLEX(KIND=dp),
INTENT(IN) :: fft_pairs(:, :, :)
2428 LOGICAL,
INTENT(IN) :: needed(:)
2429 COMPLEX(KIND=dp),
INTENT(OUT) :: q_matrices(:, :, :)
2431 CHARACTER(LEN=*),
PARAMETER :: routinen =
'fft_pairs_to_q_matrices'
2433 COMPLEX(KIND=dp),
ALLOCATABLE :: received(:), sent(:)
2434 INTEGER :: handle, i_first, i_local, i_rank, &
2435 i_round, iq, n_grid, n_local, n_q, &
2437 INTEGER,
ALLOCATABLE :: pair_counts(:), pair_displs(:), &
2438 recv_counts(:), send_counts(:), &
2440 LOGICAL :: receiving
2442 CALL timeset(routinen, handle)
2444 n_rank = para_env%num_pe
2445 n_grid =
SIZE(q_matrices, 1)
2446 n_local =
SIZE(fft_pairs, 1)
2447 n_q =
SIZE(fft_pairs, 3)
2448 cpassert(
SIZE(fft_pairs, 2) == 1 .AND.
SIZE(needed) == n_q)
2449 CALL grid_pair_blocks(n_grid, n_rank, pair_counts, pair_displs)
2450 ALLOCATE (sent(n_local*n_rank), received(n_grid**2), recv_counts(0:n_rank - 1), &
2451 send_counts(0:n_rank - 1), send_displs(0:n_rank - 1))
2452 send_displs(:) = [(
modulo(i_rank - 1, n_rank)*n_local, i_rank=0, n_rank - 1)]
2454 DO i_round = 1, (n_q + n_rank - 1)/n_rank
2455 i_first = (i_round - 1)*n_rank
2456 n_round = min(n_rank, n_q - i_first)
2458 DO i_rank = 0, n_rank - 1
2459 iq = i_first +
modulo(i_rank - 1, n_rank) + 1
2461 IF (needed(iq)) send_counts(i_rank) = n_local
2463 sent(1:n_local*n_round) = reshape(fft_pairs(:, 1, i_first + 1:i_first + n_round), [n_local*n_round])
2464 iq = i_first +
modulo(para_env%mepos - 1, n_rank) + 1
2465 receiving = iq <= n_q
2466 IF (receiving) receiving = needed(iq)
2468 IF (receiving) recv_counts(:) = pair_counts
2469 CALL para_env%alltoall(sent, send_counts, send_displs, received, recv_counts, pair_displs)
2471 i_local = i_local + 1
2472 q_matrices(:, :, i_local) = reshape(received, [n_grid, n_grid])
2475 cpassert(i_local ==
SIZE(q_matrices, 3))
2477 CALL timestop(handle)
2479 END SUBROUTINE fft_pairs_to_q_matrices
2489 SUBROUTINE project_auxiliary_time_q_to_fft_pairs(Z_q, interaction_q, itime, para_env, fft_pairs)
2490 COMPLEX(KIND=dp),
INTENT(IN) :: z_q(:, :, :)
2492 INTEGER,
INTENT(IN) :: itime
2494 COMPLEX(KIND=dp),
INTENT(OUT) :: fft_pairs(:, :, :)
2496 CHARACTER(LEN=*),
PARAMETER :: routinen =
'project_auxiliary_time_q_to_fft_pairs'
2498 COMPLEX(KIND=dp),
ALLOCATABLE :: q_matrices(:, :, :), zw(:, :)
2499 INTEGER :: handle, i_q_local, n_grid, n_q_local, &
2502 CALL timeset(routinen, handle)
2504 n_grid =
SIZE(z_q, 1)
2506 n_q_local =
SIZE(z_q, 3)
2507 cpassert(
SIZE(interaction_q) == n_q_local)
2508 ALLOCATE (q_matrices(n_grid, n_grid, n_q_local))
2511 ALLOCATE (zw(n_grid, n_ri))
2513 DO i_q_local = 1, n_q_local
2514 CALL zgemm(
'N',
'N', n_grid, n_ri, n_ri,
z_one, z_q(:, :, i_q_local), n_grid, &
2515 interaction_q(i_q_local)%values(:, :, itime), n_ri,
z_zero, zw, n_grid)
2516 CALL zgemm(
'N',
'C', n_grid, n_grid, n_ri,
z_one, zw, n_grid, z_q(:, :, i_q_local), n_grid, &
2517 z_zero, q_matrices(:, :, i_q_local), n_grid)
2522 CALL q_matrices_to_fft_pairs(q_matrices, para_env, fft_pairs)
2524 CALL timestop(handle)
2526 END SUBROUTINE project_auxiliary_time_q_to_fft_pairs
2536 SUBROUTINE set_owner_matrix(distributed, owner_matrix, group_env, root, n)
2538 COMPLEX(KIND=dp),
INTENT(IN) :: owner_matrix(:, :)
2540 INTEGER,
INTENT(IN) :: root, n
2542 COMPLEX(KIND=dp),
ALLOCATABLE :: column_block(:, :)
2543 INTEGER :: first, width
2545 IF (group_env%mepos == root)
THEN
2546 cpassert(all(shape(owner_matrix) == [n, n]))
2548 ALLOCATE (column_block(n, column_block_cols))
2549 DO first = 1, n, column_block_cols
2550 width = min(column_block_cols, n - first + 1)
2551 IF (group_env%mepos == root) column_block(:, 1:width) = owner_matrix(:, first:first + width - 1)
2552 CALL group_env%bcast(column_block(:, 1:width), root)
2554 start_row=1, start_col=first)
2556 DEALLOCATE (column_block)
2557 END SUBROUTINE set_owner_matrix
2567 SUBROUTINE get_owner_matrix(distributed, owner_matrix, group_env, root, n)
2569 COMPLEX(KIND=dp),
INTENT(OUT) :: owner_matrix(:, :)
2571 INTEGER,
INTENT(IN) :: root, n
2573 COMPLEX(KIND=dp),
ALLOCATABLE :: column_block(:, :)
2574 INTEGER :: first, width
2576 IF (group_env%mepos == root)
THEN
2577 cpassert(all(shape(owner_matrix) == [n, n]))
2579 ALLOCATE (column_block(n, column_block_cols))
2580 DO first = 1, n, column_block_cols
2581 width = min(column_block_cols, n - first + 1)
2583 start_row=1, start_col=first)
2584 IF (group_env%mepos == root) owner_matrix(:, first:first + width - 1) = column_block(:, 1:width)
2586 DEALLOCATE (column_block)
2587 END SUBROUTINE get_owner_matrix
2594 SUBROUTINE minus_q_partners(xkp, q_partner)
2595 REAL(kind=
dp),
INTENT(IN) :: xkp(:, :)
2596 INTEGER,
ALLOCATABLE,
INTENT(OUT) :: q_partner(:)
2599 REAL(kind=
dp) :: q_sum(3)
2601 ALLOCATE (q_partner(
SIZE(xkp, 2)), source=0)
2602 DO ikp = 1,
SIZE(xkp, 2)
2603 DO jkp = 1,
SIZE(xkp, 2)
2604 q_sum(:) = xkp(:, ikp) + xkp(:, jkp)
2605 IF (all(abs(q_sum - anint(q_sum)) < eps_kpoint))
THEN
2606 q_partner(ikp) = jkp
2610 cpassert(q_partner(ikp) > 0)
2612 END SUBROUTINE minus_q_partners
2623 SUBROUTINE receive_minus_q_blocks(para_env, q_partner, solves_q, n_RI, n_time, blocks)
2625 INTEGER,
INTENT(IN) :: q_partner(:)
2626 LOGICAL,
INTENT(IN) :: solves_q(:)
2627 INTEGER,
INTENT(IN) :: n_ri, n_time
2630 INTEGER :: destination, ikp, n_requests, &
2631 partner_local, q_local, source
2635 ALLOCATE (requests(
SIZE(blocks)))
2637 DO ikp = 1,
SIZE(q_partner)
2638 IF (.NOT. solves_q(ikp) .OR. q_partner(ikp) == ikp) cycle
2639 source =
modulo(ikp, para_env%num_pe)
2640 destination =
modulo(q_partner(ikp), para_env%num_pe)
2641 q_local = 1 + (ikp - 1)/para_env%num_pe
2642 partner_local = 1 + (q_partner(ikp) - 1)/para_env%num_pe
2643 IF (para_env%mepos == destination)
THEN
2644 ALLOCATE (blocks(partner_local)%values(n_ri, n_ri, n_time))
2645 IF (source == destination)
THEN
2646 blocks(partner_local)%values(:, :, :) = blocks(q_local)%values
2648 n_requests = n_requests + 1
2649 CALL para_env%irecv(blocks(partner_local)%values, source, requests(n_requests), tag=q_local)
2651 ELSE IF (para_env%mepos == source)
THEN
2652 n_requests = n_requests + 1
2653 CALL para_env%isend(blocks(q_local)%values, destination, requests(n_requests), tag=q_local)
2657 DO ikp = para_env%mepos,
SIZE(q_partner), para_env%num_pe
2659 IF (.NOT. solves_q(ikp))
THEN
2660 q_local = 1 + (ikp - 1)/para_env%num_pe
2661 blocks(q_local)%values(:, :, :) = conjg(blocks(q_local)%values)
2664 END SUBROUTINE receive_minus_q_blocks
2673 SUBROUTINE grouped_w_partition(para_env, n_qgroups, my_qgroup, q_roots)
2675 INTEGER,
INTENT(IN) :: n_qgroups
2676 INTEGER,
INTENT(OUT) :: my_qgroup
2677 INTEGER,
ALLOCATABLE,
INTENT(OUT) :: q_roots(:)
2679 INTEGER :: i_first, i_group, i_last
2681 cpassert(n_qgroups > 0 .AND. n_qgroups <= para_env%num_pe)
2682 ALLOCATE (q_roots(n_qgroups))
2683 DO i_group = 0, n_qgroups - 1
2684 i_first = (para_env%num_pe*i_group)/n_qgroups
2685 i_last = (para_env%num_pe*(i_group + 1))/n_qgroups - 1
2686 q_roots(i_group + 1) = i_first
2687 IF (para_env%mepos >= i_first .AND. para_env%mepos <= i_last) my_qgroup = i_group
2690 END SUBROUTINE grouped_w_partition
2701 SUBROUTINE grouped_w_create(matrices, blacs, matrix_struct, group_env, n)
2702 TYPE(
cp_cfm_type),
INTENT(INOUT) :: matrices(n_w_matrices)
2706 INTEGER,
INTENT(IN) :: n
2711 nrow_global=n, ncol_global=n)
2717 END SUBROUTINE grouped_w_create
2729 SUBROUTINE grouped_w_copy_matrix(world, n, source_rank, destination_rank, source, destination)
2731 INTEGER,
INTENT(IN) :: n, source_rank, destination_rank
2732 COMPLEX(KIND=dp),
INTENT(IN) :: source(:, :)
2733 COMPLEX(KIND=dp),
INTENT(INOUT) :: destination(:, :)
2735 INTEGER :: first, last, sender, tag
2737 IF (source_rank == destination_rank)
THEN
2738 IF (world%mepos == source_rank) destination = source
2741 DO first = 1, n, column_block_cols
2742 last = min(first + column_block_cols - 1, n)
2743 IF (world%mepos == source_rank)
THEN
2744 CALL world%send(source(:, first:last), destination_rank, 0)
2745 ELSE IF (world%mepos == destination_rank)
THEN
2746 sender = source_rank
2748 CALL world%recv(destination(:, first:last), sender, tag)
2751 END SUBROUTINE grouped_w_copy_matrix
2765 SUBROUTINE grouped_w_solve(matrices, group_env, n, root, chi_owner, cutoff, output_owner)
2766 TYPE(
cp_cfm_type),
INTENT(INOUT) :: matrices(n_w_matrices)
2768 INTEGER,
INTENT(IN) :: n, root
2769 COMPLEX(KIND=dp),
INTENT(IN) :: chi_owner(:, :)
2770 REAL(kind=
dp),
INTENT(IN) :: cutoff
2771 COMPLEX(KIND=dp),
INTENT(OUT) :: output_owner(:, :)
2775 cpassert(root >= 0 .AND. root < group_env%num_pe)
2776 CALL set_owner_matrix(matrices(w_chi), chi_owner, group_env, root, n)
2781 cmplx(0.5_dp, 0.0_dp, kind=
dp), matrices(w_output))
2782 CALL cp_cfm_power(matrices(w_chi), exponent=1.0_dp, threshold=cutoff)
2784 matrices(w_chi),
z_zero, matrices(w_tmp))
2786 matrices(w_metric),
z_zero, matrices(w_dielectric))
2790 cmplx(0.5_dp, 0.0_dp, kind=
dp), matrices(w_output))
2794 cpabort(
"Screened dielectric Cholesky factorization failed")
2797 IF (info /= 0) cpabort(
"Screened dielectric Cholesky inversion failed")
2803 matrices(w_dielectric),
z_zero, matrices(w_tmp))
2805 matrices(w_metric),
z_zero, matrices(w_output))
2806 CALL get_owner_matrix(matrices(w_output), output_owner, group_env, root, n)
2807 END SUBROUTINE grouped_w_solve
2815 SUBROUTINE grouped_w_release(matrices, matrix_struct, blacs)
2816 TYPE(
cp_cfm_type),
INTENT(INOUT) :: matrices(n_w_matrices)
2827 END SUBROUTINE grouped_w_release
2836 CHARACTER(LEN=*),
PARAMETER :: routinen =
'release_gw_work'
2841 CALL timeset(routinen, handle)
2843 gwkp_env => bs_env%gwkp_env
2845 IF (
ALLOCATED(gwkp_env%eigenvalues_G))
DEALLOCATE (gwkp_env%eigenvalues_G)
2847 cpassert(.NOT.
ASSOCIATED(gwkp_env%gamma_corr_d))
2848 cpassert(.NOT.
ASSOCIATED(gwkp_env%gamma_corr_h))
2849 cpassert(.NOT.
ASSOCIATED(gwkp_env%gamma_corr_s))
2850 cpassert(.NOT.
ASSOCIATED(gwkp_env%gamma_corr_index_to_cell))
2851 cpassert(.NOT.
ASSOCIATED(gwkp_env%gamma_corr_cell_to_index))
2852 DEALLOCATE (bs_env%gwkp_env)
2855 CALL timestop(handle)
static GRID_HOST_DEVICE int modulo(int a, int m)
Equivalent of Fortran's MODULO, which always return a positive number. https://gcc....
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.
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
Basic linear algebra operations for complex full matrices.
subroutine, public cp_cfm_scale_and_add(alpha, matrix_a, beta, matrix_b)
Scale and add two BLACS matrices (a = alpha*a + beta*b).
subroutine, public cp_cfm_transpose(matrix, trans, matrixt)
Transposes a BLACS distributed complex matrix.
subroutine, public cp_cfm_uplo_to_full(matrix, workspace, uplo)
...
subroutine, public cp_cfm_add_on_diag(matrix, alpha, n_active)
Adds a scalar to the diagonal of a distributed complex full matrix.
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.
used for collecting diagonalization schemes available for cp_cfm_type
subroutine, public cp_cfm_power(matrix, work, exponent, threshold, n_dependent, verbose, eigvals)
Raise the positive spectral part of a Hermitian matrix to a real power. Eigenmodes with eigenvalues b...
Represents a complex full matrix distributed on many processors.
subroutine, public cp_cfm_get_submatrix(fm, target_m, start_row, start_col, n_rows, n_cols, transpose)
Extract a sub-matrix from the full matrix: op(target_m)(1:n_rows,1:n_cols) = fm(start_row:start_row+n...
subroutine, public cp_cfm_release(matrix)
Releases a full matrix.
subroutine, public cp_cfm_create(matrix, matrix_struct, name, nrow, ncol, set_zero)
Creates a new full matrix with the given structure.
subroutine, public cp_cfm_set_submatrix(matrix, new_values, start_row, start_col, n_rows, n_cols, alpha, beta, transpose)
Set a sub-matrix of the full matrix: matrix(start_row:start_row+n_rows,start_col:start_col+n_cols) = ...
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
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 fft_3d(plan, scale, zin, zout, stat)
...
subroutine, public fft_destroy_plan(plan)
...
subroutine, public fft_create_plan_3d(plan, fft_in_place, fsign, n, zin, zout)
...
Type to store data about a (1D or 3D) FFT, including FFTW plan.
Gamma-point (q = 0) correction of W and Σ for periodic RI-RS GW.
subroutine, public add_gamma_corr_cell_correction(bs_env, cells, model, i_t, z_head, first_pair, w_grid_r)
Add the Gamma-correction head and wings of one time point to the local grid pairs....
subroutine, public singular_head_cell_factors(bs_env, cells, factors)
Integrate 1/q**2 (3D) or 1/|q| (2D slab) over the distinct shifted-mesh cells around Gamma....
subroutine, public gamma_point_correction(bs_env, qs_env, gwkp_env)
Gamma-correction head and wing coefficients for the near-Gamma cells. Construct the q->0 dielectric l...
subroutine, public add_gamma_corr_pair_cell(bs_env, cells, icell, head_scalar, head_vector, first_pair, values_r, wing_left, wing_right)
Scatter one low-rank Gamma correction into the centred grid-pair images. For s=nearest_integer[H^{-1}...
RI lattice matrices, real-space cells and data distribution shared by χ, W, Σ and the Gamma correctio...
real(kind=dp) function, public ri_metric_head_zero(bs_env)
Zero-wave-vector Fourier value of the selected RI metric kernel.
subroutine, public build_ri_2c_lattice(fm_r, cells, potential, regularization, bs_env, qs_env, reference_basis)
Form distributed I_PQ(R) = (φ_P,0 | v | φ_Q,R) over every screened neighbor cell.
real(kind=dp), parameter, public complex_bytes
subroutine, public gamma_auxiliary_charges(qs_env, charge)
Integrate each auxiliary function for the Gamma charge-mode projection. For a primitive x^(2m) exp(-α...
pure subroutine, public block_range(n, rank, n_rank, first, n_local)
Return the contiguous part of 1..n owned by one rank of a block distribution.
real(kind=dp), parameter, public real_bytes
subroutine, public assemble_aa_contraction(bs_env, u_pp)
Assembles the q-independent, atom-diagonal AA contraction from stored coefficients.
subroutine, public owned_mo_coefficients(bs_env, mo_coeff, coeff)
Dense MO coefficients of the cyclically owned SCF k points (owner of k: MODULO(k-1,...
subroutine, public ri_2c_lattice_to_kp(fm_r, cells, qpoint, matrix_q)
Evaluate I_PQ(q) = sum_R exp(i q.R) I_PQ(R) collectively into an existing dense matrix.
subroutine, public build_full_cell_grid(bs_env, index_to_cell)
Construct a complete cell grid dual to the uniform SCF k-point mesh.
Work data of periodic RI-RS GW with full k-point sampling.
Green functions, screening and self-energy for periodic RI-RS GW.
subroutine, public release_gw_work(bs_env)
Release all periodic RI-RS work data after the last quasiparticle iteration.
subroutine, public compute_w0(qs_env, bs_env, gwkp_env)
Compute ε, Wᶜ and its imaginary-time transform, Eqs. (7)-(8).
subroutine, public prepare_ri_rs(bs_env, gwkp_env)
Prepare RI-RS radial data, grid values, and Bloch orbitals.
subroutine, public compute_g_and_chi(qs_env, bs_env, gwkp_env)
Form the grid Green functions and RI polarizability.
subroutine, public compute_sigma_c_from_w_pq(bs_env, gwkp_env)
Form Σc with one owner per ordered (l,l') pair through both lattice FFTs.
subroutine, public compute_sigma_x(bs_env, gwkp_env)
Evaluate exchange and prepare band orbitals for correlation.
Full-matrix operations not provided by the CP2K FM packages.
subroutine, public local_complex_power(matrix, exponent, eps, cond_nr, min_ev, max_ev, relative_eps)
Compute a spectral power of a local complex Hermitian matrix. Eigenvalues not larger than eps (or rel...
Defines the basic variable types.
integer, parameter, public int_8
integer, parameter, public dp
Routines to compute the Coulomb integral V_(alpha beta)(k) for a k-point k using lattice summation in...
subroutine, public add_ewald_reciprocal(v_k, qs_env, kpoints, basis_type, omega, ikp_start, ikp_end)
Adds the reciprocal Ewald part sum_L exp(ik*L) (P 0 | erf(omega r)/r | Q L) to the dense V_PQ(k) of t...
Batched lattice Fourier transforms on regular k-point grids.
subroutine, public k_grid_to_cell_prepare(work, xkp, nkp_grid, index_to_cell, weights, allow_incomplete)
Prepare one inverse lattice transform for repeated matrix batches.
logical function, public regular_kpoint_grid(xkp, nkp_grid, grid_index, k_offset, allow_incomplete)
Test and map a uniformly shifted reciprocal grid or an explicitly allowed subset.
subroutine, public k_grid_to_cell_execute(work, values_k, values_rs, used_fft)
Execute a matrix batch using the prepared inverse lattice transform. Call outside OpenMP worker regio...
integer function, public lattice_fft_num_threads(nfft, nentries)
Bound concurrent forward transforms to 64 MiB of scratch, or one grid if larger.
subroutine, public k_grid_to_cell_release(work)
Release call-scoped inverse lattice maps and FFT buffers.
subroutine, public cell_to_k_grid_fft(values_rs, index_to_cell, xkp, nkp_grid, values_k, used_fft, deriv_direction, hmat, selected_kpoints)
Transform real matrices to a regular reciprocal grid or any subset of that grid.
logical function, public lattice_fft_shape(n, nfft, allow_arbitrary)
Find backend-supported FFT dimensions that preserve the original lattice grid. Sample the padded tran...
Machine interface based on Fortran 2003 and POSIX.
subroutine, public m_flush(lunit)
flushes units if the &GLOBAL flag is set accordingly
real(kind=dp) function, public m_walltime()
returns time from a real-time clock, protected against rolling early/easily
Definition of mathematical constants and functions.
complex(kind=dp), parameter, public z_one
complex(kind=dp), parameter, public gaussi
real(kind=dp), parameter, public fourpi
real(kind=dp), parameter, public twopi
complex(kind=dp), parameter, public z_zero
Interface to the message passing library MPI.
subroutine, public mp_para_env_release(para_env)
releases the para object (to be called when you don't want anymore the shared copy of this object)
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.
basic linear algebra operations for full matrixes
Main setup file for RI-RS grids {r_l}.
subroutine, public setup_ri_rs_grid(bs_env, grid_points)
Get RI-RS grid points {r_l}, either by on-the-fly optimization or reading pretabulated atomic grids.
AO sampling, D_llp(R), and the periodic RI-RS fit Z_lP(q).
subroutine, public compute_z_lp_q(bs_env, grid_points, z_lp_q, z_lp_zero)
Build explicit-cell AO values and periodic RI-RS coefficients Z_lP(q).
subroutine, public evaluate_mu_rl_r_values(bs_env, grid_points, i_cell, ao_values)
Evaluate ϕ_μ(r_l-R) locally for one cell R and the supplied points r_l.
Geometry and AO evaluation for real-space resolution of the identity.
subroutine, public precompute_ri_rs_radii(ri_rs, basis_set_ao, basis_set_ri, eps, unit_nr)
Compute per-atom AO and RI basis radii from the most diffuse Gaussian primitive in the AO ("ORB") and...
represent a blacs multidimensional parallel environment (for the mpi corrispective see cp_paratypes/m...
Represent a complex full matrix.
keeps the information about the structure of a full matrix
values(P,Q,j) stores one q point, with j an imaginary frequency or time. Each q allocation can be rel...
stores all the informations relevant to an mpi environment