50 dbt_batched_contract_finalize, dbt_batched_contract_init, dbt_clear, dbt_contract, &
51 dbt_create, dbt_destroy, dbt_get_block, dbt_get_stored_coordinates, &
52 dbt_iterator_blocks_left, dbt_iterator_next_block, dbt_iterator_start, dbt_iterator_stop, &
53 dbt_iterator_type, dbt_pgrid_create, dbt_pgrid_destroy, dbt_pgrid_type, dbt_type
71#include "./base/base_uses.f90"
77 CHARACTER(len=*),
PARAMETER,
PRIVATE :: moduleN =
'bse_bs_env_link'
82 INTEGER,
PARAMETER,
PRIVATE :: mo_block_size = 64
107 CHARACTER(LEN=*),
PARAMETER :: routinen =
'bse_from_bs_env'
109 INTEGER :: handle, ispin, n_mo_real, n_ri, n_spin, &
111 INTEGER,
ALLOCATABLE,
DIMENSION(:) :: homo_full, homo_red, virt_red
112 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:, :) :: eigenval_dft, eigenval_qp
114 TYPE(
cp_fm_type) :: fm_eps_inv, fm_m_inv_v_sqrt
115 TYPE(
cp_fm_type),
ALLOCATABLE,
DIMENSION(:) :: fm_s_ab, fm_s_ia, fm_s_ij
120 CALL timeset(routinen, handle)
127 IF (.NOT.
ASSOCIATED(bs_env)) cpabort(
"PROPERTIES%BSE found no GW environment (bs_env)")
130 IF (.NOT. bs_env%do_gw .OR. bs_env%do_periodic .OR. bs_env%do_gw_ri_rs .OR. bs_env%nkp_bs_and_DOS /= 1)
THEN
131 cpabort(
"PROPERTIES%BSE needs a non-periodic, Gamma-only GW without RI_RS")
134 IF (.NOT. (bs_env%keep_W_freq_zero .AND. bs_env%keep_3c_nl) .OR. &
135 .NOT.
ASSOCIATED(bs_env%fm_W_MIC_freq_zero%matrix_struct))
THEN
136 cpabort(
"PROPERTIES%BSE: the GW kept no static W(0) or no 3c neighbour list")
139 IF (bs_env%num_tensor_groups < 1 .OR. bs_env%tensor_group_color < 0)
THEN
140 cpabort(
"PROPERTIES%BSE: the tensor groups of the GW are not set")
143 n_spin = bs_env%n_spin
146 n_mo_real = min(bs_env%n_mo_retained, bs_env%n_ao)
152 CALL link_window(bs_env, bse_env, n_mo_real, window, homo_red, virt_red, unit_nr)
153 n_window = window%last_mo - window%first_mo + 1
155 CALL link_screening(qs_env, bs_env, unit_nr, fm_m_inv_v_sqrt, fm_eps_inv, &
160 ALLOCATE (fm_s_ia(n_spin), fm_s_ij(n_spin), fm_s_ab(n_spin))
161 ALLOCATE (eigenval_qp(n_window, n_spin), eigenval_dft(n_window, n_spin), homo_full(n_spin))
163 CALL link_slabs(qs_env, bs_env, bse_env, ispin, window, homo_red(ispin), virt_red(ispin), fm_m_inv_v_sqrt, &
164 fm_s_ij(ispin), fm_s_ia(ispin), fm_s_ab(ispin), unit_nr)
165 eigenval_qp(:, ispin) = bs_env%eigenval_GW(window%first_mo:window%last_mo, 1, ispin)
166 eigenval_dft(:, ispin) = bs_env%eigenval_scf_Gamma(window%first_mo:window%last_mo, ispin)
167 homo_full(ispin) = bs_env%n_occ(ispin)
173 eigenval_qp, eigenval_dft, homo_full, homo_red, virt_red, &
174 n_ri, qs_env, unit_nr)
176 CALL bse_solve(bse_env, bs_env%fm_mo_coeff_Gamma(1:n_spin), unit_nr)
179 CALL timestop(handle)
195 SUBROUTINE link_window(bs_env, bse_env, n_mo_real, window, homo_red, virt_red, unit_nr)
198 INTEGER,
INTENT(IN) :: n_mo_real
200 INTEGER,
ALLOCATABLE,
DIMENSION(:),
INTENT(OUT) :: homo_red, virt_red
201 INTEGER,
INTENT(IN) :: unit_nr
203 CHARACTER(LEN=*),
PARAMETER :: routinen =
'link_window'
205 INTEGER :: handle, ispin, n_spin
206 INTEGER,
ALLOCATABLE,
DIMENSION(:) :: homo, n_mo
208 CALL timeset(routinen, handle)
210 n_spin = bs_env%n_spin
211 ALLOCATE (n_mo(n_spin), homo(n_spin), homo_red(n_spin), virt_red(n_spin))
213 homo(:) = bs_env%n_occ(1:n_spin)
215 bse_env%bse_cutoff_occ, bse_env%bse_cutoff_empty, window, warn=.true.)
217 homo_red(ispin) = homo(ispin) - window%first_mo + 1
218 virt_red(ispin) = window%last_mo - homo(ispin)
219 IF (homo_red(ispin) < 1) cpabort(
"PROPERTIES%BSE: ENERGY_CUTOFF_OCC leaves no occupied level")
220 IF (virt_red(ispin) < 1) cpabort(
"PROPERTIES%BSE: ENERGY_CUTOFF_EMPTY leaves no empty level")
222 IF (unit_nr > 0)
WRITE (unit_nr,
'(T2,A4,T7,A,T61,2I10)')
'BSE|', &
223 'Active window on the DFT axis (first, last MO)', window%first_mo, window%last_mo
224 DEALLOCATE (n_mo, homo)
226 CALL timestop(handle)
228 END SUBROUTINE link_window
250 SUBROUTINE link_screening(qs_env, bs_env, unit_nr, fm_M_inv_V_sqrt, fm_eps_inv, need_screening)
253 INTEGER,
INTENT(IN) :: unit_nr
254 TYPE(
cp_fm_type),
INTENT(OUT) :: fm_m_inv_v_sqrt, fm_eps_inv
255 LOGICAL,
INTENT(IN) :: need_screening
257 CHARACTER(LEN=*),
PARAMETER :: routinen =
'link_screening'
259 INTEGER :: handle, n_dependent, n_ri
260 TYPE(
cp_fm_type) :: fm_v_inv_sqrt, fm_v_sqrt, fm_wc, fm_work
261 TYPE(
cp_fm_type),
ALLOCATABLE,
DIMENSION(:, :) :: fm_m, fm_v
262 TYPE(libint_potential_type) :: coulomb_op
264 CALL timeset(routinen, handle)
268 CALL ri_2c_integral_mat(qs_env, fm_v, bs_env%fm_RI_RI%matrix_struct, n_ri, coulomb_op)
269 IF (need_screening)
THEN
270 CALL ri_2c_integral_mat(qs_env, fm_m, bs_env%fm_RI_RI%matrix_struct, n_ri, bs_env%ri_metric)
274 CALL cp_fm_create(fm_v_sqrt, bs_env%fm_RI_RI%matrix_struct)
275 CALL cp_fm_create(fm_work, bs_env%fm_RI_RI%matrix_struct)
277 CALL cp_fm_power(fm_v_sqrt, fm_work, 0.5_dp, bs_env%eps_eigval_mat_RI, n_dependent)
278 IF (unit_nr > 0 .AND. n_dependent > 0)
WRITE (unit_nr,
'(T2,A4,T7,A,T71,I10)')
'BSE|', &
279 'RI Coulomb directions dropped by the eigenvalue threshold', n_dependent
282 CALL cp_fm_create(fm_m_inv_v_sqrt, bs_env%fm_RI_RI%matrix_struct)
283 CALL parallel_gemm(
"N",
"N", n_ri, n_ri, n_ri, 1.0_dp, bs_env%fm_Minv_Gamma, fm_v_sqrt, &
284 0.0_dp, fm_m_inv_v_sqrt)
286 IF (need_screening)
THEN
287 CALL cp_fm_create(fm_v_inv_sqrt, bs_env%fm_RI_RI%matrix_struct)
289 CALL cp_fm_power(fm_v_inv_sqrt, fm_work, -0.5_dp, bs_env%eps_eigval_mat_RI, n_dependent)
296 CALL cp_fm_create(fm_eps_inv, bs_env%fm_RI_RI%matrix_struct)
308 CALL timestop(handle)
310 END SUBROUTINE link_screening
328 SUBROUTINE link_mo_tensor(bs_env, dbcsr_dist, ispin, window, sizes_mo, t_C)
331 INTEGER,
INTENT(IN) :: ispin
333 INTEGER,
DIMENSION(:),
INTENT(IN) :: sizes_mo
334 TYPE(dbt_type),
INTENT(OUT) :: t_c
336 CHARACTER(LEN=*),
PARAMETER :: routinen =
'link_mo_tensor'
338 INTEGER :: handle, n_window
339 INTEGER,
ALLOCATABLE,
DIMENSION(:) :: dist_1, dist_2
340 INTEGER,
DIMENSION(2) :: pdims_2d
345 TYPE(dbt_pgrid_type) :: pgrid_2d
347 CALL timeset(routinen, handle)
349 n_window = window%last_mo - window%first_mo + 1
351 IF (sum(sizes_mo) /= n_window) cpabort(
"MO block sizes do not sum to the active window")
354 CALL dbt_pgrid_create(bs_env%para_env_tensor, pdims_2d, pgrid_2d)
355 CALL create_2c_tensor(t_c, dist_1, dist_2, pgrid_2d, bs_env%sizes_AO, sizes_mo, name=
"(AO | MO)")
356 DEALLOCATE (dist_1, dist_2)
357 CALL dbt_pgrid_destroy(pgrid_2d)
361 NULLIFY (struct_c_window)
362 CALL cp_fm_struct_create(struct_c_window, template_fmstruct=bs_env%fm_mo_coeff_Gamma(ispin)%matrix_struct, &
363 ncol_global=n_window)
366 CALL cp_fm_to_fm_submat(bs_env%fm_mo_coeff_Gamma(ispin), fm_c_window, bs_env%n_ao, n_window, 1, window%first_mo, 1, 1)
367 CALL link_matrix_round_robin(dbcsr_dist, bs_env%sizes_AO, sizes_mo,
"C window", dist_global, mat_global)
369 CALL dbcsr_get_info(bs_env%mat_ao_ao_tensor%matrix, distribution=dist_tmpl)
370 CALL link_matrix_round_robin(dist_tmpl, bs_env%sizes_AO, sizes_mo,
"C window, group", dist_group, mat_group)
371 CALL cp_fm_to_dbt(fm_c_window, mat_global, mat_group, t_c, bs_env%para_env, &
372 bs_env%para_env_tensor%num_pe, bs_env%eps_filter)
380 CALL timestop(handle)
382 END SUBROUTINE link_mo_tensor
394 SUBROUTINE link_matrix_round_robin(dist_tmpl, row_sizes, col_sizes, matrix_name, matrix_dist, new_matrix)
396 INTEGER,
DIMENSION(:),
INTENT(IN) :: row_sizes, col_sizes
397 CHARACTER(LEN=*),
INTENT(IN) :: matrix_name
401 INTEGER :: i_block, npcols, nprows
402 INTEGER,
DIMENSION(:),
POINTER :: col_blk, col_dist, row_blk, row_dist
404 NULLIFY (col_blk, col_dist, row_blk, row_dist)
406 ALLOCATE (row_dist(
SIZE(row_sizes)), col_dist(
SIZE(col_sizes)), row_blk(
SIZE(row_sizes)), col_blk(
SIZE(col_sizes)))
407 row_dist(:) = [(mod(i_block - 1, nprows), i_block=1,
SIZE(row_sizes))]
408 col_dist(:) = [(mod(i_block - 1, npcols), i_block=1,
SIZE(col_sizes))]
409 row_blk(:) = row_sizes(:)
410 col_blk(:) = col_sizes(:)
412 CALL dbcsr_create(new_matrix, name=matrix_name, dist=matrix_dist, matrix_type=dbcsr_type_no_symmetry, &
413 row_blk_size=row_blk, col_blk_size=col_blk)
414 DEALLOCATE (row_dist, col_dist, row_blk, col_blk)
416 END SUBROUTINE link_matrix_round_robin
426 SUBROUTINE link_sector_blocks(n_occ, n_virt, block_sizes, n_block_occ)
427 INTEGER,
INTENT(IN) :: n_occ, n_virt
428 INTEGER,
ALLOCATABLE,
DIMENSION(:),
INTENT(OUT) :: block_sizes
429 INTEGER,
INTENT(OUT) :: n_block_occ
431 INTEGER :: n_block_virt
433 n_block_occ = (n_occ - 1)/mo_block_size + 1
434 n_block_virt = (n_virt - 1)/mo_block_size + 1
435 ALLOCATE (block_sizes(n_block_occ + n_block_virt))
436 block_sizes(:) = mo_block_size
437 block_sizes(n_block_occ) = n_occ - (n_block_occ - 1)*mo_block_size
438 block_sizes(n_block_occ + n_block_virt) = n_virt - (n_block_virt - 1)*mo_block_size
440 END SUBROUTINE link_sector_blocks
450 SUBROUTINE link_ri_batches(sizes_RI, max_RI_per_batch, batch_first, batch_last)
451 INTEGER,
DIMENSION(:),
INTENT(IN) :: sizes_ri
452 INTEGER,
INTENT(IN) :: max_ri_per_batch
453 INTEGER,
ALLOCATABLE,
DIMENSION(:),
INTENT(OUT) :: batch_first, batch_last
455 INTEGER :: i_atom, n_atom, n_batch, n_ri_in_batch
456 INTEGER,
ALLOCATABLE,
DIMENSION(:) :: first_atom, last_atom
458 n_atom =
SIZE(sizes_ri)
459 ALLOCATE (first_atom(n_atom), last_atom(n_atom))
462 DO i_atom = 1, n_atom
463 IF (n_ri_in_batch > 0 .AND. n_ri_in_batch + sizes_ri(i_atom) > max_ri_per_batch)
THEN
464 last_atom(n_batch) = i_atom - 1
467 IF (n_ri_in_batch == 0)
THEN
468 n_batch = n_batch + 1
469 first_atom(n_batch) = i_atom
471 n_ri_in_batch = n_ri_in_batch + sizes_ri(i_atom)
473 last_atom(n_batch) = n_atom
474 ALLOCATE (batch_first(n_batch), batch_last(n_batch))
475 batch_first(:) = first_atom(1:n_batch)
476 batch_last(:) = last_atom(1:n_batch)
477 DEALLOCATE (first_atom, last_atom)
479 END SUBROUTINE link_ri_batches
494 SUBROUTINE link_batch_budget(bs_env, bse_env, n_window, unit_nr, budget_bytes, max_RI_per_batch)
497 INTEGER,
INTENT(IN) :: n_window, unit_nr
498 INTEGER(KIND=int_8),
INTENT(OUT) :: budget_bytes
499 INTEGER,
INTENT(OUT) :: max_ri_per_batch
501 CHARACTER(LEN=16) :: left_str, need_str
502 INTEGER(KIND=int_8) :: bytes_per_ri, largest_batch_bytes, &
504 REAL(kind=
dp) :: mem_left_gb
507 budget_bytes = int(mem_left_gb*1.0e9_dp, kind=
int_8)
512 bytes_per_ri = 8_int_8*((int(bs_env%n_ao,
int_8)**2 + int(bs_env%n_ao,
int_8)*int(n_window,
int_8) + &
513 int(n_window,
int_8)**2)/int(bs_env%para_env_tensor%num_pe,
int_8) + &
514 4_int_8*int(n_window,
int_8)**2/int(bs_env%para_env%num_pe,
int_8))
515 max_ri_per_batch = int(max(1_int_8, min(int(sum(bs_env%sizes_RI),
int_8), budget_bytes/bytes_per_ri)))
516 one_atom_bytes = int(maxval(bs_env%sizes_RI),
int_8)*bytes_per_ri
517 largest_batch_bytes = max(int(max_ri_per_batch,
int_8)*bytes_per_ri, one_atom_bytes)
518 IF (unit_nr > 0)
THEN
519 WRITE (unit_nr,
'(T2,A4,T7,A,T67,F14.3)')
'BSE|',
'Memory per MPI rank for the BSE, MEMORY_PER_PROC (GB)', &
520 bse_env%memory_per_proc_gb
521 WRITE (unit_nr,
'(T2,A4,T7,A,T67,F14.3)')
'BSE|',
'Left for the 3c integrals after the memory held (GB)', &
523 WRITE (unit_nr,
'(T2,A4,T7,A,T67,F14.3)')
'BSE|',
'Largest RI batch per MPI rank (GB)', &
524 REAL(largest_batch_bytes,
dp)*1.0e-9_dp
527 IF (one_atom_bytes > budget_bytes)
THEN
528 WRITE (need_str,
'(F16.3)') real(one_atom_bytes,
dp)*1.0e-9_dp
529 WRITE (left_str,
'(F16.3)') mem_left_gb
530 CALL cp_warn(__location__, &
531 "PROPERTIES%BSE: the 3c integral batch of one RI atom needs "//trim(adjustl(need_str))// &
532 " GB per MPI rank, "//trim(adjustl(left_str))//
" GB are left of MEMORY_PER_PROC; one atom "// &
533 "per batch. Raise MEMORY_PER_PROC or use more MPI ranks.")
536 END SUBROUTINE link_batch_budget
558 SUBROUTINE link_slabs(qs_env, bs_env, bse_env, ispin, window, n_occ, n_virt, fm_M_inv_V_sqrt, fm_S_ij, fm_S_ia, &
563 INTEGER,
INTENT(IN) :: ispin
565 INTEGER,
INTENT(IN) :: n_occ, n_virt
566 TYPE(
cp_fm_type),
INTENT(IN) :: fm_m_inv_v_sqrt
567 TYPE(
cp_fm_type),
INTENT(OUT) :: fm_s_ij, fm_s_ia, fm_s_ab
568 INTEGER,
INTENT(IN) :: unit_nr
570 CHARACTER(LEN=*),
PARAMETER :: routinen =
'link_slabs'
572 INTEGER :: atom_first, atom_last, handle, i_batch, &
573 max_ri_per_batch, n_batch, &
574 n_block_occ, n_ri, n_window
575 INTEGER(KIND=int_8) :: budget_bytes
576 INTEGER,
ALLOCATABLE,
DIMENSION(:) :: batch_first, batch_last, dist_1, dist_2, &
577 dist_3, sizes_p, sizes_q
578 INTEGER,
DIMENSION(3) :: pdims_3d
582 TYPE(dbt_pgrid_type) :: pgrid_3d
583 TYPE(dbt_type) :: t_3c, t_3c_half, t_3c_mo, t_c_p, t_c_q
585 CALL timeset(routinen, handle)
587 NULLIFY (blacs_env, dbcsr_dist, struct_ab, struct_ia, struct_ij)
588 CALL get_qs_env(qs_env, blacs_env=blacs_env, dbcsr_dist=dbcsr_dist)
590 n_window = n_occ + n_virt
592 nrow_global=n_ri, ncol_global=n_occ*n_occ)
594 nrow_global=n_ri, ncol_global=n_occ*n_virt)
596 nrow_global=n_ri, ncol_global=n_virt*n_virt)
598 CALL cp_fm_create(fm_s_ij, struct_ij, name=
"fm_S_ij", set_zero=.true.)
599 CALL cp_fm_create(fm_s_ia, struct_ia, name=
"fm_S_ia", set_zero=.true.)
600 CALL cp_fm_create(fm_s_ab, struct_ab, name=
"fm_S_ab", set_zero=.true.)
607 ALLOCATE (sizes_q(2))
608 sizes_q(:) = [n_occ, n_virt]
609 CALL link_sector_blocks(n_occ, n_virt, sizes_p, n_block_occ)
610 CALL link_mo_tensor(bs_env, dbcsr_dist, ispin, window, sizes_q, t_c_q)
611 CALL link_mo_tensor(bs_env, dbcsr_dist, ispin, window, sizes_p, t_c_p)
613 CALL link_batch_budget(bs_env, bse_env, n_window, unit_nr, budget_bytes, max_ri_per_batch)
614 CALL link_ri_batches(bs_env%sizes_RI, max_ri_per_batch, batch_first, batch_last)
615 n_batch =
SIZE(batch_first)
616 IF (unit_nr > 0)
WRITE (unit_nr,
'(T2,A4,T7,A,T71,I10)')
'BSE|',
'RI atom batches of the 3c integral transformation', n_batch
620 CALL dbt_pgrid_create(bs_env%para_env_tensor, pdims_3d, pgrid_3d)
621 CALL create_3c_tensor(t_3c_half, dist_1, dist_2, dist_3, pgrid_3d, bs_env%sizes_RI, bs_env%sizes_AO, &
622 sizes_q, map1=[1, 2], map2=[3], name=
"(RI AO | MO)")
623 DEALLOCATE (dist_1, dist_2, dist_3)
624 CALL dbt_pgrid_destroy(pgrid_3d)
626 CALL dbt_pgrid_create(bs_env%para_env_tensor, pdims_3d, pgrid_3d, &
627 tensor_dims=[bs_env%n_atom,
SIZE(sizes_q),
SIZE(sizes_p)])
628 CALL create_3c_tensor(t_3c_mo, dist_1, dist_2, dist_3, pgrid_3d, bs_env%sizes_RI, sizes_q, sizes_p, &
629 map1=[1], map2=[2, 3], name=
"(RI | MO MO)")
630 DEALLOCATE (dist_1, dist_2, dist_3)
631 CALL dbt_pgrid_destroy(pgrid_3d)
632 CALL dbt_create(bs_env%t_RI_AO__AO, t_3c)
637 CALL dbt_batched_contract_init(t_c_q)
639 DO i_batch = 1, n_batch
640 atom_first = batch_first(i_batch)
641 atom_last = batch_last(i_batch)
643 IF (
modulo(i_batch - 1, bs_env%num_tensor_groups) == bs_env%tensor_group_color)
THEN
646 CALL dbt_contract(alpha=1.0_dp, tensor_1=t_3c, tensor_2=t_c_q, beta=0.0_dp, tensor_3=t_3c_half, &
647 contract_1=[3], notcontract_1=[1, 2], map_1=[1, 2], &
648 contract_2=[1], notcontract_2=[2], map_2=[3], &
649 filter_eps=bs_env%eps_filter)
652 CALL dbt_contract(alpha=1.0_dp, tensor_1=t_3c_half, tensor_2=t_c_p, beta=0.0_dp, tensor_3=t_3c_mo, &
653 contract_1=[2], notcontract_1=[1, 3], map_1=[1, 2], &
654 contract_2=[1], notcontract_2=[2], map_2=[3], &
655 filter_eps=bs_env%eps_filter)
656 CALL dbt_clear(t_3c_half)
658 CALL link_slab_rows(bs_env, blacs_env, dbcsr_dist, t_3c_mo, n_occ, n_virt, sizes_p, n_block_occ, atom_first, atom_last, &
659 fm_s_ij, fm_s_ia, fm_s_ab)
660 CALL dbt_clear(t_3c_mo)
663 CALL dbt_batched_contract_finalize(t_c_q)
664 CALL dbt_destroy(t_3c)
665 CALL dbt_destroy(t_3c_half)
666 CALL dbt_destroy(t_3c_mo)
667 CALL dbt_destroy(t_c_q)
668 CALL dbt_destroy(t_c_p)
669 DEALLOCATE (sizes_q, sizes_p, batch_first, batch_last)
672 CALL apply_ri_transform(fm_m_inv_v_sqrt, fm_s_ij, n_ri, n_occ*n_occ, budget_bytes)
673 CALL apply_ri_transform(fm_m_inv_v_sqrt, fm_s_ia, n_ri, n_occ*n_virt, budget_bytes)
674 CALL apply_ri_transform(fm_m_inv_v_sqrt, fm_s_ab, n_ri, n_virt*n_virt, budget_bytes)
676 CALL timestop(handle)
678 END SUBROUTINE link_slabs
703 SUBROUTINE link_slab_rows(bs_env, blacs_env, dbcsr_dist, t_3c_mo, n_occ, n_virt, sizes_p, n_block_occ, atom_first, atom_last, &
704 fm_S_ij, fm_S_ia, fm_S_ab)
708 TYPE(dbt_type),
INTENT(INOUT) :: t_3c_mo
709 INTEGER,
INTENT(IN) :: n_occ, n_virt
710 INTEGER,
DIMENSION(:),
INTENT(IN) :: sizes_p
711 INTEGER,
INTENT(IN) :: n_block_occ, atom_first, atom_last
712 TYPE(
cp_fm_type),
INTENT(IN) :: fm_s_ij, fm_s_ia, fm_s_ab
714 CHARACTER(LEN=*),
PARAMETER :: routinen =
'link_slab_rows'
715 INTEGER,
PARAMETER :: pair_ab = 3, pair_ia = 2, pair_ij = 1
717 INTEGER :: col_block, group_handle, handle, i_pair, my_rank, n_atom_batch, n_block_p, &
718 n_ri_batch, npcol, nprow, owner_rank, p_block, q_block, rank, ri_first, row_block
719 INTEGER,
ALLOCATABLE,
DIMENSION(:, :) :: cart_coords
720 INTEGER,
DIMENSION(3) :: blk_index, blk_size, n_col_blocks, &
721 n_cols_pair, p_block_offset, &
723 INTEGER,
DIMENSION(:),
POINTER :: col_dist, col_sizes, row_dist, row_sizes
724 INTEGER,
DIMENSION(:, :),
POINTER :: pgrid
726 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:, :, :) :: block_pqp
730 TYPE(
dbcsr_type),
DIMENSION(3) :: mat_global, mat_group
731 TYPE(dbt_iterator_type) :: iter
733 CALL timeset(routinen, handle)
735 NULLIFY (col_dist, col_sizes, pgrid, row_dist, row_sizes, struct_batch)
736 ri_first = bs_env%i_RI_start_from_atom(atom_first)
737 n_ri_batch = bs_env%i_RI_end_from_atom(atom_last) - ri_first + 1
738 n_atom_batch = atom_last - atom_first + 1
739 n_block_p =
SIZE(sizes_p)
740 n_cols_pair = [n_occ*n_occ, n_occ*n_virt, n_virt*n_virt]
741 n_col_blocks = [n_block_occ, n_block_occ, n_block_p - n_block_occ]
742 q_block_of_pair = [1, 2, 2]
744 p_block_offset = [0, 0, n_block_occ]
748 associate(cart => t_3c_mo%pgrid%mp_comm_2d)
750 group_handle = cart%get_handle()
751 nprow = cart%num_pe_cart(1)
752 npcol = cart%num_pe_cart(2)
753 ALLOCATE (cart_coords(2, 0:cart%num_pe - 1), pgrid(0:nprow - 1, 0:npcol - 1))
754 DO rank = 0, cart%num_pe - 1
755 CALL cart%coords(rank, cart_coords(:, rank))
756 pgrid(cart_coords(1, rank), cart_coords(2, rank)) = rank
759 ALLOCATE (row_dist(n_atom_batch), row_sizes(n_atom_batch))
760 DO row_block = 1, n_atom_batch
761 CALL dbt_get_stored_coordinates(t_3c_mo, [atom_first + row_block - 1, 1, 1], owner_rank)
762 row_dist(row_block) = cart_coords(1, owner_rank)
763 row_sizes(row_block) = bs_env%sizes_RI(atom_first + row_block - 1)
766 ALLOCATE (col_dist(n_col_blocks(i_pair)), col_sizes(n_col_blocks(i_pair)))
767 DO col_block = 1, n_col_blocks(i_pair)
768 p_block = p_block_offset(i_pair) + col_block
769 CALL dbt_get_stored_coordinates(t_3c_mo, [atom_first, q_block_of_pair(i_pair), p_block], owner_rank)
770 col_dist(col_block) = cart_coords(2, owner_rank)
772 col_sizes(col_block) = merge(n_occ, n_virt, i_pair == pair_ij)*sizes_p(p_block)
775 row_dist=row_dist, col_dist=col_dist)
776 CALL dbcsr_create(mat_group(i_pair), name=
"(P|qp) batch, group", dist=dist_group(i_pair), &
777 matrix_type=dbcsr_type_no_symmetry, row_blk_size=row_sizes, col_blk_size=col_sizes)
781 CALL link_matrix_round_robin(dbcsr_dist, row_sizes, col_sizes,
"(P|qp) batch", dist_global(i_pair), mat_global(i_pair))
782 DEALLOCATE (col_dist, col_sizes)
784 DEALLOCATE (pgrid, cart_coords, row_dist, row_sizes)
790 CALL dbt_iterator_start(iter, t_3c_mo)
791 DO WHILE (dbt_iterator_blocks_left(iter))
792 CALL dbt_iterator_next_block(iter, blk_index, blk_size=blk_size)
793 q_block = blk_index(2)
794 p_block = blk_index(3)
797 IF (q_block == 1 .AND. p_block > n_block_occ) cycle
798 IF (q_block == 1)
THEN
800 ELSE IF (p_block <= n_block_occ)
THEN
805 ALLOCATE (block_pqp(blk_size(1), blk_size(2), blk_size(3)))
806 CALL dbt_get_block(t_3c_mo, blk_index, blk_size, block_pqp, found)
808 row_block = blk_index(1) - atom_first + 1
809 col_block = p_block - p_block_offset(i_pair)
812 IF (owner_rank /= my_rank) cpabort(
"(P|qp) block is not local to its group matrix")
814 reshape(block_pqp, [blk_size(1), blk_size(2)*blk_size(3)]))
816 DEALLOCATE (block_pqp)
818 CALL dbt_iterator_stop(iter)
825 nrow_global=n_ri_batch, ncol_global=n_cols_pair(i_pair))
834 CALL cp_fm_to_fm_submat(fm_batch, fm_s_ij, n_ri_batch, n_cols_pair(i_pair), 1, 1, ri_first, 1)
836 CALL cp_fm_to_fm_submat(fm_batch, fm_s_ia, n_ri_batch, n_cols_pair(i_pair), 1, 1, ri_first, 1)
838 CALL cp_fm_to_fm_submat(fm_batch, fm_s_ab, n_ri_batch, n_cols_pair(i_pair), 1, 1, ri_first, 1)
847 CALL timestop(handle)
849 END SUBROUTINE link_slab_rows
861 SUBROUTINE apply_ri_transform(fm_M_inv_V_sqrt, fm_slab, n_RI, n_cols, budget_bytes)
862 TYPE(cp_fm_type),
INTENT(IN) :: fm_m_inv_v_sqrt, fm_slab
863 INTEGER,
INTENT(IN) :: n_ri, n_cols
864 INTEGER(KIND=int_8),
INTENT(IN) :: budget_bytes
866 CHARACTER(LEN=*),
PARAMETER :: routinen =
'apply_ri_transform'
868 INTEGER :: col_first, handle, max_cols_chunk, &
870 TYPE(cp_fm_struct_type),
POINTER :: struct_work
871 TYPE(cp_fm_type) :: fm_work
873 CALL timeset(routinen, handle)
875 max_cols_chunk = int(max(1_int_8, min(int(n_cols, int_8), &
876 budget_bytes*int(fm_slab%matrix_struct%para_env%num_pe, int_8) &
877 /(8_int_8*int(n_ri, int_8)))))
878 NULLIFY (struct_work)
879 CALL cp_fm_struct_create(struct_work, para_env=fm_slab%matrix_struct%para_env, &
880 context=fm_slab%matrix_struct%context, nrow_global=n_ri, ncol_global=max_cols_chunk)
881 CALL cp_fm_create(fm_work, struct_work)
882 CALL cp_fm_struct_release(struct_work)
883 DO col_first = 1, n_cols, max_cols_chunk
884 n_cols_chunk = min(max_cols_chunk, n_cols - col_first + 1)
887 CALL parallel_gemm(
"T",
"N", n_ri, n_cols_chunk, n_ri, 1.0_dp, fm_m_inv_v_sqrt, fm_slab, 0.0_dp, fm_work, &
888 b_first_col=col_first, c_first_col=1)
889 CALL cp_fm_to_fm_submat(fm_work, fm_slab, nrow=n_ri, ncol=n_cols_chunk, s_firstrow=1, s_firstcol=1, &
890 t_firstrow=1, t_firstcol=col_first)
892 CALL cp_fm_release(fm_work)
894 CALL timestop(handle)
896 END SUBROUTINE apply_ri_transform
static GRID_HOST_DEVICE int modulo(int a, int m)
Equivalent of Fortran's MODULO, which always return a positive number. https://gcc....
Bethe-Salpeter equation on the RI-AO GW, the GW of PROPERTIESBANDSTRUCTUREGW with explicit three-cent...
subroutine, public bse_from_bs_env(qs_env, bse_section)
Entry from the properties driver after the bandstructure block. Hands the solver core what its kernel...
Main routines for GW + Bethe-Salpeter for computing electronic excitations: a GW path prepares the BS...
subroutine, public prepare_bse_env_from_bandstructure_gw(bse_env, fm_s_ia, fm_s_ij, fm_s_ab, fm_eps_inv, eigenval_qp, eigenval_dft, homo_full, homo_red, virt_red, dimen_ri, qs_env, unit_nr)
Entry for the BSE of PROPERTIESBANDSTRUCTUREGW (PROPERTIESBSE), which hands over window-sized slabs a...
subroutine, public bse_solve(bse_env, mo_coeff, unit_nr)
Solves the BSE on a prepared environment: input normalisation, the screened slabs from [1+Q(0)]^-1,...
Matrix-free application of the BSE matrices A and B to trial vectors from RI slabs that are sliced al...
real(kind=dp) function, public bse_memory_left_gb(memory_per_proc_gb, para_env)
What MEMORY_PER_PROC leaves to a step: the resolved memory per MPI rank minus the memory the rank hol...
subroutine, public bse_resolve_memory_per_proc(memory_per_proc_gb, para_env, unit_nr)
MEMORY_PER_PROC of the BSE as a number: the keyword's value, or for -1 the memory the rank holds plus...
The BSE environment: the settings of the &BSE section and the state a GW path prepares for the solver...
subroutine, public bse_env_release(bse_env)
Releases the state a GW path prepared and nullifies the QS pointers; the settings stay,...
Auxiliary routines for GW + Bethe-Salpeter for computing electronic excitations.
subroutine, public adapt_bse_screening(bse_env, unit_nr)
Resolve SCREENING_IN_W and its factor before constructing the dielectric matrix or slabs.
subroutine, public bse_window_from_dft(eigenval_scf, n_mo, homo, cutoff_occ, cutoff_empty, window, warn)
The active MO window on the DFT axis: one absolute MO range for every spin; when the spin windows dif...
methods related to the blacs parallel environment
subroutine, public dbcsr_distribution_release(dist)
...
subroutine, public dbcsr_distribution_new(dist, template, group, pgrid, row_dist, col_dist, reuse_arrays)
...
subroutine, public dbcsr_get_info(matrix, nblkrows_total, nblkcols_total, nfullrows_total, nfullcols_total, nblkrows_local, nblkcols_local, nfullrows_local, nfullcols_local, my_prow, my_pcol, local_rows, local_cols, proc_row_dist, proc_col_dist, row_blk_size, col_blk_size, row_blk_offset, col_blk_offset, distribution, name, matrix_type, group)
...
subroutine, public dbcsr_get_stored_coordinates(matrix, row, column, processor)
...
subroutine, public dbcsr_work_create(matrix, nblks_guess, sizedata_guess, n, work_mutable)
...
subroutine, public dbcsr_finalize(matrix)
...
subroutine, public dbcsr_release(matrix)
...
subroutine, public dbcsr_put_block(matrix, row, col, block, summation)
...
subroutine, public dbcsr_distribution_get(dist, row_dist, col_dist, nrows, ncols, has_threads, group, mynode, numnodes, nprows, npcols, myprow, mypcol, pgrid, subgroups_defined, prow_group, pcol_group)
...
DBCSR operations in CP2K.
subroutine, public copy_dbcsr_to_fm(matrix, fm, plan, check_plan)
Copy a DBCSR matrix to a BLACS matrix.
Redistribution of DBCSR blocks and distributed matrix slices.
subroutine, public cp_dbcsr_from_subgroups(mat_local, mat_global, para_env, row_mapping, copy_only)
Sum subgroup blocks into the global layout, or copy mapped blocks.
Basic linear algebra operations for full matrices.
subroutine, public cp_fm_scale_and_add(alpha, matrix_a, beta, matrix_b)
calc A <- alpha*A + beta*B optimized for alpha == 1.0 (just add beta*B) and beta == 0....
used for collecting some of the diagonalization schemes available for cp_fm_type. cp_fm_power also mo...
subroutine, public cp_fm_power(matrix, work, exponent, threshold, n_dependent, verbose, eigvals)
...
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_to_fm_submat(msource, mtarget, nrow, ncol, s_firstrow, s_firstcol, t_firstrow, t_firstcol)
copy just a part ot the matrix
subroutine, public cp_fm_set_all(matrix, alpha, beta)
set all elements of a matrix to the same value, and optionally the diagonal to a different one
subroutine, public cp_fm_create(matrix, matrix_struct, name, nrow, ncol, set_zero)
creates a new full matrix with the given structure
various routines to log and control the output. The idea is that decisions about where to log should ...
integer function, public cp_logger_get_default_io_unit(logger)
returns the unit nr for the ionode (-1 on all other processors) skips as well checks if the procs cal...
type(cp_logger_type) function, pointer, public cp_get_default_logger()
returns the default logger
This is the start of a dbt_api, all publically needed functions are exported here....
Redistribute matrices between full-matrix and tensor process layouts.
subroutine, public cp_fm_to_dbt(fm_global, mat_global, mat_local, tensor, para_env, num_pe_sub, eps_filter, block_row_ranges)
...
Routines from paper [Graml2024].
subroutine, public compute_3c_integrals(qs_env, bs_env, t_3c, atoms_ao_1, atoms_ao_2, atoms_ri)
...
Full-matrix operations not provided by the CP2K FM packages.
Defines the basic variable types.
integer, parameter, public int_8
integer, parameter, public dp
2- and 3-center electron repulsion integral routines based on libint2 Currently available operators: ...
Common selection and union operations for contiguous molecular-orbital windows.
Framework for 2c-integrals for RI.
subroutine, public ri_2c_integral_mat(qs_env, fm_matrix_minv_l_gamma, fm_matrix_l_struct, dimen_ri, ri_metric, put_mat_ks_env, regularization_ri)
...
basic linear algebra operations for full matrixes
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, matrix_vhxc, 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, xcint_weights, 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.
Utility methods to build 3-center integral tensors of various types.
subroutine, public create_2c_tensor(t2c, dist_1, dist_2, pgrid, sizes_1, sizes_2, order, name)
...
subroutine, public create_3c_tensor(t3c, dist_1, dist_2, dist_3, pgrid, sizes_1, sizes_2, sizes_3, map1, map2, name)
...
Utility methods to build 3-center integral tensors of various types.
subroutine, public neighbor_list_3c_destroy(ijk_list)
Destroy 3c neighborlist.
Settings of the &BSE section (read_bse_section, re-read before every BSE run, normalised in place by ...
represent a blacs multidimensional parallel environment (for the mpi corrispective see cp_paratypes/m...
keeps the information about the structure of a full matrix
type of a logger, at the moment it contains just a print level starting at which level it should be l...