Line data Source code
1 : !--------------------------------------------------------------------------------------------------!
2 : ! CP2K: A general program to perform molecular dynamics simulations !
3 : ! Copyright 2000-2024 CP2K developers group <https://cp2k.org> !
4 : ! !
5 : ! SPDX-License-Identifier: GPL-2.0-or-later !
6 : !--------------------------------------------------------------------------------------------------!
7 :
8 : ! **************************************************************************************************
9 : !> \brief Calls routines to get RI integrals and calculate total energies
10 : !> \par History
11 : !> 10.2011 created [Joost VandeVondele and Mauro Del Ben]
12 : !> 07.2019 split from mp2_gpw.F [Frederick Stein]
13 : ! **************************************************************************************************
14 : MODULE mp2_gpw
15 : USE atomic_kind_types, ONLY: atomic_kind_type
16 : USE basis_set_types, ONLY: get_gto_basis_set,&
17 : gto_basis_set_p_type,&
18 : gto_basis_set_type
19 : USE cell_types, ONLY: cell_type,&
20 : get_cell
21 : USE cp_blacs_env, ONLY: BLACS_GRID_SQUARE,&
22 : cp_blacs_env_create,&
23 : cp_blacs_env_release,&
24 : cp_blacs_env_type
25 : USE cp_control_types, ONLY: dft_control_type
26 : USE cp_dbcsr_api, ONLY: &
27 : dbcsr_clear_mempools, dbcsr_copy, dbcsr_create, dbcsr_distribution_release, &
28 : dbcsr_distribution_type, dbcsr_filter, dbcsr_init_p, dbcsr_iterator_blocks_left, &
29 : dbcsr_iterator_next_block, dbcsr_iterator_start, dbcsr_iterator_stop, dbcsr_iterator_type, &
30 : dbcsr_p_type, dbcsr_release, dbcsr_reserve_all_blocks, dbcsr_type, dbcsr_type_no_symmetry, &
31 : dbcsr_type_real_default, dbcsr_type_symmetric
32 : USE cp_dbcsr_cp2k_link, ONLY: cp_dbcsr_alloc_block_from_nbl
33 : USE cp_dbcsr_operations, ONLY: cp_dbcsr_dist2d_to_dist,&
34 : cp_dbcsr_m_by_n_from_row_template
35 : USE cp_fm_types, ONLY: cp_fm_get_info,&
36 : cp_fm_release,&
37 : cp_fm_type
38 : USE cp_log_handling, ONLY: &
39 : cp_add_default_logger, cp_get_default_logger, cp_logger_create, &
40 : cp_logger_get_default_unit_nr, cp_logger_release, cp_logger_set, cp_logger_type, &
41 : cp_rm_default_logger, cp_to_string
42 : USE dbt_api, ONLY: dbt_type
43 : USE distribution_1d_types, ONLY: distribution_1d_release,&
44 : distribution_1d_type
45 : USE distribution_2d_types, ONLY: distribution_2d_release,&
46 : distribution_2d_type
47 : USE distribution_methods, ONLY: distribute_molecules_1d,&
48 : distribute_molecules_2d
49 : USE group_dist_types, ONLY: create_group_dist,&
50 : get_group_dist,&
51 : group_dist_d1_type,&
52 : release_group_dist
53 : USE hfx_types, ONLY: block_ind_type,&
54 : hfx_compression_type
55 : USE input_constants, ONLY: &
56 : do_eri_gpw, do_eri_os, do_potential_coulomb, do_potential_id, do_potential_truncated, &
57 : eri_default, mp2_method_gpw, ri_default, ri_mp2_method_gpw, rpa_exchange_none
58 : USE input_section_types, ONLY: section_vals_val_get
59 : USE kinds, ONLY: dp
60 : USE kpoint_types, ONLY: kpoint_type
61 : USE libint_wrapper, ONLY: cp_libint_static_cleanup,&
62 : cp_libint_static_init
63 : USE machine, ONLY: default_output_unit,&
64 : m_flush
65 : USE message_passing, ONLY: mp_para_env_release,&
66 : mp_para_env_type
67 : USE molecule_kind_types, ONLY: molecule_kind_type
68 : USE molecule_types, ONLY: molecule_type
69 : USE mp2_cphf, ONLY: solve_z_vector_eq
70 : USE mp2_gpw_method, ONLY: mp2_gpw_compute
71 : USE mp2_integrals, ONLY: mp2_ri_gpw_compute_in
72 : USE mp2_ri_gpw, ONLY: mp2_ri_gpw_compute_en
73 : USE mp2_ri_grad, ONLY: calc_ri_mp2_nonsep
74 : USE mp2_types, ONLY: mp2_type,&
75 : three_dim_real_array
76 : USE particle_methods, ONLY: get_particle_set
77 : USE particle_types, ONLY: particle_type
78 : USE qs_environment_types, ONLY: get_qs_env,&
79 : qs_environment_type
80 : USE qs_integral_utils, ONLY: basis_set_list_setup
81 : USE qs_interactions, ONLY: init_interaction_radii
82 : USE qs_kind_types, ONLY: get_qs_kind,&
83 : qs_kind_type
84 : USE qs_ks_types, ONLY: qs_ks_env_type
85 : USE qs_mo_types, ONLY: get_mo_set,&
86 : mo_set_type
87 : USE qs_neighbor_list_types, ONLY: neighbor_list_set_p_type,&
88 : release_neighbor_list_sets
89 : USE qs_neighbor_lists, ONLY: atom2d_build,&
90 : atom2d_cleanup,&
91 : build_neighbor_lists,&
92 : local_atoms_type,&
93 : pair_radius_setup
94 : USE rpa_main, ONLY: rpa_ri_compute_en
95 : USE rpa_rse, ONLY: rse_energy
96 : #include "./base/base_uses.f90"
97 :
98 : IMPLICIT NONE
99 :
100 : PRIVATE
101 :
102 : CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'mp2_gpw'
103 :
104 : PUBLIC :: mp2_gpw_main, create_mat_munu, grep_rows_in_subgroups, build_dbcsr_from_rows
105 :
106 : CONTAINS
107 :
108 : ! **************************************************************************************************
109 : !> \brief with a big bang to mp2
110 : !> \param qs_env ...
111 : !> \param mp2_env ...
112 : !> \param Emp2 ...
113 : !> \param Emp2_Cou ...
114 : !> \param Emp2_EX ...
115 : !> \param Emp2_S ...
116 : !> \param Emp2_T ...
117 : !> \param mos_mp2 ...
118 : !> \param para_env ...
119 : !> \param unit_nr ...
120 : !> \param calc_forces ...
121 : !> \param calc_ex ...
122 : !> \param do_ri_mp2 ...
123 : !> \param do_ri_rpa ...
124 : !> \param do_ri_sos_laplace_mp2 ...
125 : !> \author Mauro Del Ben and Joost VandeVondele
126 : ! **************************************************************************************************
127 632 : SUBROUTINE mp2_gpw_main(qs_env, mp2_env, Emp2, Emp2_Cou, Emp2_EX, Emp2_S, Emp2_T, &
128 632 : mos_mp2, para_env, unit_nr, calc_forces, calc_ex, do_ri_mp2, do_ri_rpa, &
129 : do_ri_sos_laplace_mp2)
130 : TYPE(qs_environment_type), POINTER :: qs_env
131 : TYPE(mp2_type) :: mp2_env
132 : REAL(KIND=dp), INTENT(OUT) :: Emp2, Emp2_Cou, Emp2_EX, Emp2_S, Emp2_T
133 : TYPE(mo_set_type), DIMENSION(:), INTENT(IN) :: mos_mp2
134 : TYPE(mp_para_env_type), POINTER :: para_env
135 : INTEGER, INTENT(IN) :: unit_nr
136 : LOGICAL, INTENT(IN) :: calc_forces, calc_ex
137 : LOGICAL, INTENT(IN), OPTIONAL :: do_ri_mp2, do_ri_rpa, &
138 : do_ri_sos_laplace_mp2
139 :
140 : CHARACTER(LEN=*), PARAMETER :: routineN = 'mp2_gpw_main'
141 :
142 : INTEGER :: blacs_grid_layout, bse_lev_virt, color_sub, dimen, dimen_RI, dimen_RI_red, &
143 : eri_method, handle, ispin, local_unit_nr, my_group_L_end, my_group_L_size, &
144 : my_group_L_start, nmo, nspins, potential_type, ri_metric_type
145 632 : INTEGER, ALLOCATABLE, DIMENSION(:) :: ends_array_mc, ends_array_mc_block, gw_corr_lev_occ, &
146 632 : gw_corr_lev_virt, homo, starts_array_mc, starts_array_mc_block
147 : INTEGER, DIMENSION(3) :: periodic
148 : LOGICAL :: blacs_repeatable, do_bse, do_im_time, do_kpoints_cubic_RPA, my_do_gw, &
149 : my_do_ri_mp2, my_do_ri_rpa, my_do_ri_sos_laplace_mp2
150 : REAL(KIND=dp) :: Emp2_AB, Emp2_BB, Emp2_Cou_BB, &
151 : Emp2_EX_BB, eps_gvg_rspace_old, &
152 : eps_pgf_orb_old, eps_rho_rspace_old
153 632 : REAL(KIND=dp), ALLOCATABLE, DIMENSION(:, :) :: Eigenval
154 632 : REAL(KIND=dp), ALLOCATABLE, DIMENSION(:, :, :) :: BIb_C_bse_ab, BIb_C_bse_ij
155 632 : REAL(KIND=dp), DIMENSION(:), POINTER :: mo_eigenvalues
156 632 : TYPE(atomic_kind_type), DIMENSION(:), POINTER :: atomic_kind_set
157 : TYPE(block_ind_type), ALLOCATABLE, &
158 632 : DIMENSION(:, :, :) :: t_3c_O_ind
159 : TYPE(cell_type), POINTER :: cell
160 : TYPE(cp_blacs_env_type), POINTER :: blacs_env_sub, blacs_env_sub_mat_munu
161 : TYPE(cp_fm_type) :: fm_matrix_PQ
162 632 : TYPE(cp_fm_type), ALLOCATABLE, DIMENSION(:) :: mo_coeff
163 632 : TYPE(cp_fm_type), ALLOCATABLE, DIMENSION(:, :) :: fm_matrix_L_kpoints, fm_matrix_Minv, &
164 632 : fm_matrix_Minv_L_kpoints, &
165 632 : fm_matrix_Minv_Vtrunc_Minv
166 : TYPE(cp_fm_type), POINTER :: mo_coeff_ptr
167 : TYPE(cp_logger_type), POINTER :: logger, logger_sub
168 : TYPE(dbcsr_p_type) :: mat_munu, mat_P_global
169 632 : TYPE(dbcsr_p_type), ALLOCATABLE, DIMENSION(:) :: mo_coeff_all, mo_coeff_gw, mo_coeff_o, &
170 632 : mo_coeff_o_bse, mo_coeff_v, &
171 632 : mo_coeff_v_bse
172 632 : TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: matrix_s
173 632 : TYPE(dbcsr_p_type), DIMENSION(:, :), POINTER :: matrix_s_kp
174 4424 : TYPE(dbt_type) :: t_3c_M
175 632 : TYPE(dbt_type), ALLOCATABLE, DIMENSION(:, :) :: t_3c_O
176 : TYPE(dft_control_type), POINTER :: dft_control
177 632 : TYPE(group_dist_d1_type) :: gd_array, gd_B_all, gd_B_occ_bse, &
178 632 : gd_B_virt_bse
179 : TYPE(group_dist_d1_type), ALLOCATABLE, &
180 632 : DIMENSION(:) :: gd_B_virtual
181 : TYPE(hfx_compression_type), ALLOCATABLE, &
182 632 : DIMENSION(:, :, :) :: t_3c_O_compressed
183 : TYPE(kpoint_type), POINTER :: kpoints, kpoints_from_DFT
184 632 : TYPE(mo_set_type), DIMENSION(:), POINTER :: mos
185 : TYPE(mp_para_env_type), POINTER :: para_env_sub
186 : TYPE(neighbor_list_set_p_type), DIMENSION(:), &
187 632 : POINTER :: sab_orb_sub
188 632 : TYPE(particle_type), DIMENSION(:), POINTER :: particle_set
189 632 : TYPE(qs_kind_type), DIMENSION(:), POINTER :: qs_kind_set
190 : TYPE(qs_ks_env_type), POINTER :: ks_env
191 : TYPE(three_dim_real_array), ALLOCATABLE, &
192 632 : DIMENSION(:) :: BIb_C, BIb_C_gw
193 :
194 632 : CALL timeset(routineN, handle)
195 :
196 : ! check if we want to do ri-mp2
197 632 : my_do_ri_mp2 = .FALSE.
198 632 : IF (PRESENT(do_ri_mp2)) my_do_ri_mp2 = do_ri_mp2
199 :
200 : ! check if we want to do ri-rpa
201 632 : my_do_ri_rpa = .FALSE.
202 632 : IF (PRESENT(do_ri_rpa)) my_do_ri_rpa = do_ri_rpa
203 :
204 : ! check if we want to do ri-sos-laplace-mp2
205 632 : my_do_ri_sos_laplace_mp2 = .FALSE.
206 632 : IF (PRESENT(do_ri_sos_laplace_mp2)) my_do_ri_sos_laplace_mp2 = do_ri_sos_laplace_mp2
207 :
208 : ! GW and SOS-MP2 cannot be used together
209 632 : IF (my_do_ri_sos_laplace_mp2) THEN
210 58 : CPASSERT(.NOT. mp2_env%ri_rpa%do_ri_g0w0)
211 : END IF
212 :
213 : ! check if we want to do imaginary time
214 632 : do_im_time = mp2_env%do_im_time
215 632 : do_bse = qs_env%mp2_env%ri_g0w0%do_bse
216 632 : do_kpoints_cubic_RPA = qs_env%mp2_env%ri_rpa_im_time%do_im_time_kpoints
217 :
218 632 : IF (do_kpoints_cubic_RPA .AND. mp2_env%ri_rpa%do_ri_g0w0) THEN
219 0 : CPABORT("Full RPA k-points (DO_KPOINTS in LOW_SCALING section) not implemented with GW")
220 : END IF
221 :
222 : ! Get the number of spins
223 632 : nspins = SIZE(mos_mp2)
224 :
225 : ! ... setup needed to be able to qs_integrate in a subgroup.
226 632 : IF (do_kpoints_cubic_RPA) THEN
227 4 : CALL get_qs_env(qs_env=qs_env, dft_control=dft_control, kpoints=kpoints_from_DFT)
228 4 : mos(1:nspins) => kpoints_from_DFT%kp_env(1)%kpoint_env%mos(1:nspins, 1)
229 : ELSE
230 628 : CALL get_qs_env(qs_env=qs_env, dft_control=dft_control, mos=mos)
231 : END IF
232 632 : CALL get_mo_set(mo_set=mos_mp2(1), nao=dimen)
233 5830 : ALLOCATE (homo(nspins), Eigenval(dimen, nspins), mo_coeff(nspins))
234 1406 : DO ispin = 1, nspins
235 : CALL get_mo_set(mo_set=mos_mp2(ispin), &
236 : eigenvalues=mo_eigenvalues, nmo=nmo, homo=homo(ispin), &
237 774 : mo_coeff=mo_coeff_ptr)
238 774 : mo_coeff(ispin) = mo_coeff_ptr
239 17032 : Eigenval(:, ispin) = mo_eigenvalues(:)
240 : END DO
241 :
242 : ! a para_env
243 632 : color_sub = para_env%mepos/mp2_env%mp2_num_proc
244 632 : ALLOCATE (para_env_sub)
245 632 : CALL para_env_sub%from_split(para_env, color_sub)
246 :
247 : ! each of the sub groups might need to generate output
248 632 : logger => cp_get_default_logger()
249 632 : IF (para_env%is_source()) THEN
250 316 : local_unit_nr = cp_logger_get_default_unit_nr(logger, local=.FALSE.)
251 : ELSE
252 316 : local_unit_nr = default_output_unit
253 : END IF
254 :
255 : ! get stuff
256 : CALL get_qs_env(qs_env, &
257 : ks_env=ks_env, &
258 : qs_kind_set=qs_kind_set, &
259 : cell=cell, &
260 : particle_set=particle_set, &
261 : atomic_kind_set=atomic_kind_set, &
262 : dft_control=dft_control, &
263 632 : matrix_s_kp=matrix_s_kp)
264 :
265 632 : CALL get_cell(cell=cell, periodic=periodic)
266 :
267 632 : IF (do_im_time) THEN
268 :
269 134 : IF (mp2_env%ri_metric%potential_type == ri_default) THEN
270 420 : IF (SUM(periodic) == 1 .OR. SUM(periodic) == 3) THEN
271 6 : mp2_env%ri_metric%potential_type = do_potential_id
272 : ELSE
273 54 : mp2_env%ri_metric%potential_type = do_potential_truncated
274 : END IF
275 : END IF
276 :
277 : ! statically initialize libint
278 134 : CALL cp_libint_static_init()
279 :
280 : END IF
281 :
282 632 : IF (mp2_env%ri_metric%potential_type == ri_default) THEN
283 286 : mp2_env%ri_metric%potential_type = do_potential_coulomb
284 : END IF
285 :
286 632 : IF (mp2_env%eri_method == eri_default) THEN
287 1048 : IF (SUM(periodic) > 0) mp2_env%eri_method = do_eri_gpw
288 1048 : IF (SUM(periodic) == 0) mp2_env%eri_method = do_eri_os
289 1048 : IF (SUM(mp2_env%ri_rpa_im_time%kp_grid) > 0) mp2_env%eri_method = do_eri_os
290 262 : IF (mp2_env%method == mp2_method_gpw) mp2_env%eri_method = do_eri_gpw
291 262 : IF (mp2_env%method == ri_mp2_method_gpw) mp2_env%eri_method = do_eri_gpw
292 262 : IF (mp2_env%ri_rpa_im_time%do_im_time_kpoints) mp2_env%eri_method = do_eri_os
293 262 : IF (calc_forces .AND. mp2_env%eri_method == do_eri_os) mp2_env%eri_method = do_eri_gpw
294 : END IF
295 632 : eri_method = mp2_env%eri_method
296 :
297 632 : IF (unit_nr > 0 .AND. mp2_env%eri_method == do_eri_gpw) THEN
298 : WRITE (UNIT=unit_nr, FMT="(T3,A,T71,F10.1)") &
299 176 : "GPW_INFO| Density cutoff [a.u.]:", mp2_env%mp2_gpw%cutoff*0.5_dp
300 : WRITE (UNIT=unit_nr, FMT="(T3,A,T71,F10.1)") &
301 176 : "GPW_INFO| Relative density cutoff [a.u.]:", mp2_env%mp2_gpw%relative_cutoff*0.5_dp
302 176 : CALL m_flush(unit_nr)
303 : END IF
304 :
305 632 : IF (.NOT. mp2_env%ri_g0w0%print_local_bandgap) THEN
306 : ! a logger
307 626 : NULLIFY (logger_sub)
308 : CALL cp_logger_create(logger_sub, para_env=para_env_sub, &
309 626 : default_global_unit_nr=local_unit_nr, close_global_unit_on_dealloc=.FALSE.)
310 626 : CALL cp_logger_set(logger_sub, local_filename="MP2_localLog")
311 : ! set to a custom print level (we could also have a different print level for para_env%source)
312 626 : logger_sub%iter_info%print_level = mp2_env%mp2_gpw%print_level
313 626 : CALL cp_add_default_logger(logger_sub)
314 : END IF
315 :
316 : ! a blacs_env (ignore the globenv stored defaults for now)
317 632 : blacs_grid_layout = BLACS_GRID_SQUARE
318 632 : blacs_repeatable = .TRUE.
319 632 : NULLIFY (blacs_env_sub)
320 : CALL cp_blacs_env_create(blacs_env_sub, para_env_sub, &
321 : blacs_grid_layout, &
322 632 : blacs_repeatable)
323 :
324 632 : blacs_env_sub_mat_munu => blacs_env_sub
325 :
326 632 : matrix_s(1:1) => matrix_s_kp(1:1, 1)
327 :
328 632 : CALL get_eps_old(dft_control, eps_pgf_orb_old, eps_rho_rspace_old, eps_gvg_rspace_old)
329 :
330 : CALL create_mat_munu(mat_munu, qs_env, mp2_env%mp2_gpw%eps_grid, &
331 : blacs_env_sub_mat_munu, do_alloc_blocks_from_nbl=.NOT. do_im_time, sab_orb_sub=sab_orb_sub, &
332 : do_kpoints=mp2_env%ri_rpa_im_time%do_im_time_kpoints, &
333 632 : dbcsr_sym_type=dbcsr_type_symmetric)
334 :
335 : ! which RI metric we want to have
336 632 : ri_metric_type = mp2_env%ri_metric%potential_type
337 :
338 : ! which interaction potential
339 632 : potential_type = mp2_env%potential_parameter%potential_type
340 :
341 : ! check if we want to do ri-g0w0 on top of ri-rpa
342 632 : my_do_gw = mp2_env%ri_rpa%do_ri_g0w0
343 1896 : ALLOCATE (gw_corr_lev_occ(nspins), gw_corr_lev_virt(nspins))
344 632 : gw_corr_lev_occ(1) = mp2_env%ri_g0w0%corr_mos_occ
345 632 : gw_corr_lev_virt(1) = mp2_env%ri_g0w0%corr_mos_virt
346 632 : IF (nspins == 2) THEN
347 142 : gw_corr_lev_occ(2) = mp2_env%ri_g0w0%corr_mos_occ_beta
348 142 : gw_corr_lev_virt(2) = mp2_env%ri_g0w0%corr_mos_virt_beta
349 : END IF
350 :
351 632 : IF (do_bse) THEN
352 18 : IF (nspins > 1) THEN
353 0 : CPABORT("BSE not implemented for open shell calculations")
354 : END IF
355 : !Keep default behavior for occupied
356 : ! We do not implement an explicit bse_lev_occ here, because the small number of occupied levels
357 : ! does not critically influence the memory
358 18 : bse_lev_virt = gw_corr_lev_virt(1)
359 : END IF
360 :
361 : ! After the components are inside of the routines, we can move this line insight the branch
362 6888 : ALLOCATE (mo_coeff_o(nspins), mo_coeff_v(nspins), mo_coeff_all(nspins), mo_coeff_gw(nspins))
363 :
364 : ! Always allocate for usage in call of replicate_mat_to_subgroup
365 1896 : ALLOCATE (mo_coeff_o_bse(1), mo_coeff_v_bse(1))
366 :
367 : ! for imag. time, we do not need this
368 632 : IF (.NOT. do_im_time) THEN
369 :
370 : ! new routine: replicate a full matrix from one para_env to a smaller one
371 : ! keeping the memory usage as small as possible in this case the
372 : ! output the two part of the C matrix (virtual, occupied)
373 1108 : DO ispin = 1, nspins
374 :
375 : CALL replicate_mat_to_subgroup(para_env, para_env_sub, mo_coeff(ispin), dimen, homo(ispin), mat_munu%matrix, &
376 : mo_coeff_o(ispin)%matrix, mo_coeff_v(ispin)%matrix, &
377 : mo_coeff_all(ispin)%matrix, mo_coeff_gw(ispin)%matrix, &
378 : my_do_gw, gw_corr_lev_occ(ispin), gw_corr_lev_virt(ispin), do_bse, &
379 : bse_lev_virt, mo_coeff_o_bse(1)%matrix, mo_coeff_v_bse(1)%matrix, &
380 1108 : mp2_env%mp2_gpw%eps_filter)
381 :
382 : END DO
383 :
384 : END IF
385 :
386 : ! now we're kind of ready to go....
387 632 : Emp2_S = 0.0_dp
388 632 : Emp2_T = 0.0_dp
389 632 : IF (my_do_ri_mp2 .OR. my_do_ri_rpa .OR. my_do_ri_sos_laplace_mp2) THEN
390 : ! RI-GPW integrals (same stuff for both RPA and MP2)
391 618 : IF (nspins == 2) THEN
392 : ! open shell case (RI) here the (ia|K) integrals are computed for both the alpha and beta components
393 : CALL mp2_ri_gpw_compute_in( &
394 : BIb_C, BIb_C_gw, BIb_C_bse_ij, BIb_C_bse_ab, gd_array, gd_B_virtual, dimen_RI, dimen_RI_red, qs_env, &
395 : para_env, para_env_sub, color_sub, cell, particle_set, &
396 : atomic_kind_set, qs_kind_set, fm_matrix_PQ, fm_matrix_L_kpoints, fm_matrix_Minv_L_kpoints, &
397 : fm_matrix_Minv, fm_matrix_Minv_Vtrunc_Minv, nmo, homo, mat_munu, sab_orb_sub, &
398 : mo_coeff_o, mo_coeff_v, mo_coeff_all, mo_coeff_gw, mo_coeff_o_bse, mo_coeff_v_bse, &
399 : mp2_env%mp2_gpw%eps_filter, unit_nr, &
400 : mp2_env%mp2_memory, mp2_env%calc_PQ_cond_num, calc_forces, blacs_env_sub, my_do_gw .AND. .NOT. do_im_time, &
401 : do_bse, gd_B_all, starts_array_mc, ends_array_mc, starts_array_mc_block, ends_array_mc_block, &
402 : gw_corr_lev_occ(1), gw_corr_lev_virt(1), &
403 : bse_lev_virt, &
404 : do_im_time, do_kpoints_cubic_RPA, kpoints, &
405 : t_3c_M, t_3c_O, t_3c_O_compressed, t_3c_O_ind, &
406 : mp2_env%ri_metric, &
407 276 : gd_B_occ_bse, gd_B_virt_bse)
408 : ELSE
409 : ! closed shell case (RI)
410 : CALL mp2_ri_gpw_compute_in(BIb_C, BIb_C_gw, BIb_C_bse_ij, BIb_C_bse_ab, gd_array, gd_B_virtual, &
411 : dimen_RI, dimen_RI_red, qs_env, para_env, para_env_sub, &
412 : color_sub, cell, particle_set, &
413 : atomic_kind_set, qs_kind_set, fm_matrix_PQ, &
414 : fm_matrix_L_kpoints, fm_matrix_Minv_L_kpoints, &
415 : fm_matrix_Minv, fm_matrix_Minv_Vtrunc_Minv, nmo, homo, &
416 : mat_munu, sab_orb_sub, &
417 : mo_coeff_o, mo_coeff_v, mo_coeff_all, mo_coeff_gw, mo_coeff_o_bse, mo_coeff_v_bse, &
418 : mp2_env%mp2_gpw%eps_filter, unit_nr, &
419 : mp2_env%mp2_memory, mp2_env%calc_PQ_cond_num, calc_forces, &
420 : blacs_env_sub, my_do_gw .AND. .NOT. do_im_time, do_bse, gd_B_all, &
421 : starts_array_mc, ends_array_mc, &
422 : starts_array_mc_block, ends_array_mc_block, &
423 : gw_corr_lev_occ(1), gw_corr_lev_virt(1), &
424 : bse_lev_virt, &
425 : do_im_time, do_kpoints_cubic_RPA, kpoints, &
426 : t_3c_M, t_3c_O, t_3c_O_compressed, t_3c_O_ind, &
427 914 : mp2_env%ri_metric, gd_B_occ_bse, gd_B_virt_bse)
428 : END IF
429 :
430 : ELSE
431 : ! Canonical MP2-GPW
432 14 : IF (nspins == 2) THEN
433 : ! alpha-alpha and alpha-beta components
434 2 : IF (unit_nr > 0) WRITE (unit_nr, *)
435 2 : IF (unit_nr > 0) WRITE (unit_nr, '(T3,A)') 'Alpha (ia|'
436 : CALL mp2_gpw_compute( &
437 : Emp2, Emp2_Cou, Emp2_EX, qs_env, para_env, para_env_sub, color_sub, &
438 : cell, particle_set, &
439 : atomic_kind_set, qs_kind_set, Eigenval, nmo, homo, mat_munu, &
440 : sab_orb_sub, mo_coeff_o, mo_coeff_v, mp2_env%mp2_gpw%eps_filter, unit_nr, &
441 2 : mp2_env%mp2_memory, calc_ex, blacs_env_sub, Emp2_AB)
442 :
443 : ! beta-beta component
444 2 : IF (unit_nr > 0) WRITE (unit_nr, *)
445 2 : IF (unit_nr > 0) WRITE (unit_nr, '(T3,A)') 'Beta (ia|'
446 : CALL mp2_gpw_compute( &
447 : Emp2_BB, Emp2_Cou_BB, Emp2_EX_BB, qs_env, para_env, para_env_sub, color_sub, cell, particle_set, &
448 : atomic_kind_set, qs_kind_set, Eigenval(:, 2:2), nmo, homo(2:2), mat_munu, &
449 : sab_orb_sub, mo_coeff_o(2:2), mo_coeff_v(2:2), mp2_env%mp2_gpw%eps_filter, unit_nr, &
450 2 : mp2_env%mp2_memory, calc_ex, blacs_env_sub)
451 :
452 : ! make order on the MP2 energy contributions
453 2 : Emp2_Cou = Emp2_Cou*0.25_dp
454 2 : Emp2_EX = Emp2_EX*0.5_dp
455 :
456 2 : Emp2_Cou_BB = Emp2_Cou_BB*0.25_dp
457 2 : Emp2_EX_BB = Emp2_EX_BB*0.5_dp
458 :
459 2 : Emp2_S = Emp2_AB
460 2 : Emp2_T = Emp2_Cou + Emp2_Cou_BB + Emp2_EX + Emp2_EX_BB
461 :
462 2 : Emp2_Cou = Emp2_Cou + Emp2_Cou_BB + Emp2_AB
463 2 : Emp2_EX = Emp2_EX + Emp2_EX_BB
464 2 : Emp2 = Emp2_EX + Emp2_Cou
465 :
466 : ELSE
467 : ! closed shell case
468 : CALL mp2_gpw_compute( &
469 : Emp2, Emp2_Cou, Emp2_EX, qs_env, para_env, para_env_sub, color_sub, cell, particle_set, &
470 : atomic_kind_set, qs_kind_set, Eigenval(:, 1:1), nmo, homo(1:1), mat_munu, &
471 : sab_orb_sub, mo_coeff_o(1:1), mo_coeff_v(1:1), mp2_env%mp2_gpw%eps_filter, unit_nr, &
472 12 : mp2_env%mp2_memory, calc_ex, blacs_env_sub)
473 : END IF
474 : END IF
475 :
476 : ! Free possibly large buffers allocated by dbcsr on the GPU,
477 : ! large hybrid dgemm/pdgemm's coming later will need the space.
478 632 : CALL dbcsr_clear_mempools()
479 :
480 632 : IF (calc_forces .AND. .NOT. do_im_time) THEN
481 : ! make a copy of mo_coeff_o and mo_coeff_v
482 1468 : ALLOCATE (mp2_env%ri_grad%mo_coeff_o(nspins), mp2_env%ri_grad%mo_coeff_v(nspins))
483 604 : DO ispin = 1, nspins
484 344 : NULLIFY (mp2_env%ri_grad%mo_coeff_o(ispin)%matrix)
485 344 : CALL dbcsr_init_p(mp2_env%ri_grad%mo_coeff_o(ispin)%matrix)
486 : CALL dbcsr_copy(mp2_env%ri_grad%mo_coeff_o(ispin)%matrix, mo_coeff_o(ispin)%matrix, &
487 344 : name="mo_coeff_o"//cp_to_string(ispin))
488 344 : NULLIFY (mp2_env%ri_grad%mo_coeff_v(ispin)%matrix)
489 344 : CALL dbcsr_init_p(mp2_env%ri_grad%mo_coeff_v(ispin)%matrix)
490 : CALL dbcsr_copy(mp2_env%ri_grad%mo_coeff_v(ispin)%matrix, mo_coeff_v(ispin)%matrix, &
491 604 : name="mo_coeff_v"//cp_to_string(ispin))
492 : END DO
493 260 : CALL get_group_dist(gd_array, color_sub, my_group_L_start, my_group_L_end, my_group_L_size)
494 : END IF
495 : ! Copy mo coeffs for RPA exchange correction
496 632 : IF (mp2_env%ri_rpa%exchange_correction /= rpa_exchange_none) THEN
497 76 : ALLOCATE (mp2_env%ri_rpa%mo_coeff_o(nspins), mp2_env%ri_rpa%mo_coeff_v(nspins))
498 26 : DO ispin = 1, nspins
499 14 : CALL dbcsr_copy(mp2_env%ri_rpa%mo_coeff_o(ispin), mo_coeff_o(ispin)%matrix, name="mo_coeff_o")
500 26 : CALL dbcsr_copy(mp2_env%ri_rpa%mo_coeff_v(ispin), mo_coeff_v(ispin)%matrix, name="mo_coeff_v")
501 : END DO
502 : END IF
503 :
504 632 : IF (.NOT. do_im_time) THEN
505 :
506 1108 : DO ispin = 1, nspins
507 610 : CALL dbcsr_release(mo_coeff_o(ispin)%matrix)
508 610 : DEALLOCATE (mo_coeff_o(ispin)%matrix)
509 610 : CALL dbcsr_release(mo_coeff_v(ispin)%matrix)
510 610 : DEALLOCATE (mo_coeff_v(ispin)%matrix)
511 1108 : IF (my_do_gw) THEN
512 50 : CALL dbcsr_release(mo_coeff_all(ispin)%matrix)
513 50 : DEALLOCATE (mo_coeff_all(ispin)%matrix)
514 : END IF
515 : END DO
516 498 : DEALLOCATE (mo_coeff_o, mo_coeff_v)
517 498 : IF (my_do_gw) DEALLOCATE (mo_coeff_all)
518 :
519 : END IF
520 632 : IF (do_bse) THEN
521 18 : CALL dbcsr_release(mo_coeff_o_bse(1)%matrix)
522 18 : CALL dbcsr_release(mo_coeff_v_bse(1)%matrix)
523 18 : DEALLOCATE (mo_coeff_o_bse(1)%matrix)
524 18 : DEALLOCATE (mo_coeff_v_bse(1)%matrix)
525 : END IF
526 632 : DEALLOCATE (mo_coeff_o_bse, mo_coeff_v_bse)
527 :
528 : ! Release some memory for RPA exchange correction
529 632 : IF (calc_forces .AND. do_im_time .OR. &
530 : (.NOT. calc_forces .AND. mp2_env%ri_rpa%exchange_correction == rpa_exchange_none)) THEN
531 :
532 360 : CALL dbcsr_release(mat_munu%matrix)
533 360 : DEALLOCATE (mat_munu%matrix)
534 :
535 360 : CALL release_neighbor_list_sets(sab_orb_sub)
536 :
537 : END IF
538 :
539 : ! decide if to do RI-RPA or RI-MP2
540 632 : IF (my_do_ri_rpa .OR. my_do_ri_sos_laplace_mp2) THEN
541 :
542 272 : IF (do_im_time) CALL create_matrix_P(mat_P_global, qs_env, mp2_env, para_env)
543 :
544 704 : IF (.NOT. ALLOCATED(BIb_C)) ALLOCATE (BIb_C(nspins))
545 1000 : IF (.NOT. ALLOCATED(BIb_C_gw)) ALLOCATE (BIb_C_gw(nspins))
546 704 : IF (.NOT. ALLOCATED(gd_B_virtual)) ALLOCATE (gd_B_virtual(nspins))
547 :
548 : ! RI-RPA
549 : CALL rpa_ri_compute_en(qs_env, Emp2, mp2_env, BIb_C, BIb_C_gw, BIb_C_bse_ij, BIb_C_bse_ab, &
550 : para_env, para_env_sub, color_sub, &
551 : gd_array, gd_B_virtual, gd_B_all, gd_B_occ_bse, gd_B_virt_bse, &
552 : mo_coeff, fm_matrix_PQ, fm_matrix_L_kpoints, fm_matrix_Minv_L_kpoints, &
553 : fm_matrix_Minv, fm_matrix_Minv_Vtrunc_Minv, kpoints, &
554 : Eigenval, nmo, homo, dimen_RI, dimen_RI_red, gw_corr_lev_occ, gw_corr_lev_virt, &
555 : bse_lev_virt, &
556 : unit_nr, my_do_ri_sos_laplace_mp2, my_do_gw, do_im_time, do_bse, matrix_s, &
557 : mat_munu, mat_P_global, t_3c_M, t_3c_O, t_3c_O_compressed, t_3c_O_ind, &
558 : starts_array_mc, ends_array_mc, &
559 272 : starts_array_mc_block, ends_array_mc_block, calc_forces)
560 :
561 272 : IF (mp2_env%ri_rpa%do_rse) &
562 4 : CALL rse_energy(qs_env, mp2_env, para_env, dft_control, mo_coeff, nmo, homo, Eigenval)
563 :
564 272 : IF (do_im_time) THEN
565 134 : IF (ASSOCIATED(mat_P_global%matrix)) THEN
566 134 : CALL dbcsr_release(mat_P_global%matrix)
567 134 : DEALLOCATE (mat_P_global%matrix)
568 : END IF
569 :
570 134 : CALL cp_libint_static_cleanup()
571 134 : IF (calc_forces) CALL cp_fm_release(fm_matrix_PQ)
572 : END IF
573 :
574 : ! Release some memory for RPA exchange correction
575 272 : IF (mp2_env%ri_rpa%exchange_correction /= rpa_exchange_none) THEN
576 :
577 12 : CALL dbcsr_release(mat_munu%matrix)
578 12 : DEALLOCATE (mat_munu%matrix)
579 :
580 12 : CALL release_neighbor_list_sets(sab_orb_sub)
581 :
582 : END IF
583 :
584 : ELSE
585 360 : IF (my_do_ri_mp2) THEN
586 346 : Emp2 = 0.0_dp
587 346 : Emp2_Cou = 0.0_dp
588 346 : Emp2_EX = 0.0_dp
589 :
590 : ! RI-MP2-GPW compute energy
591 : CALL mp2_ri_gpw_compute_en( &
592 : Emp2_Cou, Emp2_EX, Emp2_S, Emp2_T, BIb_C, mp2_env, para_env, para_env_sub, color_sub, &
593 : gd_array, gd_B_virtual, &
594 346 : Eigenval, nmo, homo, dimen_RI_red, unit_nr, calc_forces, calc_ex)
595 :
596 : END IF
597 : END IF
598 :
599 : ! if we need forces time to calculate the MP2 non-separable contribution
600 : ! and start computing the Lagrangian
601 632 : IF (calc_forces .AND. .NOT. do_im_time) THEN
602 :
603 : CALL calc_ri_mp2_nonsep(qs_env, mp2_env, para_env, para_env_sub, cell, &
604 : particle_set, atomic_kind_set, qs_kind_set, &
605 : mo_coeff, nmo, homo, dimen_RI, Eigenval, &
606 : my_group_L_start, my_group_L_end, my_group_L_size, &
607 260 : sab_orb_sub, mat_munu, blacs_env_sub)
608 :
609 604 : DO ispin = 1, nspins
610 344 : CALL dbcsr_release(mp2_env%ri_grad%mo_coeff_o(ispin)%matrix)
611 344 : DEALLOCATE (mp2_env%ri_grad%mo_coeff_o(ispin)%matrix)
612 :
613 344 : CALL dbcsr_release(mp2_env%ri_grad%mo_coeff_v(ispin)%matrix)
614 604 : DEALLOCATE (mp2_env%ri_grad%mo_coeff_v(ispin)%matrix)
615 : END DO
616 260 : DEALLOCATE (mp2_env%ri_grad%mo_coeff_o, mp2_env%ri_grad%mo_coeff_v)
617 :
618 260 : CALL dbcsr_release(mat_munu%matrix)
619 260 : DEALLOCATE (mat_munu%matrix)
620 :
621 260 : CALL release_neighbor_list_sets(sab_orb_sub)
622 :
623 : END IF
624 :
625 : !XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXx
626 : ! moved from above
627 632 : IF (my_do_gw .AND. .NOT. do_im_time) THEN
628 96 : DO ispin = 1, nspins
629 50 : CALL dbcsr_release(mo_coeff_gw(ispin)%matrix)
630 96 : DEALLOCATE (mo_coeff_gw(ispin)%matrix)
631 : END DO
632 46 : DEALLOCATE (mo_coeff_gw)
633 : END IF
634 :
635 : ! re-init the radii to be able to generate pair lists with MP2-appropriate screening
636 632 : dft_control%qs_control%eps_pgf_orb = eps_pgf_orb_old
637 632 : dft_control%qs_control%eps_rho_rspace = eps_rho_rspace_old
638 632 : dft_control%qs_control%eps_gvg_rspace = eps_gvg_rspace_old
639 632 : CALL init_interaction_radii(dft_control%qs_control, qs_kind_set)
640 :
641 632 : CALL cp_blacs_env_release(blacs_env_sub)
642 :
643 632 : IF (.NOT. mp2_env%ri_g0w0%print_local_bandgap) THEN
644 626 : CALL cp_rm_default_logger()
645 626 : CALL cp_logger_release(logger_sub)
646 : END IF
647 :
648 632 : CALL mp_para_env_release(para_env_sub)
649 :
650 : ! finally solve the z-vector equation if forces are required
651 632 : IF (calc_forces .AND. .NOT. do_im_time) THEN
652 : CALL solve_z_vector_eq(qs_env, mp2_env, para_env, dft_control, &
653 260 : mo_coeff, nmo, homo, Eigenval, unit_nr)
654 : END IF
655 :
656 632 : DEALLOCATE (Eigenval, mo_coeff)
657 :
658 632 : CALL timestop(handle)
659 :
660 5002 : END SUBROUTINE mp2_gpw_main
661 :
662 : ! **************************************************************************************************
663 : !> \brief ...
664 : !> \param para_env ...
665 : !> \param para_env_sub ...
666 : !> \param mo_coeff ...
667 : !> \param dimen ...
668 : !> \param homo ...
669 : !> \param mat_munu ...
670 : !> \param mo_coeff_o ...
671 : !> \param mo_coeff_v ...
672 : !> \param mo_coeff_all ...
673 : !> \param mo_coeff_gw ...
674 : !> \param my_do_gw ...
675 : !> \param gw_corr_lev_occ ...
676 : !> \param gw_corr_lev_virt ...
677 : !> \param my_do_bse ...
678 : !> \param bse_lev_virt ...
679 : !> \param mo_coeff_o_bse ...
680 : !> \param mo_coeff_v_bse ...
681 : !> \param eps_filter ...
682 : ! **************************************************************************************************
683 610 : SUBROUTINE replicate_mat_to_subgroup(para_env, para_env_sub, mo_coeff, dimen, homo, mat_munu, &
684 : mo_coeff_o, mo_coeff_v, mo_coeff_all, mo_coeff_gw, my_do_gw, &
685 : gw_corr_lev_occ, gw_corr_lev_virt, my_do_bse, &
686 : bse_lev_virt, mo_coeff_o_bse, mo_coeff_v_bse, eps_filter)
687 : TYPE(mp_para_env_type), INTENT(IN) :: para_env, para_env_sub
688 : TYPE(cp_fm_type), INTENT(IN) :: mo_coeff
689 : INTEGER, INTENT(IN) :: dimen, homo
690 : TYPE(dbcsr_type), INTENT(INOUT) :: mat_munu
691 : TYPE(dbcsr_type), POINTER :: mo_coeff_o, mo_coeff_v, mo_coeff_all, &
692 : mo_coeff_gw
693 : LOGICAL, INTENT(IN) :: my_do_gw
694 : INTEGER, INTENT(IN) :: gw_corr_lev_occ, gw_corr_lev_virt
695 : LOGICAL, INTENT(IN) :: my_do_bse
696 : INTEGER, INTENT(IN) :: bse_lev_virt
697 : TYPE(dbcsr_type), POINTER :: mo_coeff_o_bse, mo_coeff_v_bse
698 : REAL(KIND=dp), INTENT(IN) :: eps_filter
699 :
700 : CHARACTER(LEN=*), PARAMETER :: routineN = 'replicate_mat_to_subgroup'
701 :
702 : INTEGER :: handle
703 610 : REAL(KIND=dp), ALLOCATABLE, DIMENSION(:, :) :: C
704 610 : TYPE(group_dist_d1_type) :: gd_array
705 :
706 610 : CALL timeset(routineN, handle)
707 :
708 : CALL grep_rows_in_subgroups(para_env, para_env_sub, mo_coeff, gd_array, C)
709 :
710 : ! create and fill mo_coeff_o, mo_coeff_v and mo_coeff_all
711 610 : ALLOCATE (mo_coeff_o)
712 : CALL build_dbcsr_from_rows(para_env_sub, mo_coeff_o, C(:, 1:homo), &
713 610 : mat_munu, gd_array, eps_filter)
714 :
715 610 : ALLOCATE (mo_coeff_v)
716 : CALL build_dbcsr_from_rows(para_env_sub, mo_coeff_v, C(:, homo + 1:dimen), &
717 610 : mat_munu, gd_array, eps_filter)
718 :
719 610 : IF (my_do_gw) THEN
720 50 : ALLOCATE (mo_coeff_gw)
721 : CALL build_dbcsr_from_rows(para_env_sub, mo_coeff_gw, C(:, homo - gw_corr_lev_occ + 1:homo + gw_corr_lev_virt), &
722 50 : mat_munu, gd_array, eps_filter)
723 :
724 : ! all levels
725 50 : ALLOCATE (mo_coeff_all)
726 : CALL build_dbcsr_from_rows(para_env_sub, mo_coeff_all, C, &
727 50 : mat_munu, gd_array, eps_filter)
728 :
729 : END IF
730 :
731 610 : IF (my_do_bse) THEN
732 :
733 18 : ALLOCATE (mo_coeff_o_bse)
734 : CALL build_dbcsr_from_rows(para_env_sub, mo_coeff_o_bse, C(:, 1:homo), &
735 18 : mat_munu, gd_array, eps_filter)
736 :
737 18 : ALLOCATE (mo_coeff_v_bse)
738 : CALL build_dbcsr_from_rows(para_env_sub, mo_coeff_v_bse, C(:, homo + 1:homo + bse_lev_virt), &
739 18 : mat_munu, gd_array, eps_filter)
740 :
741 : END IF
742 610 : DEALLOCATE (C)
743 610 : CALL release_group_dist(gd_array)
744 :
745 610 : CALL timestop(handle)
746 :
747 610 : END SUBROUTINE replicate_mat_to_subgroup
748 :
749 : ! **************************************************************************************************
750 : !> \brief ...
751 : !> \param para_env ...
752 : !> \param para_env_sub ...
753 : !> \param mo_coeff ...
754 : !> \param gd_array ...
755 : !> \param C ...
756 : ! **************************************************************************************************
757 634 : SUBROUTINE grep_rows_in_subgroups(para_env, para_env_sub, mo_coeff, gd_array, C)
758 : TYPE(mp_para_env_type), INTENT(IN) :: para_env, para_env_sub
759 : TYPE(cp_fm_type), INTENT(IN) :: mo_coeff
760 : TYPE(group_dist_d1_type), INTENT(OUT) :: gd_array
761 : REAL(KIND=dp), ALLOCATABLE, DIMENSION(:, :), &
762 : INTENT(OUT) :: C
763 :
764 : CHARACTER(LEN=*), PARAMETER :: routineN = 'grep_rows_in_subgroups'
765 :
766 : INTEGER :: handle, i_global, iiB, j_global, jjB, max_row_col_local, my_mu_end, my_mu_size, &
767 : my_mu_start, ncol_global, ncol_local, ncol_rec, nrow_global, nrow_local, nrow_rec, &
768 : proc_receive_static, proc_send_static, proc_shift
769 634 : INTEGER, ALLOCATABLE, DIMENSION(:, :) :: local_col_row_info, rec_col_row_info
770 634 : INTEGER, DIMENSION(:), POINTER :: col_indices, col_indices_rec, &
771 634 : row_indices, row_indices_rec
772 634 : REAL(KIND=dp), ALLOCATABLE, DIMENSION(:, :) :: local_C, rec_C
773 : REAL(KIND=dp), CONTIGUOUS, DIMENSION(:, :), &
774 634 : POINTER :: local_C_internal
775 :
776 634 : CALL timeset(routineN, handle)
777 :
778 : CALL cp_fm_get_info(matrix=mo_coeff, &
779 : ncol_global=ncol_global, &
780 : nrow_global=nrow_global, &
781 : nrow_local=nrow_local, &
782 : ncol_local=ncol_local, &
783 : row_indices=row_indices, &
784 : col_indices=col_indices, &
785 634 : local_data=local_C_internal)
786 :
787 634 : CALL create_group_dist(gd_array, para_env_sub%num_pe, nrow_global)
788 634 : CALL get_group_dist(gd_array, para_env_sub%mepos, my_mu_start, my_mu_end, my_mu_size)
789 :
790 : ! local storage for the C matrix
791 2536 : ALLOCATE (C(my_mu_size, ncol_global))
792 265072 : C = 0.0_dp
793 :
794 2536 : ALLOCATE (local_C(nrow_local, ncol_local))
795 142837 : local_C(:, :) = local_C_internal(1:nrow_local, 1:ncol_local)
796 634 : NULLIFY (local_C_internal)
797 :
798 634 : max_row_col_local = MAX(nrow_local, ncol_local)
799 634 : CALL para_env%max(max_row_col_local)
800 :
801 2536 : ALLOCATE (local_col_row_info(0:max_row_col_local, 2))
802 26494 : local_col_row_info = 0
803 : ! 0,1 nrows
804 634 : local_col_row_info(0, 1) = nrow_local
805 6489 : local_col_row_info(1:nrow_local, 1) = row_indices(1:nrow_local)
806 : ! 0,2 ncols
807 634 : local_col_row_info(0, 2) = ncol_local
808 12296 : local_col_row_info(1:ncol_local, 2) = col_indices(1:ncol_local)
809 :
810 1268 : ALLOCATE (rec_col_row_info(0:max_row_col_local, 2))
811 :
812 : ! accumulate data on C buffer starting from myself
813 6489 : DO iiB = 1, nrow_local
814 5855 : i_global = row_indices(iiB)
815 6489 : IF (i_global >= my_mu_start .AND. i_global <= my_mu_end) THEN
816 136396 : DO jjB = 1, ncol_local
817 130541 : j_global = col_indices(jjB)
818 136396 : C(i_global - my_mu_start + 1, j_global) = local_C(iiB, jjB)
819 : END DO
820 : END IF
821 : END DO
822 :
823 : ! start ring communication for collecting the data from the other
824 634 : proc_send_static = MODULO(para_env%mepos + 1, para_env%num_pe)
825 634 : proc_receive_static = MODULO(para_env%mepos - 1, para_env%num_pe)
826 1268 : DO proc_shift = 1, para_env%num_pe - 1
827 : ! first exchange information on the local data
828 26494 : rec_col_row_info = 0
829 634 : CALL para_env%sendrecv(local_col_row_info, proc_send_static, rec_col_row_info, proc_receive_static)
830 634 : nrow_rec = rec_col_row_info(0, 1)
831 634 : ncol_rec = rec_col_row_info(0, 2)
832 :
833 1902 : ALLOCATE (row_indices_rec(nrow_rec))
834 6489 : row_indices_rec = rec_col_row_info(1:nrow_rec, 1)
835 :
836 1902 : ALLOCATE (col_indices_rec(ncol_rec))
837 12296 : col_indices_rec = rec_col_row_info(1:ncol_rec, 2)
838 :
839 2536 : ALLOCATE (rec_C(nrow_rec, ncol_rec))
840 142837 : rec_C = 0.0_dp
841 :
842 : ! then send and receive the real data
843 634 : CALL para_env%sendrecv(local_C, proc_send_static, rec_C, proc_receive_static)
844 :
845 : ! accumulate the received data on C buffer
846 6489 : DO iiB = 1, nrow_rec
847 5855 : i_global = row_indices_rec(iiB)
848 6489 : IF (i_global >= my_mu_start .AND. i_global <= my_mu_end) THEN
849 127704 : DO jjB = 1, ncol_rec
850 122235 : j_global = col_indices_rec(jjB)
851 127704 : C(i_global - my_mu_start + 1, j_global) = rec_C(iiB, jjB)
852 : END DO
853 : END IF
854 : END DO
855 :
856 26494 : local_col_row_info(:, :) = rec_col_row_info
857 634 : DEALLOCATE (local_C)
858 1902 : ALLOCATE (local_C(nrow_rec, ncol_rec))
859 142837 : local_C(:, :) = rec_C
860 :
861 634 : DEALLOCATE (col_indices_rec)
862 634 : DEALLOCATE (row_indices_rec)
863 1268 : DEALLOCATE (rec_C)
864 : END DO
865 :
866 634 : DEALLOCATE (local_C)
867 634 : DEALLOCATE (local_col_row_info)
868 634 : DEALLOCATE (rec_col_row_info)
869 :
870 634 : CALL timestop(handle)
871 :
872 2536 : END SUBROUTINE grep_rows_in_subgroups
873 :
874 : ! **************************************************************************************************
875 : !> \brief Encapsulate the building of dbcsr_matrices mo_coeff_(v,o,all)
876 : !> \param para_env_sub ...
877 : !> \param mo_coeff_to_build ...
878 : !> \param Cread ...
879 : !> \param mat_munu ...
880 : !> \param gd_array ...
881 : !> \param eps_filter ...
882 : !> \author Jan Wilhelm, Code by Mauro Del Ben
883 : ! **************************************************************************************************
884 1380 : SUBROUTINE build_dbcsr_from_rows(para_env_sub, mo_coeff_to_build, Cread, &
885 : mat_munu, gd_array, eps_filter)
886 : TYPE(mp_para_env_type), INTENT(IN) :: para_env_sub
887 : TYPE(dbcsr_type) :: mo_coeff_to_build
888 : REAL(KIND=dp), DIMENSION(:, :), INTENT(IN) :: Cread
889 : TYPE(dbcsr_type), INTENT(INOUT) :: mat_munu
890 : TYPE(group_dist_d1_type), INTENT(IN) :: gd_array
891 : REAL(KIND=dp), INTENT(IN) :: eps_filter
892 :
893 : CHARACTER(LEN=*), PARAMETER :: routineN = 'build_dbcsr_from_rows'
894 :
895 : INTEGER :: blk, col, col_offset, col_size, handle, i, i_global, j, j_global, my_mu_end, &
896 : my_mu_start, ncol_global, proc_receive, proc_send, proc_shift, rec_mu_end, rec_mu_size, &
897 : rec_mu_start, row, row_offset, row_size
898 1380 : REAL(KIND=dp), ALLOCATABLE, DIMENSION(:, :) :: rec_C
899 1380 : REAL(KIND=dp), DIMENSION(:, :), POINTER :: data_block
900 : TYPE(dbcsr_iterator_type) :: iter
901 :
902 1380 : CALL timeset(routineN, handle)
903 :
904 1380 : ncol_global = SIZE(Cread, 2)
905 :
906 1380 : CALL get_group_dist(gd_array, para_env_sub%mepos, my_mu_start, my_mu_end)
907 :
908 : CALL cp_dbcsr_m_by_n_from_row_template(mo_coeff_to_build, template=mat_munu, n=ncol_global, &
909 1380 : sym=dbcsr_type_no_symmetry, data_type=dbcsr_type_real_default)
910 1380 : CALL dbcsr_reserve_all_blocks(mo_coeff_to_build)
911 :
912 : ! accumulate data on mo_coeff_to_build starting from myself
913 1380 : CALL dbcsr_iterator_start(iter, mo_coeff_to_build)
914 5324 : DO WHILE (dbcsr_iterator_blocks_left(iter))
915 : CALL dbcsr_iterator_next_block(iter, row, col, data_block, blk, &
916 : row_size=row_size, col_size=col_size, &
917 3944 : row_offset=row_offset, col_offset=col_offset)
918 31312 : DO i = 1, row_size
919 25988 : i_global = row_offset + i - 1
920 29932 : IF (i_global >= my_mu_start .AND. i_global <= my_mu_end) THEN
921 327464 : DO j = 1, col_size
922 301652 : j_global = col_offset + j - 1
923 327464 : data_block(i, j) = Cread(i_global - my_mu_start + 1, col_offset + j - 1)
924 : END DO
925 : END IF
926 : END DO
927 : END DO
928 1380 : CALL dbcsr_iterator_stop(iter)
929 :
930 : ! start ring communication in the subgroup for collecting the data from the other
931 : ! proc (occupied)
932 1460 : DO proc_shift = 1, para_env_sub%num_pe - 1
933 80 : proc_send = MODULO(para_env_sub%mepos + proc_shift, para_env_sub%num_pe)
934 80 : proc_receive = MODULO(para_env_sub%mepos - proc_shift, para_env_sub%num_pe)
935 :
936 80 : CALL get_group_dist(gd_array, proc_receive, rec_mu_start, rec_mu_end, rec_mu_size)
937 :
938 320 : ALLOCATE (rec_C(rec_mu_size, ncol_global))
939 9110 : rec_C = 0.0_dp
940 :
941 : ! then send and receive the real data
942 9110 : CALL para_env_sub%sendrecv(Cread, proc_send, rec_C, proc_receive)
943 :
944 : ! accumulate data on mo_coeff_to_build the data received from proc_rec
945 80 : CALL dbcsr_iterator_start(iter, mo_coeff_to_build)
946 188 : DO WHILE (dbcsr_iterator_blocks_left(iter))
947 : CALL dbcsr_iterator_next_block(iter, row, col, data_block, blk, &
948 : row_size=row_size, col_size=col_size, &
949 108 : row_offset=row_offset, col_offset=col_offset)
950 912 : DO i = 1, row_size
951 724 : i_global = row_offset + i - 1
952 832 : IF (i_global >= rec_mu_start .AND. i_global <= rec_mu_end) THEN
953 1910 : DO j = 1, col_size
954 1734 : j_global = col_offset + j - 1
955 1910 : data_block(i, j) = rec_C(i_global - rec_mu_start + 1, col_offset + j - 1)
956 : END DO
957 : END IF
958 : END DO
959 : END DO
960 80 : CALL dbcsr_iterator_stop(iter)
961 :
962 1620 : DEALLOCATE (rec_C)
963 :
964 : END DO
965 1380 : CALL dbcsr_filter(mo_coeff_to_build, eps_filter)
966 :
967 1380 : CALL timestop(handle)
968 :
969 2760 : END SUBROUTINE build_dbcsr_from_rows
970 :
971 : ! **************************************************************************************************
972 : !> \brief Encapsulate the building of dbcsr_matrix mat_munu
973 : !> \param mat_munu ...
974 : !> \param qs_env ...
975 : !> \param eps_grid ...
976 : !> \param blacs_env_sub ...
977 : !> \param do_ri_aux_basis ...
978 : !> \param do_mixed_basis ...
979 : !> \param group_size_prim ...
980 : !> \param do_alloc_blocks_from_nbl ...
981 : !> \param do_kpoints ...
982 : !> \param sab_orb_sub ...
983 : !> \param dbcsr_sym_type ...
984 : !> \author Jan Wilhelm, code by Mauro Del Ben
985 : ! **************************************************************************************************
986 856 : SUBROUTINE create_mat_munu(mat_munu, qs_env, eps_grid, blacs_env_sub, &
987 : do_ri_aux_basis, do_mixed_basis, group_size_prim, &
988 : do_alloc_blocks_from_nbl, do_kpoints, sab_orb_sub, dbcsr_sym_type)
989 :
990 : TYPE(dbcsr_p_type), INTENT(OUT) :: mat_munu
991 : TYPE(qs_environment_type), POINTER :: qs_env
992 : REAL(KIND=dp) :: eps_grid
993 : TYPE(cp_blacs_env_type), POINTER :: blacs_env_sub
994 : LOGICAL, INTENT(IN), OPTIONAL :: do_ri_aux_basis, do_mixed_basis
995 : INTEGER, INTENT(IN), OPTIONAL :: group_size_prim
996 : LOGICAL, INTENT(IN), OPTIONAL :: do_alloc_blocks_from_nbl, do_kpoints
997 : TYPE(neighbor_list_set_p_type), DIMENSION(:), &
998 : OPTIONAL, POINTER :: sab_orb_sub
999 : CHARACTER, OPTIONAL :: dbcsr_sym_type
1000 :
1001 : CHARACTER(LEN=*), PARAMETER :: routineN = 'create_mat_munu'
1002 :
1003 : CHARACTER :: my_dbcsr_sym_type
1004 : INTEGER :: handle, ikind, natom, nkind
1005 856 : INTEGER, DIMENSION(:), POINTER :: col_blk_sizes, row_blk_sizes
1006 : LOGICAL :: my_do_alloc_blocks_from_nbl, &
1007 : my_do_kpoints, my_do_mixed_basis, &
1008 : my_do_ri_aux_basis
1009 856 : LOGICAL, ALLOCATABLE, DIMENSION(:) :: orb_present
1010 856 : REAL(dp), ALLOCATABLE, DIMENSION(:) :: orb_radius
1011 856 : REAL(dp), ALLOCATABLE, DIMENSION(:, :) :: pair_radius
1012 : REAL(KIND=dp) :: subcells
1013 856 : TYPE(atomic_kind_type), DIMENSION(:), POINTER :: atomic_kind_set
1014 : TYPE(cell_type), POINTER :: cell
1015 : TYPE(dbcsr_distribution_type), POINTER :: dbcsr_dist_sub
1016 : TYPE(dft_control_type), POINTER :: dft_control
1017 : TYPE(distribution_1d_type), POINTER :: local_molecules_sub, local_particles_sub
1018 : TYPE(distribution_2d_type), POINTER :: distribution_2d_sub
1019 856 : TYPE(gto_basis_set_p_type), DIMENSION(:), POINTER :: basis_set_ri_aux
1020 : TYPE(gto_basis_set_type), POINTER :: orb_basis_set
1021 856 : TYPE(local_atoms_type), ALLOCATABLE, DIMENSION(:) :: atom2d
1022 856 : TYPE(molecule_kind_type), DIMENSION(:), POINTER :: molecule_kind_set
1023 856 : TYPE(molecule_type), DIMENSION(:), POINTER :: molecule_set
1024 : TYPE(neighbor_list_set_p_type), DIMENSION(:), &
1025 856 : POINTER :: my_sab_orb_sub
1026 856 : TYPE(particle_type), DIMENSION(:), POINTER :: particle_set
1027 856 : TYPE(qs_kind_type), DIMENSION(:), POINTER :: qs_kind_set
1028 :
1029 856 : CALL timeset(routineN, handle)
1030 :
1031 856 : NULLIFY (basis_set_ri_aux)
1032 :
1033 856 : my_do_ri_aux_basis = .FALSE.
1034 856 : IF (PRESENT(do_ri_aux_basis)) THEN
1035 200 : my_do_ri_aux_basis = do_ri_aux_basis
1036 : END IF
1037 :
1038 856 : my_do_mixed_basis = .FALSE.
1039 856 : IF (PRESENT(do_mixed_basis)) THEN
1040 0 : my_do_mixed_basis = do_mixed_basis
1041 : END IF
1042 :
1043 856 : my_do_alloc_blocks_from_nbl = .FALSE.
1044 856 : IF (PRESENT(do_alloc_blocks_from_nbl)) THEN
1045 656 : my_do_alloc_blocks_from_nbl = do_alloc_blocks_from_nbl
1046 : END IF
1047 :
1048 856 : my_do_kpoints = .FALSE.
1049 856 : IF (PRESENT(do_kpoints)) THEN
1050 766 : my_do_kpoints = do_kpoints
1051 : END IF
1052 :
1053 856 : my_dbcsr_sym_type = dbcsr_type_no_symmetry
1054 856 : IF (PRESENT(dbcsr_sym_type)) THEN
1055 656 : my_dbcsr_sym_type = dbcsr_sym_type
1056 : END IF
1057 :
1058 : CALL get_qs_env(qs_env, &
1059 : qs_kind_set=qs_kind_set, &
1060 : cell=cell, &
1061 : particle_set=particle_set, &
1062 : atomic_kind_set=atomic_kind_set, &
1063 : molecule_set=molecule_set, &
1064 : molecule_kind_set=molecule_kind_set, &
1065 856 : dft_control=dft_control)
1066 :
1067 856 : IF (my_do_kpoints) THEN
1068 : ! please choose EPS_PGF_ORB in QS section smaller than EPS_GRID in WFC_GPW section
1069 8 : IF (eps_grid < dft_control%qs_control%eps_pgf_orb) THEN
1070 0 : eps_grid = dft_control%qs_control%eps_pgf_orb
1071 0 : CPWARN("WFC_GPW%EPS_GRID has been set to QS%EPS_PGF_ORB")
1072 : END IF
1073 : END IF
1074 :
1075 : ! hack hack hack XXXXXXXXXXXXXXX ... to be fixed
1076 856 : dft_control%qs_control%eps_pgf_orb = eps_grid
1077 856 : dft_control%qs_control%eps_rho_rspace = eps_grid
1078 856 : dft_control%qs_control%eps_gvg_rspace = eps_grid
1079 856 : CALL init_interaction_radii(dft_control%qs_control, qs_kind_set)
1080 :
1081 : ! get a distribution_1d
1082 856 : NULLIFY (local_particles_sub, local_molecules_sub)
1083 : CALL distribute_molecules_1d(atomic_kind_set=atomic_kind_set, &
1084 : particle_set=particle_set, &
1085 : local_particles=local_particles_sub, &
1086 : molecule_kind_set=molecule_kind_set, &
1087 : molecule_set=molecule_set, &
1088 : local_molecules=local_molecules_sub, &
1089 856 : force_env_section=qs_env%input)
1090 :
1091 : ! get a distribution_2d
1092 856 : NULLIFY (distribution_2d_sub)
1093 : CALL distribute_molecules_2d(cell=cell, &
1094 : atomic_kind_set=atomic_kind_set, &
1095 : qs_kind_set=qs_kind_set, &
1096 : particle_set=particle_set, &
1097 : molecule_kind_set=molecule_kind_set, &
1098 : molecule_set=molecule_set, &
1099 : distribution_2d=distribution_2d_sub, &
1100 : blacs_env=blacs_env_sub, &
1101 856 : force_env_section=qs_env%input)
1102 :
1103 : ! Build the sub orbital-orbital overlap neighbor lists
1104 856 : CALL section_vals_val_get(qs_env%input, "DFT%SUBCELLS", r_val=subcells)
1105 856 : nkind = SIZE(atomic_kind_set)
1106 4148 : ALLOCATE (atom2d(nkind))
1107 :
1108 : CALL atom2d_build(atom2d, local_particles_sub, distribution_2d_sub, atomic_kind_set, &
1109 856 : molecule_set, molecule_only=.FALSE., particle_set=particle_set)
1110 :
1111 2568 : ALLOCATE (orb_present(nkind))
1112 2568 : ALLOCATE (orb_radius(nkind))
1113 3424 : ALLOCATE (pair_radius(nkind, nkind))
1114 :
1115 2436 : DO ikind = 1, nkind
1116 1580 : CALL get_qs_kind(qs_kind_set(ikind), basis_set=orb_basis_set)
1117 2436 : IF (ASSOCIATED(orb_basis_set)) THEN
1118 1580 : orb_present(ikind) = .TRUE.
1119 1580 : CALL get_gto_basis_set(gto_basis_set=orb_basis_set, kind_radius=orb_radius(ikind))
1120 : ELSE
1121 0 : orb_present(ikind) = .FALSE.
1122 0 : orb_radius(ikind) = 0.0_dp
1123 : END IF
1124 : END DO
1125 :
1126 856 : CALL pair_radius_setup(orb_present, orb_present, orb_radius, orb_radius, pair_radius)
1127 :
1128 856 : IF (PRESENT(sab_orb_sub)) THEN
1129 656 : NULLIFY (sab_orb_sub)
1130 : ! for cubic RPA/GW with kpoints, we need all neighbors and not only the symmetric ones
1131 656 : IF (my_do_kpoints) THEN
1132 : CALL build_neighbor_lists(sab_orb_sub, particle_set, atom2d, cell, pair_radius, &
1133 : mic=.FALSE., subcells=subcells, molecular=.FALSE., nlname="sab_orb_sub", &
1134 4 : symmetric=.FALSE.)
1135 : ELSE
1136 : CALL build_neighbor_lists(sab_orb_sub, particle_set, atom2d, cell, pair_radius, &
1137 652 : mic=.FALSE., subcells=subcells, molecular=.FALSE., nlname="sab_orb_sub")
1138 : END IF
1139 : ELSE
1140 200 : NULLIFY (my_sab_orb_sub)
1141 : ! for cubic RPA/GW with kpoints, we need all neighbors and not only the symmetric ones
1142 200 : IF (my_do_kpoints) THEN
1143 : CALL build_neighbor_lists(my_sab_orb_sub, particle_set, atom2d, cell, pair_radius, &
1144 : mic=.FALSE., subcells=subcells, molecular=.FALSE., nlname="sab_orb_sub", &
1145 4 : symmetric=.FALSE.)
1146 : ELSE
1147 : CALL build_neighbor_lists(my_sab_orb_sub, particle_set, atom2d, cell, pair_radius, &
1148 196 : mic=.FALSE., subcells=subcells, molecular=.FALSE., nlname="sab_orb_sub")
1149 : END IF
1150 : END IF
1151 856 : CALL atom2d_cleanup(atom2d)
1152 856 : DEALLOCATE (atom2d)
1153 856 : DEALLOCATE (orb_present, orb_radius, pair_radius)
1154 :
1155 : ! a dbcsr_dist
1156 856 : ALLOCATE (dbcsr_dist_sub)
1157 856 : CALL cp_dbcsr_dist2d_to_dist(distribution_2d_sub, dbcsr_dist_sub)
1158 :
1159 : ! build a dbcsr matrix the hard way
1160 856 : natom = SIZE(particle_set)
1161 2568 : ALLOCATE (row_blk_sizes(natom))
1162 856 : IF (my_do_ri_aux_basis) THEN
1163 :
1164 708 : ALLOCATE (basis_set_ri_aux(nkind))
1165 178 : CALL basis_set_list_setup(basis_set_ri_aux, "RI_AUX", qs_kind_set)
1166 178 : CALL get_particle_set(particle_set, qs_kind_set, nsgf=row_blk_sizes, basis=basis_set_ri_aux)
1167 178 : DEALLOCATE (basis_set_ri_aux)
1168 :
1169 678 : ELSE IF (my_do_mixed_basis) THEN
1170 :
1171 0 : ALLOCATE (basis_set_ri_aux(nkind))
1172 0 : CALL basis_set_list_setup(basis_set_ri_aux, "RI_AUX", qs_kind_set)
1173 0 : CALL get_particle_set(particle_set, qs_kind_set, nsgf=row_blk_sizes, basis=basis_set_ri_aux)
1174 0 : DEALLOCATE (basis_set_ri_aux)
1175 :
1176 0 : ALLOCATE (col_blk_sizes(natom))
1177 :
1178 0 : CALL get_particle_set(particle_set, qs_kind_set, nsgf=col_blk_sizes)
1179 0 : col_blk_sizes = col_blk_sizes*group_size_prim
1180 :
1181 : ELSE
1182 678 : CALL get_particle_set(particle_set, qs_kind_set, nsgf=row_blk_sizes)
1183 : END IF
1184 :
1185 : NULLIFY (mat_munu%matrix)
1186 856 : ALLOCATE (mat_munu%matrix)
1187 :
1188 856 : IF (my_do_ri_aux_basis) THEN
1189 :
1190 : CALL dbcsr_create(matrix=mat_munu%matrix, &
1191 : name="(ai|munu)", &
1192 : dist=dbcsr_dist_sub, matrix_type=my_dbcsr_sym_type, &
1193 : row_blk_size=row_blk_sizes, col_blk_size=row_blk_sizes, &
1194 178 : nze=0)
1195 :
1196 678 : ELSE IF (my_do_mixed_basis) THEN
1197 :
1198 : CALL dbcsr_create(matrix=mat_munu%matrix, &
1199 : name="(ai|munu)", &
1200 : dist=dbcsr_dist_sub, matrix_type=my_dbcsr_sym_type, &
1201 : row_blk_size=row_blk_sizes, col_blk_size=col_blk_sizes, &
1202 0 : nze=0)
1203 :
1204 : ELSE
1205 :
1206 : CALL dbcsr_create(matrix=mat_munu%matrix, &
1207 : name="(ai|munu)", &
1208 : dist=dbcsr_dist_sub, matrix_type=my_dbcsr_sym_type, &
1209 : row_blk_size=row_blk_sizes, col_blk_size=row_blk_sizes, &
1210 678 : nze=0)
1211 :
1212 678 : IF (my_do_alloc_blocks_from_nbl) THEN
1213 :
1214 522 : IF (PRESENT(sab_orb_sub)) THEN
1215 522 : CALL cp_dbcsr_alloc_block_from_nbl(mat_munu%matrix, sab_orb_sub)
1216 : ELSE
1217 0 : CALL cp_dbcsr_alloc_block_from_nbl(mat_munu%matrix, my_sab_orb_sub)
1218 : END IF
1219 :
1220 : END IF
1221 :
1222 : END IF
1223 :
1224 856 : DEALLOCATE (row_blk_sizes)
1225 :
1226 856 : IF (my_do_mixed_basis) THEN
1227 0 : DEALLOCATE (col_blk_sizes)
1228 : END IF
1229 :
1230 856 : CALL dbcsr_distribution_release(dbcsr_dist_sub)
1231 856 : DEALLOCATE (dbcsr_dist_sub)
1232 :
1233 856 : CALL distribution_2d_release(distribution_2d_sub)
1234 :
1235 856 : CALL distribution_1d_release(local_particles_sub)
1236 856 : CALL distribution_1d_release(local_molecules_sub)
1237 :
1238 856 : IF (.NOT. PRESENT(sab_orb_sub)) THEN
1239 200 : CALL release_neighbor_list_sets(my_sab_orb_sub)
1240 : END IF
1241 :
1242 856 : CALL timestop(handle)
1243 :
1244 3424 : END SUBROUTINE create_mat_munu
1245 :
1246 : ! **************************************************************************************************
1247 : !> \brief ...
1248 : !> \param mat_P_global ...
1249 : !> \param qs_env ...
1250 : !> \param mp2_env ...
1251 : !> \param para_env ...
1252 : ! **************************************************************************************************
1253 134 : SUBROUTINE create_matrix_P(mat_P_global, qs_env, mp2_env, para_env)
1254 :
1255 : TYPE(dbcsr_p_type), INTENT(OUT) :: mat_P_global
1256 : TYPE(qs_environment_type), POINTER :: qs_env
1257 : TYPE(mp2_type) :: mp2_env
1258 : TYPE(mp_para_env_type), POINTER :: para_env
1259 :
1260 : CHARACTER(LEN=*), PARAMETER :: routineN = 'create_matrix_P'
1261 :
1262 : INTEGER :: blacs_grid_layout, handle
1263 : LOGICAL :: blacs_repeatable
1264 : TYPE(cp_blacs_env_type), POINTER :: blacs_env_global
1265 :
1266 134 : CALL timeset(routineN, handle)
1267 :
1268 134 : blacs_grid_layout = BLACS_GRID_SQUARE
1269 134 : blacs_repeatable = .TRUE.
1270 134 : NULLIFY (blacs_env_global)
1271 : CALL cp_blacs_env_create(blacs_env_global, para_env, &
1272 : blacs_grid_layout, &
1273 134 : blacs_repeatable)
1274 :
1275 : CALL create_mat_munu(mat_P_global, qs_env, mp2_env%mp2_gpw%eps_grid, &
1276 : blacs_env_global, do_ri_aux_basis=.TRUE., &
1277 134 : do_kpoints=mp2_env%ri_rpa_im_time%do_im_time_kpoints)
1278 :
1279 134 : CALL dbcsr_reserve_all_blocks(mat_P_global%matrix)
1280 134 : CALL cp_blacs_env_release(blacs_env_global)
1281 :
1282 134 : CALL timestop(handle)
1283 :
1284 134 : END SUBROUTINE
1285 :
1286 : ! **************************************************************************************************
1287 : !> \brief ...
1288 : !> \param dft_control ...
1289 : !> \param eps_pgf_orb_old ...
1290 : !> \param eps_rho_rspace_old ...
1291 : !> \param eps_gvg_rspace_old ...
1292 : ! **************************************************************************************************
1293 632 : PURE SUBROUTINE get_eps_old(dft_control, eps_pgf_orb_old, eps_rho_rspace_old, eps_gvg_rspace_old)
1294 :
1295 : TYPE(dft_control_type), INTENT(INOUT) :: dft_control
1296 : REAL(kind=dp), INTENT(OUT) :: eps_pgf_orb_old, eps_rho_rspace_old, &
1297 : eps_gvg_rspace_old
1298 :
1299 : ! re-init the radii to be able to generate pair lists with MP2-appropriate screening
1300 632 : eps_pgf_orb_old = dft_control%qs_control%eps_pgf_orb
1301 632 : eps_rho_rspace_old = dft_control%qs_control%eps_rho_rspace
1302 632 : eps_gvg_rspace_old = dft_control%qs_control%eps_gvg_rspace
1303 :
1304 632 : END SUBROUTINE get_eps_old
1305 :
1306 : END MODULE mp2_gpw
|