(git:27c966b)
Loading...
Searching...
No Matches
hfx_derivatives.F
Go to the documentation of this file.
1!--------------------------------------------------------------------------------------------------!
2! CP2K: A general program to perform molecular dynamics simulations !
3! Copyright 2000-2026 CP2K developers group <https://cp2k.org> !
4! !
5! SPDX-License-Identifier: GPL-2.0-or-later !
6!--------------------------------------------------------------------------------------------------!
7
8! **************************************************************************************************
9!> \brief Routines to calculate derivatives with respect to basis function origin
10!> \par History
11!> 04.2008 created [Manuel Guidon]
12!> \author Manuel Guidon
13! **************************************************************************************************
16 USE admm_types, ONLY: admm_type
19 USE cell_types, ONLY: cell_type, &
20 pbc
22 USE cp_files, ONLY: close_file, &
26 USE cp_output_handling, ONLY: cp_p_file, &
33 dbcsr_type_antisymmetric
49 USE hfx_types, ONLY: &
53 hfx_potential_type, hfx_screen_coeff_type, hfx_screening_type, hfx_task_list_type, &
59 USE kinds, ONLY: dp, &
60 int_8
61 USE machine, ONLY: m_walltime
62 USE mathconstants, ONLY: fac
63 USE orbital_pointers, ONLY: nco, &
64 ncoset, &
65 nso
70 USE util, ONLY: sort
71 USE virial_types, ONLY: virial_type
72
73!$ USE OMP_LIB, ONLY: omp_get_max_threads, omp_get_thread_num, omp_get_num_threads
74
75#include "./base/base_uses.f90"
76
77 IMPLICIT NONE
78 PRIVATE
79
81
82 CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'hfx_derivatives'
83
84!***
85
86CONTAINS
87
88! **************************************************************************************************
89!> \brief computes four center derivatives for a full basis set and updates the
90!> forces%fock_4c arrays. Uses all 8 eri symmetries
91!> \param qs_env ...
92!> \param rho_ao density matrix
93!> \param rho_ao_resp relaxed density matrix from response
94!> \param hfx_section HFX input section
95!> \param para_env para_env
96!> \param irep ID of HFX replica
97!> \param use_virial ...
98!> \param adiabatic_rescale_factor parameter used for MCY3 hybrid
99!> \param resp_only Calculate only forces from response density
100!> \par History
101!> 06.2007 created [Manuel Guidon]
102!> 08.2007 optimized load balance [Manuel Guidon]
103!> 02.2009 completely rewritten screening part [Manuel Guidon]
104!> 12.2017 major bug fix. removed wrong cycle that was causing segfault.
105!> see https://groups.google.com/forum/#!topic/cp2k/pc6B14XOALY
106!> [Tobias Binninger + Valery Weber]
107!> \author Manuel Guidon
108! **************************************************************************************************
109 SUBROUTINE derivatives_four_center(qs_env, rho_ao, rho_ao_resp, hfx_section, para_env, &
110 irep, use_virial, adiabatic_rescale_factor, resp_only, &
111 external_x_data, nspins)
112
113 TYPE(qs_environment_type), POINTER :: qs_env
114 TYPE(dbcsr_p_type), DIMENSION(:, :), POINTER :: rho_ao
115 TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: rho_ao_resp
116 TYPE(section_vals_type), POINTER :: hfx_section
117 TYPE(mp_para_env_type), POINTER :: para_env
118 INTEGER, INTENT(IN) :: irep
119 LOGICAL, INTENT(IN) :: use_virial
120 REAL(dp), INTENT(IN), OPTIONAL :: adiabatic_rescale_factor
121 LOGICAL, INTENT(IN), OPTIONAL :: resp_only
122 TYPE(hfx_type), DIMENSION(:, :), POINTER, OPTIONAL :: external_x_data
123 INTEGER, INTENT(IN), OPTIONAL :: nspins
124
125 CHARACTER(LEN=*), PARAMETER :: routinen = 'derivatives_four_center'
126
127 INTEGER :: atomic_offset_ac, atomic_offset_ad, atomic_offset_bc, atomic_offset_bd, bin, &
128 bits_max_val, buffer_left, buffer_size, buffer_start, cache_size, coord, current_counter, &
129 forces_map(4, 2), handle, handle_bin, handle_getp, handle_load, handle_main, i, i_atom, &
130 i_list_ij, i_list_kl, i_set_list_ij, i_set_list_ij_start, i_set_list_ij_stop, &
131 i_set_list_kl, i_set_list_kl_start, i_set_list_kl_stop, i_thread, iatom, iatom_block, &
132 iatom_end, iatom_start, ikind, iset, iw, j, j_atom, jatom, jatom_block, jatom_end, &
133 jatom_start, jkind, jset, k, k_atom, katom, katom_block, katom_end, katom_start
134 INTEGER :: kind_kind_idx, kkind, kset, l_atom, l_max, latom, latom_block, latom_end, &
135 latom_start, lkind, lset, max_am, max_pgf, max_set, my_bin_id, my_bin_size, my_thread_id, &
136 n_threads, natom, nbits, ncob, ncos_max, nints, nkimages, nkind, nneighbors, nseta, nsetb, &
137 nsgf_max, my_nspins, sgfb, shm_task_counter, shm_total_bins, sphi_a_u1, sphi_a_u2, &
138 sphi_a_u3, sphi_b_u1, sphi_b_u2, sphi_b_u3, sphi_c_u1, sphi_c_u2, sphi_c_u3, sphi_d_u1, &
139 sphi_d_u2, sphi_d_u3, swap_id, tmp_i4
140 INTEGER(int_8) :: atom_block, counter, estimate_to_store_int, max_val_memory, &
141 mem_compression_counter, mem_eris, mem_max_val, my_current_counter, my_istart, &
142 n_processes, nblocks, ncpu, neris_incore, neris_onthefly, neris_tmp, neris_total, &
143 nprim_ints, shm_neris_incore, shm_neris_onthefly, shm_neris_total, shm_nprim_ints, &
144 shm_stor_count_max_val, shm_storage_counter_integrals, stor_count_max_val, &
145 storage_counter_integrals, tmp_block, tmp_i8(6)
146 INTEGER(int_8), ALLOCATABLE, DIMENSION(:) :: tmp_task_list_cost
147 INTEGER, ALLOCATABLE, DIMENSION(:) :: atom_of_kind, kind_of, last_sgf_global, &
148 nimages, tmp_index
149 INTEGER, DIMENSION(:), POINTER :: la_max, la_min, lb_max, lb_min, lc_max, lc_min, ld_max, &
150 ld_min, npgfa, npgfb, npgfc, npgfd, nsgfa, nsgfb, nsgfc, nsgfd, shm_block_offset
151 INTEGER, DIMENSION(:, :), POINTER :: first_sgfb, nsgfl_a, nsgfl_b, nsgfl_c, nsgfl_d, &
152 offset_ac_set, offset_ad_set, offset_bc_set, offset_bd_set, shm_atomic_block_offset
153 INTEGER, DIMENSION(:, :), POINTER, SAVE :: shm_is_assoc_atomic_block
154 INTEGER, DIMENSION(:, :, :, :), POINTER :: shm_set_offset
155 INTEGER, SAVE :: shm_number_of_p_entries
156 LOGICAL :: bins_left, buffer_overflow, do_dynamic_load_balancing, do_it, do_periodic, &
157 do_print_load_balance_info, is_anti_symmetric, my_resp_only, screen_pmat_forces, &
158 treat_forces_in_core, use_disk_storage, with_resp_density
159 LOGICAL, DIMENSION(:, :), POINTER :: shm_atomic_pair_list
160 REAL(dp) :: bintime_start, bintime_stop, cartesian_estimate, cartesian_estimate_virial, &
161 compression_factor, eps_schwarz, eps_storage, fac, hf_fraction, ln_10, log10_eps_schwarz, &
162 log10_pmax, log_2, max_contraction_val, max_val1, max_val2, max_val2_set, &
163 my_adiabatic_rescale_factor, pmax_atom, pmax_blocks, pmax_entry, pmax_tmp, ra(3), rab2, &
164 rb(3), rc(3), rcd2, rd(3), spherical_estimate, spherical_estimate_virial, symm_fac, &
165 tmp_virial(3, 3)
166 REAL(dp), ALLOCATABLE, DIMENSION(:) :: ede_buffer1, ede_buffer2, ede_primitives_tmp, &
167 ede_primitives_tmp_virial, ede_work, ede_work2, ede_work2_virial, ede_work_forces, &
168 ede_work_virial, pac_buf, pac_buf_beta, pac_buf_resp, pac_buf_resp_beta, pad_buf, &
169 pad_buf_beta, pad_buf_resp, pad_buf_resp_beta, pbc_buf, pbc_buf_beta, pbc_buf_resp, &
170 pbc_buf_resp_beta, pbd_buf, pbd_buf_beta, pbd_buf_resp, pbd_buf_resp_beta
171 REAL(dp), ALLOCATABLE, DIMENSION(:), TARGET :: primitive_forces, primitive_forces_virial
172 REAL(dp), DIMENSION(:), POINTER :: full_density_resp, &
173 full_density_resp_beta, t2
174 REAL(dp), DIMENSION(:, :), POINTER :: full_density_alpha, full_density_beta, &
175 max_contraction, ptr_p_1, ptr_p_2, ptr_p_3, ptr_p_4, shm_pmax_atom, shm_pmax_block, &
176 sphi_b, zeta, zetb, zetc, zetd
177 REAL(dp), DIMENSION(:, :, :), POINTER :: sphi_a_ext_set, sphi_b_ext_set, &
178 sphi_c_ext_set, sphi_d_ext_set
179 REAL(dp), DIMENSION(:, :, :, :), POINTER :: sphi_a_ext, sphi_b_ext, sphi_c_ext, &
180 sphi_d_ext
181 REAL(kind=dp) :: coeffs_kind_max0
182 TYPE(admm_type), POINTER :: admm_env
183 TYPE(atomic_kind_type), DIMENSION(:), POINTER :: atomic_kind_set
184 TYPE(cell_type), POINTER :: cell
185 TYPE(cp_logger_type), POINTER :: logger
186 TYPE(dft_control_type), POINTER :: dft_control
187 TYPE(hfx_basis_info_type), POINTER :: basis_info
188 TYPE(hfx_basis_type), DIMENSION(:), POINTER :: basis_parameter
189 TYPE(hfx_cache_type), DIMENSION(:), POINTER :: integral_caches
190 TYPE(hfx_cache_type), POINTER :: maxval_cache
191 TYPE(hfx_container_type), DIMENSION(:), POINTER :: integral_containers
192 TYPE(hfx_container_type), POINTER :: maxval_container
193 TYPE(hfx_distribution), POINTER :: distribution_forces
194 TYPE(hfx_general_type) :: general_parameter
195 TYPE(hfx_load_balance_type), POINTER :: load_balance_parameter
196 TYPE(hfx_memory_type), POINTER :: memory_parameter
197 TYPE(hfx_p_kind), DIMENSION(:), POINTER :: shm_initial_p
198 TYPE(hfx_pgf_list), ALLOCATABLE, DIMENSION(:) :: pgf_list_ij, pgf_list_kl
199 TYPE(hfx_potential_type) :: potential_parameter
200 TYPE(hfx_screen_coeff_type), DIMENSION(:, :), &
201 POINTER :: screen_coeffs_kind, tmp_r_1, tmp_r_2, &
202 tmp_screen_pgf1, tmp_screen_pgf2
203 TYPE(hfx_screen_coeff_type), &
204 DIMENSION(:, :, :, :), POINTER :: screen_coeffs_set
205 TYPE(hfx_screen_coeff_type), &
206 DIMENSION(:, :, :, :, :, :), POINTER :: radii_pgf, screen_coeffs_pgf
207 TYPE(hfx_screening_type) :: screening_parameter
208 TYPE(hfx_task_list_type), DIMENSION(:), POINTER :: shm_task_list, tmp_task_list
209 TYPE(hfx_type), POINTER :: actual_x_data
210 TYPE(hfx_type), DIMENSION(:, :), POINTER :: my_x_data
211 TYPE(pair_list_type) :: list_ij, list_kl
212 TYPE(pair_set_list_type), ALLOCATABLE, &
213 DIMENSION(:) :: set_list_ij, set_list_kl
214 TYPE(particle_type), DIMENSION(:), POINTER :: particle_set
215 TYPE(qs_force_type), DIMENSION(:), POINTER :: force
216 TYPE(virial_type), POINTER :: virial
217
218 NULLIFY (dft_control, admm_env)
219
220 with_resp_density = .false.
221 IF (ASSOCIATED(rho_ao_resp)) with_resp_density = .true.
222
223 my_resp_only = .false.
224 IF (PRESENT(resp_only)) my_resp_only = resp_only
225
226 is_anti_symmetric = dbcsr_get_matrix_type(rho_ao(1, 1)%matrix) == dbcsr_type_antisymmetric
227
228 CALL get_qs_env(qs_env, &
229 admm_env=admm_env, &
230 particle_set=particle_set, &
231 atomic_kind_set=atomic_kind_set, &
232 cell=cell, &
233 dft_control=dft_control)
234
235 IF (PRESENT(nspins)) THEN
236 my_nspins = nspins
237 ELSE
238 my_nspins = dft_control%nspins
239 END IF
240 nkimages = dft_control%nimages
241 cpassert(nkimages == 1)
242
243 my_x_data => qs_env%x_data
244 IF (PRESENT(external_x_data)) my_x_data => external_x_data
245
246 !! One atom systems have no contribution to forces
247 IF (SIZE(particle_set, 1) == 1) THEN
248 IF (.NOT. use_virial) RETURN
249 END IF
250
251 CALL timeset(routinen, handle)
252 !! Calculate l_max used in fgamma , because init_md_ftable is definitely not thread safe
253 nkind = SIZE(atomic_kind_set, 1)
254 l_max = 0
255 DO ikind = 1, nkind
256 l_max = max(l_max, maxval(my_x_data(1, 1)%basis_parameter(ikind)%lmax))
257 END DO
258 l_max = 4*l_max + 1
259 CALL r12_fundamentals_init(l_max, my_x_data(1, 1)%potential_parameter, para_env)
260
261 n_threads = 1
262!$ n_threads = omp_get_max_threads()
263
264 shm_neris_total = 0
265 shm_nprim_ints = 0
266 shm_neris_onthefly = 0
267 shm_storage_counter_integrals = 0
268 shm_neris_incore = 0
269 shm_stor_count_max_val = 0
270
271 !! get force array
272 CALL get_qs_env(qs_env=qs_env, force=force, virial=virial)
273
274 my_adiabatic_rescale_factor = 1.0_dp
275 IF (PRESENT(adiabatic_rescale_factor)) THEN
276 my_adiabatic_rescale_factor = adiabatic_rescale_factor
277 END IF
278
279 !$OMP PARALLEL DEFAULT(NONE) &
280!$OMP SHARED(qs_env,&
281!$OMP rho_ao,&
282!$OMP rho_ao_resp,&
283!$OMP with_resp_density,&
284!$OMP hfx_section,&
285!$OMP para_env,&
286!$OMP irep,&
287!$OMP my_resp_only,&
288!$OMP ncoset,&
289!$OMP nco,&
290!$OMP nso,&
291!$OMP n_threads,&
292!$OMP full_density_alpha,&
293!$OMP full_density_resp,&
294!$OMP full_density_resp_beta,&
295!$OMP full_density_beta,&
296!$OMP shm_initial_p,&
297!$OMP shm_is_assoc_atomic_block,&
298!$OMP shm_number_of_p_entries,&
299!$OMP force,&
300!$OMP virial,&
301!$OMP my_adiabatic_rescale_factor,&
302!$OMP shm_neris_total,&
303!$OMP shm_neris_onthefly,&
304!$OMP shm_storage_counter_integrals,&
305!$OMP shm_neris_incore,&
306!$OMP shm_nprim_ints,&
307!$OMP shm_stor_count_max_val,&
308!$OMP cell,&
309!$OMP screen_coeffs_set,&
310!$OMP screen_coeffs_kind,&
311!$OMP screen_coeffs_pgf,&
312!$OMP nkind,&
313!$OMP is_anti_symmetric,&
314!$OMP radii_pgf,&
315!$OMP shm_atomic_block_offset,&
316!$OMP shm_set_offset,&
317!$OMP shm_block_offset,&
318!$OMP shm_task_counter,&
319!$OMP shm_task_list,&
320!$OMP shm_total_bins,&
321!$OMP shm_pmax_block,&
322!$OMP shm_atomic_pair_list,&
323!$OMP shm_pmax_atom,&
324!$OMP use_virial,&
325!$OMP do_print_load_balance_info,&
326!$OMP nkimages,my_nspins,my_x_data)&
327!$OMP PRIVATE(actual_x_data,atomic_kind_set,atomic_offset_ac,atomic_offset_ad,atomic_offset_bc,&
328!$OMP atomic_offset_bd,atom_of_kind,basis_info,&
329!$OMP basis_parameter,bin,bins_left,bintime_start,bintime_stop,bits_max_val,buffer_left,buffer_overflow,buffer_size,&
330!$OMP buffer_start,cache_size,cartesian_estimate,cartesian_estimate_virial,&
331!$OMP coeffs_kind_max0,compression_factor,counter,current_counter,&
332!$OMP distribution_forces,do_dynamic_load_balancing,do_it,do_periodic,ede_buffer1,ede_buffer2,&
333!$OMP ede_primitives_tmp,ede_primitives_tmp_virial,&
334!$OMP ede_work,ede_work2,ede_work2_virial,ede_work_forces,ede_work_virial,eps_schwarz,eps_storage,estimate_to_store_int,&
335!$OMP fac,first_sgfb,forces_map,general_parameter,handle_bin,handle_getp,handle_load,&
336!$OMP handle_main,hf_fraction,i_atom,iatom_end,iatom_start,ikind,integral_caches,integral_containers,&
337!$OMP i_set_list_ij_start,i_set_list_ij_stop,i_set_list_kl_start,i_set_list_kl_stop,i_thread,iw,j_atom,jatom_end,&
338!$OMP jatom_start,jkind,katom,k_atom,katom_block,katom_end,katom_start,kind_kind_idx,&
339!$OMP kind_of,kkind,kset,la_max,la_min,last_sgf_global,latom,l_atom,&
340!$OMP latom_block,latom_end,latom_start,lb_max,lb_min,lc_max,lc_min,ld_max,&
341!$OMP ld_min,list_ij,list_kl,lkind,ln_10,load_balance_parameter,log10_eps_schwarz,log10_pmax,&
342!$OMP log_2,logger,lset,max_am,max_contraction,max_contraction_val,max_pgf,max_set,&
343!$OMP max_val1,max_val2,max_val2_set,maxval_cache,maxval_container,max_val_memory,mem_compression_counter,mem_eris,&
344!$OMP mem_max_val,memory_parameter,my_bin_id,my_bin_size,my_current_counter,my_istart,my_thread_id,natom,&
345!$OMP nbits,nblocks,ncob,ncos_max,ncpu,neris_incore,neris_onthefly,neris_tmp,&
346!$OMP neris_total,nimages,nints,nneighbors,npgfa,npgfb,npgfc,npgfd,&
347!$OMP nprim_ints,n_processes,nseta,nsetb,nsgfa,nsgfb,nsgfc,nsgfd,&
348!$OMP nsgfl_a,nsgfl_b,nsgfl_c,nsgfl_d,nsgf_max,offset_ac_set,offset_ad_set,&
349!$OMP offset_bc_set,offset_bd_set,pac_buf,pac_buf_beta,pac_buf_resp,pac_buf_resp_beta,pad_buf,pad_buf_beta,pad_buf_resp,&
350!$OMP pad_buf_resp_beta,particle_set,pbc_buf,pbc_buf_beta,pbc_buf_resp,pbc_buf_resp_beta,pbd_buf,pbd_buf_beta, &
351!$OMP pbd_buf_resp, pbd_buf_resp_beta, pgf_list_ij,&
352!$OMP pgf_list_kl,pmax_atom,pmax_blocks,pmax_entry,pmax_tmp,potential_parameter,primitive_forces,&
353!$OMP primitive_forces_virial,ptr_p_1,ptr_p_2,ptr_p_3,ptr_p_4,ra,rab2,&
354!$OMP rb,rc,rcd2,rd,screening_parameter,screen_pmat_forces,set_list_ij,set_list_kl,&
355!$OMP sgfb,spherical_estimate,spherical_estimate_virial,sphi_a_ext,sphi_a_ext_set,sphi_a_u1,sphi_a_u2,sphi_a_u3,&
356!$OMP sphi_b,sphi_b_ext,sphi_b_ext_set,sphi_b_u1,sphi_b_u2,sphi_b_u3,sphi_c_ext,sphi_c_ext_set,&
357!$OMP sphi_c_u1,sphi_c_u2,sphi_c_u3,sphi_d_ext,sphi_d_ext_set,sphi_d_u1,sphi_d_u2,sphi_d_u3,&
358!$OMP storage_counter_integrals,stor_count_max_val,swap_id,symm_fac,t2,tmp_block,tmp_i8, tmp_i4,&
359!$OMP tmp_index,tmp_r_1,tmp_r_2,tmp_screen_pgf1,tmp_screen_pgf2,tmp_task_list,tmp_task_list_cost,tmp_virial,&
360!$OMP treat_forces_in_core,use_disk_storage,zeta,zetb,zetc,zetd)
361
362 i_thread = 0
363!$ i_thread = omp_get_thread_num()
364
365 ln_10 = log(10.0_dp)
366 log_2 = log10(2.0_dp)
367 actual_x_data => my_x_data(irep, i_thread + 1)
368 do_periodic = actual_x_data%periodic_parameter%do_periodic
369
370 screening_parameter = actual_x_data%screening_parameter
371 general_parameter = actual_x_data%general_parameter
372 potential_parameter = actual_x_data%potential_parameter
373 basis_info => actual_x_data%basis_info
374
375 load_balance_parameter => actual_x_data%load_balance_parameter
376 basis_parameter => actual_x_data%basis_parameter
377
378 ! IF(with_resp_density) THEN
379 ! ! here we also do a copy of the original load_balance_parameter
380 ! ! since if MP2 forces are required after the calculation of the HFX
381 ! ! derivatives we need to calculate again the SCF energy.
382 ! ALLOCATE(load_balance_parameter_energy)
383 ! load_balance_parameter_energy = actual_x_data%load_balance_parameter
384 ! END IF
385
386 memory_parameter => actual_x_data%memory_parameter
387
388 cache_size = memory_parameter%cache_size
389 bits_max_val = memory_parameter%bits_max_val
390
391 use_disk_storage = .false.
392
393 CALL get_qs_env(qs_env=qs_env, &
394 atomic_kind_set=atomic_kind_set, &
395 particle_set=particle_set)
396
397 max_set = basis_info%max_set
398 max_am = basis_info%max_am
399 natom = SIZE(particle_set, 1)
400
401 treat_forces_in_core = memory_parameter%treat_forces_in_core
402
403 hf_fraction = general_parameter%fraction
404 hf_fraction = hf_fraction*my_adiabatic_rescale_factor
405 eps_schwarz = screening_parameter%eps_schwarz_forces
406 IF (eps_schwarz < 0.0_dp) THEN
407 log10_eps_schwarz = log_zero
408 ELSE
409 !! ** make eps_schwarz tighter in case of a stress calculation
410 IF (use_virial) eps_schwarz = eps_schwarz/actual_x_data%periodic_parameter%R_max_stress
411 log10_eps_schwarz = log10(eps_schwarz)
412 END IF
413 screen_pmat_forces = screening_parameter%do_p_screening_forces
414 ! don't do density screening in case of response forces
415 IF (with_resp_density) screen_pmat_forces = .false.
416
417 eps_storage = eps_schwarz*memory_parameter%eps_storage_scaling
418
419 counter = 0_int_8
420
421 !! Get screening parameter
422
423 CALL get_atomic_kind_set(atomic_kind_set=atomic_kind_set, &
424 atom_of_kind=atom_of_kind, &
425 kind_of=kind_of)
426
427 !! Create helper arrray for mapping local basis functions to global ones
428 ALLOCATE (last_sgf_global(0:natom))
429 last_sgf_global(0) = 0
430 DO iatom = 1, natom
431 ikind = kind_of(iatom)
432 last_sgf_global(iatom) = last_sgf_global(iatom - 1) + basis_parameter(ikind)%nsgf_total
433 END DO
434
435 ALLOCATE (max_contraction(max_set, natom))
436
437 max_contraction = 0.0_dp
438 max_pgf = 0
439 DO jatom = 1, natom
440 jkind = kind_of(jatom)
441 lb_max => basis_parameter(jkind)%lmax
442 npgfb => basis_parameter(jkind)%npgf
443 nsetb = basis_parameter(jkind)%nset
444 first_sgfb => basis_parameter(jkind)%first_sgf
445 sphi_b => basis_parameter(jkind)%sphi
446 nsgfb => basis_parameter(jkind)%nsgf
447 DO jset = 1, nsetb
448 ! takes the primitive to contracted transformation into account
449 ncob = npgfb(jset)*ncoset(lb_max(jset))
450 sgfb = first_sgfb(1, jset)
451 ! if the primitives are assumed to be all of max_val2, max_val2*p2s_b becomes
452 ! the maximum value after multiplication with sphi_b
453 max_contraction(jset, jatom) = maxval([(sum(abs(sphi_b(1:ncob, i))), i=sgfb, sgfb + nsgfb(jset) - 1)])
454 max_pgf = max(max_pgf, npgfb(jset))
455 END DO
456 END DO
457
458 ncpu = para_env%num_pe
459 n_processes = ncpu*n_threads
460
461 !! initialize some counters
462 neris_total = 0_int_8
463 neris_incore = 0_int_8
464 neris_onthefly = 0_int_8
465 mem_eris = 0_int_8
466 mem_max_val = 0_int_8
467 compression_factor = 0.0_dp
468 nprim_ints = 0_int_8
469 neris_tmp = 0_int_8
470 max_val_memory = 1_int_8
471
472!$OMP MASTER
473 !! Set pointer for is_assoc helper
474 shm_is_assoc_atomic_block => actual_x_data%is_assoc_atomic_block
475 shm_number_of_p_entries = actual_x_data%number_of_p_entries
476 shm_atomic_block_offset => actual_x_data%atomic_block_offset
477 shm_set_offset => actual_x_data%set_offset
478 shm_block_offset => actual_x_data%block_offset
479
480 NULLIFY (full_density_alpha)
481 NULLIFY (full_density_beta)
482 ALLOCATE (full_density_alpha(shm_block_offset(ncpu + 1), nkimages))
483
484 !! Get the full density from all the processors
485 CALL timeset(routinen//"_getP", handle_getp)
486 CALL get_full_density(para_env, full_density_alpha(:, 1), rho_ao(1, 1)%matrix, shm_number_of_p_entries, &
487 shm_block_offset, &
488 kind_of, basis_parameter, get_max_vals_spin=.false., &
489 antisymmetric=is_anti_symmetric)
490 ! for now only closed shell case
491 IF (with_resp_density) THEN
492 NULLIFY (full_density_resp)
493 ALLOCATE (full_density_resp(shm_block_offset(ncpu + 1)))
494 CALL get_full_density(para_env, full_density_resp, rho_ao_resp(1)%matrix, shm_number_of_p_entries, &
495 shm_block_offset, &
496 kind_of, basis_parameter, get_max_vals_spin=.false., &
497 antisymmetric=is_anti_symmetric)
498 END IF
499
500 IF (my_nspins == 2) THEN
501 ALLOCATE (full_density_beta(shm_block_offset(ncpu + 1), 1))
502 CALL get_full_density(para_env, full_density_beta(:, 1), rho_ao(2, 1)%matrix, shm_number_of_p_entries, &
503 shm_block_offset, &
504 kind_of, basis_parameter, get_max_vals_spin=.false., &
505 antisymmetric=is_anti_symmetric)
506 ! With resp density
507 IF (with_resp_density) THEN
508 NULLIFY (full_density_resp_beta)
509 ALLOCATE (full_density_resp_beta(shm_block_offset(ncpu + 1)))
510 CALL get_full_density(para_env, full_density_resp_beta, rho_ao_resp(2)%matrix, shm_number_of_p_entries, &
511 shm_block_offset, &
512 kind_of, basis_parameter, get_max_vals_spin=.false., &
513 antisymmetric=is_anti_symmetric)
514 END IF
515
516 END IF
517 CALL timestop(handle_getp)
518
519 !! Calculate max entries for screening on actual density. If screen_p_mat_forces = FALSE, the
520 !! matrix is initialized to 1.0
521 IF (screen_pmat_forces) THEN
522 NULLIFY (shm_initial_p)
523 shm_initial_p => actual_x_data%initial_p_forces
524 shm_pmax_atom => actual_x_data%pmax_atom_forces
525 IF (memory_parameter%recalc_forces) THEN
526 CALL update_pmax_mat(shm_initial_p, &
527 actual_x_data%map_atom_to_kind_atom, &
528 actual_x_data%set_offset, &
529 actual_x_data%atomic_block_offset, &
530 shm_pmax_atom, &
531 full_density_alpha, full_density_beta, &
532 natom, kind_of, basis_parameter, &
533 nkind, actual_x_data%is_assoc_atomic_block, my_nspins)
534 END IF
535 END IF
536
537 ! restore as full density the HF density
538 ! maybe in the future
539 IF (with_resp_density .AND. .NOT. my_resp_only) THEN
540 full_density_alpha(:, 1) = full_density_alpha(:, 1) - full_density_resp
541 IF (my_nspins == 2) THEN
542 full_density_beta(:, 1) = &
543 full_density_beta(:, 1) - full_density_resp_beta
544 END IF
545 ! full_density_resp=full_density+full_density_resp
546 END IF
547
548 screen_coeffs_set => actual_x_data%screen_funct_coeffs_set
549 screen_coeffs_kind => actual_x_data%screen_funct_coeffs_kind
550 screen_coeffs_pgf => actual_x_data%screen_funct_coeffs_pgf
551 radii_pgf => actual_x_data%pair_dist_radii_pgf
552 shm_pmax_block => actual_x_data%pmax_block
553
554!$OMP END MASTER
555!$OMP BARRIER
556
557!$OMP MASTER
558 CALL timeset(routinen//"_load", handle_load)
559!$OMP END MASTER
560 !! Load balance the work
561 IF (actual_x_data%memory_parameter%recalc_forces) THEN
562 IF (actual_x_data%b_first_load_balance_forces) THEN
563 CALL hfx_load_balance(actual_x_data, eps_schwarz, particle_set, max_set, para_env, &
564 screen_coeffs_set, screen_coeffs_kind, &
565 shm_is_assoc_atomic_block, do_periodic, &
566 load_balance_parameter, kind_of, basis_parameter, shm_initial_p, &
567 shm_pmax_atom, i_thread, n_threads, &
568 cell, screen_pmat_forces, actual_x_data%map_atom_to_kind_atom, &
569 nkind, hfx_do_eval_forces, shm_pmax_block, use_virial)
570 actual_x_data%b_first_load_balance_forces = .false.
571 ELSE
572 CALL hfx_update_load_balance(actual_x_data, para_env, &
573 load_balance_parameter, &
574 i_thread, n_threads, hfx_do_eval_forces)
575 END IF
576 END IF
577!$OMP MASTER
578 CALL timestop(handle_load)
579!$OMP END MASTER
580
581 !! precompute maximum nco and allocate scratch
582 ncos_max = 0
583 nsgf_max = 0
584 DO iatom = 1, natom
585 ikind = kind_of(iatom)
586 nseta = basis_parameter(ikind)%nset
587 npgfa => basis_parameter(ikind)%npgf
588 la_max => basis_parameter(ikind)%lmax
589 nsgfa => basis_parameter(ikind)%nsgf
590 DO iset = 1, nseta
591 ncos_max = max(ncos_max, ncoset(la_max(iset)))
592 nsgf_max = max(nsgf_max, nsgfa(iset))
593 END DO
594 END DO
595
596 !! Allocate work arrays
597 ALLOCATE (primitive_forces(12*nsgf_max**4))
598 primitive_forces = 0.0_dp
599
600 ! ** Allocate buffers for pgf_lists
601 nneighbors = SIZE(actual_x_data%neighbor_cells)
602 ALLOCATE (pgf_list_ij(max_pgf**2))
603 ALLOCATE (pgf_list_kl(max_pgf**2))
604 ALLOCATE (nimages(max_pgf**2))
605
606 DO i = 1, max_pgf**2
607 ALLOCATE (pgf_list_ij(i)%image_list(nneighbors))
608 ALLOCATE (pgf_list_kl(i)%image_list(nneighbors))
609 END DO
610
611 ALLOCATE (pbd_buf(nsgf_max**2))
612 ALLOCATE (pbc_buf(nsgf_max**2))
613 ALLOCATE (pad_buf(nsgf_max**2))
614 ALLOCATE (pac_buf(nsgf_max**2))
615 IF (with_resp_density) THEN
616 ALLOCATE (pbd_buf_resp(nsgf_max**2))
617 ALLOCATE (pbc_buf_resp(nsgf_max**2))
618 ALLOCATE (pad_buf_resp(nsgf_max**2))
619 ALLOCATE (pac_buf_resp(nsgf_max**2))
620 END IF
621 IF (my_nspins == 2) THEN
622 ALLOCATE (pbd_buf_beta(nsgf_max**2))
623 ALLOCATE (pbc_buf_beta(nsgf_max**2))
624 ALLOCATE (pad_buf_beta(nsgf_max**2))
625 ALLOCATE (pac_buf_beta(nsgf_max**2))
626 IF (with_resp_density) THEN
627 ALLOCATE (pbd_buf_resp_beta(nsgf_max**2))
628 ALLOCATE (pbc_buf_resp_beta(nsgf_max**2))
629 ALLOCATE (pad_buf_resp_beta(nsgf_max**2))
630 ALLOCATE (pac_buf_resp_beta(nsgf_max**2))
631 END IF
632 END IF
633
634 ALLOCATE (ede_work(ncos_max**4*12))
635 ALLOCATE (ede_work2(ncos_max**4*12))
636 ALLOCATE (ede_work_forces(ncos_max**4*12))
637 ALLOCATE (ede_buffer1(ncos_max**4))
638 ALLOCATE (ede_buffer2(ncos_max**4))
639 ALLOCATE (ede_primitives_tmp(nsgf_max**4))
640
641 IF (use_virial) THEN
642 ALLOCATE (primitive_forces_virial(12*nsgf_max**4*3))
643 primitive_forces_virial = 0.0_dp
644 ALLOCATE (ede_work_virial(ncos_max**4*12*3))
645 ALLOCATE (ede_work2_virial(ncos_max**4*12*3))
646 ALLOCATE (ede_primitives_tmp_virial(nsgf_max**4))
647 tmp_virial = 0.0_dp
648 ELSE
649 ! dummy allocation
650 ALLOCATE (primitive_forces_virial(1))
651 primitive_forces_virial = 0.0_dp
652 ALLOCATE (ede_work_virial(1))
653 ALLOCATE (ede_work2_virial(1))
654 ALLOCATE (ede_primitives_tmp_virial(1))
655 END IF
656
657 !! Start caluclating integrals of the form (ab|cd) or (ij|kl)
658 !! In order to do so, there is a main four-loop structure that takes into account the two symmetries
659 !!
660 !! (ab|cd) = (ba|cd) = (ab|dc) = (ba|dc)
661 !!
662 !! by iterating in the following way
663 !!
664 !! DO iatom=1,natom and DO katom=1,natom
665 !! DO jatom=iatom,natom DO latom=katom,natom
666 !!
667 !! The third symmetry
668 !!
669 !! (ab|cd) = (cd|ab)
670 !!
671 !! is taken into account by the following criterion:
672 !!
673 !! IF(katom+latom<=iatom+jatom) THEN
674 !! IF( ((iatom+jatom)==(katom+latom) ) .AND.(katom<iatom)) CYCLE
675 !!
676 !! Furthermore, if iatom==jatom==katom==latom we cycle, because the derivatives are zero anyway.
677 !!
678 !! Depending on the degeneracy of an integral the exchange contribution is multiplied by a corresponding
679 !! factor ( symm_fac ).
680 !!
681 !! If one quartet does not pass the screening we CYCLE on the outer most possible loop. Thats why we use
682 !! different hierarchies of short range screening matrices.
683 !!
684 !! If we do a parallel run, each process owns a unique array of workloads. Here, a workload is
685 !! defined as :
686 !!
687 !! istart, jstart, kstart, lstart, number_of_atom_quartets, initial_cpu_id
688 !!
689 !! This tells the process where to start the main loops and how many bunches of integrals it has to
690 !! calculate. The original parallelization is a simple modulo distribution that is binned and
691 !! optimized in the load_balance routines. Since the Monte Carlo routines can swap processors,
692 !! we need to know which was the initial cpu_id.
693 !! Furthermore, the indices iatom, jatom, katom, latom have to be set to istart, jstart, kstart and
694 !! lstart only the first time the loop is executed. All subsequent loops have to start with one or
695 !! iatom and katom respectively. Therefore, we use flags like first_j_loop etc.
696
697!$OMP BARRIER
698!$OMP MASTER
699 CALL timeset(routinen//"_main", handle_main)
700!$OMP END MASTER
701!$OMP BARRIER
702
703 coeffs_kind_max0 = maxval(screen_coeffs_kind(:, :)%x(2))
704 ALLOCATE (set_list_ij((max_set*load_balance_parameter%block_size)**2))
705 ALLOCATE (set_list_kl((max_set*load_balance_parameter%block_size)**2))
706
707!$OMP BARRIER
708
709 IF (actual_x_data%memory_parameter%recalc_forces) THEN
710 actual_x_data%distribution_forces%ram_counter = huge(distribution_forces%ram_counter)
711 memory_parameter%ram_counter_forces = huge(memory_parameter%ram_counter_forces)
712 END IF
713
714 IF (treat_forces_in_core) THEN
715 buffer_overflow = .false.
716 ELSE
717 buffer_overflow = .true.
718 END IF
719
720 do_dynamic_load_balancing = .true.
721 IF (n_threads == 1) do_dynamic_load_balancing = .false.
722
723 IF (do_dynamic_load_balancing) THEN
724 my_bin_size = SIZE(actual_x_data%distribution_forces)
725 ELSE
726 my_bin_size = 1
727 END IF
728 !! We do not need the containers if MAX_MEM = 0
729 IF (treat_forces_in_core) THEN
730 !! IF new md step -> reinitialize containers
731 IF (actual_x_data%memory_parameter%recalc_forces) THEN
732 CALL dealloc_containers(actual_x_data%store_forces, memory_parameter%actual_memory_usage)
733 CALL alloc_containers(actual_x_data%store_forces, my_bin_size)
734
735 DO bin = 1, my_bin_size
736 maxval_container => actual_x_data%store_forces%maxval_container(bin)
737 integral_containers => actual_x_data%store_forces%integral_containers(:, bin)
738 CALL hfx_init_container(maxval_container, memory_parameter%actual_memory_usage, .false.)
739 DO i = 1, 64
740 CALL hfx_init_container(integral_containers(i), memory_parameter%actual_memory_usage, .false.)
741 END DO
742 END DO
743 END IF
744
745 !! Decompress the first cache for maxvals and integrals
746 IF (.NOT. actual_x_data%memory_parameter%recalc_forces) THEN
747 DO bin = 1, my_bin_size
748 maxval_cache => actual_x_data%store_forces%maxval_cache(bin)
749 maxval_container => actual_x_data%store_forces%maxval_container(bin)
750 integral_caches => actual_x_data%store_forces%integral_caches(:, bin)
751 integral_containers => actual_x_data%store_forces%integral_containers(:, bin)
752 CALL hfx_decompress_first_cache(bits_max_val, maxval_cache, maxval_container, &
753 memory_parameter%actual_memory_usage, .false.)
754 DO i = 1, 64
755 CALL hfx_decompress_first_cache(i, integral_caches(i), integral_containers(i), &
756 memory_parameter%actual_memory_usage, .false.)
757 END DO
758 END DO
759 END IF
760 END IF
761
762!$OMP BARRIER
763!$OMP MASTER
764 IF (do_dynamic_load_balancing) THEN
765 ! ** Lets construct the task list
766 shm_total_bins = 0
767 DO i = 1, n_threads
768 shm_total_bins = shm_total_bins + SIZE(my_x_data(irep, i)%distribution_forces)
769 END DO
770 ALLOCATE (tmp_task_list(shm_total_bins))
771 shm_task_counter = 0
772 DO i = 1, n_threads
773 DO bin = 1, SIZE(my_x_data(irep, i)%distribution_forces)
774 shm_task_counter = shm_task_counter + 1
775 tmp_task_list(shm_task_counter)%thread_id = i
776 tmp_task_list(shm_task_counter)%bin_id = bin
777 tmp_task_list(shm_task_counter)%cost = my_x_data(irep, i)%distribution_forces(bin)%cost
778 END DO
779 END DO
780
781 ! ** Now sort the task list
782 ALLOCATE (tmp_task_list_cost(shm_total_bins))
783 ALLOCATE (tmp_index(shm_total_bins))
784
785 DO i = 1, shm_total_bins
786 tmp_task_list_cost(i) = tmp_task_list(i)%cost
787 END DO
788
789 CALL sort(tmp_task_list_cost, shm_total_bins, tmp_index)
790
791 ALLOCATE (actual_x_data%task_list(shm_total_bins))
792
793 DO i = 1, shm_total_bins
794 actual_x_data%task_list(i) = tmp_task_list(tmp_index(shm_total_bins - i + 1))
795 END DO
796
797 shm_task_list => actual_x_data%task_list
798 shm_task_counter = 0
799
800 DEALLOCATE (tmp_task_list_cost, tmp_index, tmp_task_list)
801 END IF
802
803 !! precalculate maximum density matrix elements in blocks
804 shm_pmax_block => actual_x_data%pmax_block
805 actual_x_data%pmax_block = 0.0_dp
806 IF (screen_pmat_forces) THEN
807 DO iatom_block = 1, SIZE(actual_x_data%blocks)
808 iatom_start = actual_x_data%blocks(iatom_block)%istart
809 iatom_end = actual_x_data%blocks(iatom_block)%iend
810 DO jatom_block = 1, SIZE(actual_x_data%blocks)
811 jatom_start = actual_x_data%blocks(jatom_block)%istart
812 jatom_end = actual_x_data%blocks(jatom_block)%iend
813 shm_pmax_block(iatom_block, jatom_block) = maxval(shm_pmax_atom(iatom_start:iatom_end, jatom_start:jatom_end))
814 END DO
815 END DO
816 END IF
817 shm_atomic_pair_list => actual_x_data%atomic_pair_list_forces
818 IF (actual_x_data%memory_parameter%recalc_forces) THEN
819 CALL build_atomic_pair_list(natom, shm_atomic_pair_list, kind_of, basis_parameter, particle_set, &
820 do_periodic, screen_coeffs_kind, coeffs_kind_max0, log10_eps_schwarz, cell, &
821 actual_x_data%blocks)
822 END IF
823
824 my_bin_size = SIZE(actual_x_data%distribution_forces)
825 DO bin = 1, my_bin_size
826 actual_x_data%distribution_forces(bin)%time_forces = 0.0_dp
827 END DO
828!$OMP END MASTER
829!$OMP BARRIER
830
831 IF (treat_forces_in_core) THEN
832 IF (my_bin_size > 0) THEN
833 maxval_container => actual_x_data%store_forces%maxval_container(1)
834 maxval_cache => actual_x_data%store_forces%maxval_cache(1)
835
836 integral_containers => actual_x_data%store_forces%integral_containers(:, 1)
837 integral_caches => actual_x_data%store_forces%integral_caches(:, 1)
838 END IF
839 END IF
840
841 nblocks = load_balance_parameter%nblocks
842
843 bins_left = .true.
844 do_it = .true.
845 bin = 0
846 DO WHILE (bins_left)
847 IF (.NOT. do_dynamic_load_balancing) THEN
848 bin = bin + 1
849 IF (bin > my_bin_size) THEN
850 do_it = .false.
851 bins_left = .false.
852 ELSE
853 do_it = .true.
854 bins_left = .true.
855 distribution_forces => actual_x_data%distribution_forces(bin)
856 END IF
857 ELSE
858!$OMP CRITICAL(hfxderivatives_critical)
859 shm_task_counter = shm_task_counter + 1
860 IF (shm_task_counter <= shm_total_bins) THEN
861 my_thread_id = shm_task_list(shm_task_counter)%thread_id
862 my_bin_id = shm_task_list(shm_task_counter)%bin_id
863 IF (treat_forces_in_core) THEN
864 maxval_cache => my_x_data(irep, my_thread_id)%store_forces%maxval_cache(my_bin_id)
865 maxval_container => my_x_data(irep, my_thread_id)%store_forces%maxval_container(my_bin_id)
866 integral_caches => my_x_data(irep, my_thread_id)%store_forces%integral_caches(:, my_bin_id)
867 integral_containers => my_x_data(irep, my_thread_id)%store_forces%integral_containers(:, my_bin_id)
868 END IF
869 distribution_forces => my_x_data(irep, my_thread_id)%distribution_forces(my_bin_id)
870 do_it = .true.
871 bins_left = .true.
872 IF (actual_x_data%memory_parameter%recalc_forces) THEN
873 distribution_forces%ram_counter = huge(distribution_forces%ram_counter)
874 END IF
875 counter = 0_int_8
876 ELSE
877 do_it = .false.
878 bins_left = .false.
879 END IF
880!$OMP END CRITICAL(hfxderivatives_critical)
881 END IF
882
883 IF (.NOT. do_it) cycle
884!$OMP MASTER
885 CALL timeset(routinen//"_bin", handle_bin)
886!$OMP END MASTER
887 bintime_start = m_walltime()
888 my_istart = distribution_forces%istart
889 my_current_counter = 0
890 IF (distribution_forces%number_of_atom_quartets == 0 .OR. &
891 my_istart == -1_int_8) my_istart = nblocks**4
892 atomic_blocks: DO atom_block = my_istart, nblocks**4 - 1, n_processes
893 latom_block = int(modulo(atom_block, nblocks)) + 1
894 tmp_block = atom_block/nblocks
895 katom_block = int(modulo(tmp_block, nblocks)) + 1
896 IF (latom_block < katom_block) cycle atomic_blocks
897 tmp_block = tmp_block/nblocks
898 jatom_block = int(modulo(tmp_block, nblocks)) + 1
899 tmp_block = tmp_block/nblocks
900 iatom_block = int(modulo(tmp_block, nblocks)) + 1
901 IF (jatom_block < iatom_block) cycle atomic_blocks
902 my_current_counter = my_current_counter + 1
903 IF (my_current_counter > distribution_forces%number_of_atom_quartets) EXIT atomic_blocks
904
905 iatom_start = actual_x_data%blocks(iatom_block)%istart
906 iatom_end = actual_x_data%blocks(iatom_block)%iend
907 jatom_start = actual_x_data%blocks(jatom_block)%istart
908 jatom_end = actual_x_data%blocks(jatom_block)%iend
909 katom_start = actual_x_data%blocks(katom_block)%istart
910 katom_end = actual_x_data%blocks(katom_block)%iend
911 latom_start = actual_x_data%blocks(latom_block)%istart
912 latom_end = actual_x_data%blocks(latom_block)%iend
913
914 pmax_blocks = max(shm_pmax_block(katom_block, iatom_block) + &
915 shm_pmax_block(latom_block, jatom_block), &
916 shm_pmax_block(latom_block, iatom_block) + &
917 shm_pmax_block(katom_block, jatom_block))
918
919 IF (2.0_dp*coeffs_kind_max0 + pmax_blocks < log10_eps_schwarz) cycle atomic_blocks
920
921 CALL build_pair_list(natom, list_ij, set_list_ij, iatom_start, iatom_end, &
922 jatom_start, jatom_end, &
923 kind_of, basis_parameter, particle_set, &
924 do_periodic, screen_coeffs_set, screen_coeffs_kind, coeffs_kind_max0, &
925 log10_eps_schwarz, cell, pmax_blocks, shm_atomic_pair_list)
926
927 CALL build_pair_list(natom, list_kl, set_list_kl, katom_start, katom_end, &
928 latom_start, latom_end, &
929 kind_of, basis_parameter, particle_set, &
930 do_periodic, screen_coeffs_set, screen_coeffs_kind, coeffs_kind_max0, &
931 log10_eps_schwarz, cell, pmax_blocks, shm_atomic_pair_list)
932
933 DO i_list_ij = 1, list_ij%n_element
934 iatom = list_ij%elements(i_list_ij)%pair(1)
935 jatom = list_ij%elements(i_list_ij)%pair(2)
936 i_set_list_ij_start = list_ij%elements(i_list_ij)%set_bounds(1)
937 i_set_list_ij_stop = list_ij%elements(i_list_ij)%set_bounds(2)
938 ikind = list_ij%elements(i_list_ij)%kind_pair(1)
939 jkind = list_ij%elements(i_list_ij)%kind_pair(2)
940 ra = list_ij%elements(i_list_ij)%r1
941 rb = list_ij%elements(i_list_ij)%r2
942 rab2 = list_ij%elements(i_list_ij)%dist2
943
944 la_max => basis_parameter(ikind)%lmax
945 la_min => basis_parameter(ikind)%lmin
946 npgfa => basis_parameter(ikind)%npgf
947 nseta = basis_parameter(ikind)%nset
948 zeta => basis_parameter(ikind)%zet
949 nsgfa => basis_parameter(ikind)%nsgf
950 sphi_a_ext => basis_parameter(ikind)%sphi_ext(:, :, :, :)
951 nsgfl_a => basis_parameter(ikind)%nsgfl
952 sphi_a_u1 = ubound(sphi_a_ext, 1)
953 sphi_a_u2 = ubound(sphi_a_ext, 2)
954 sphi_a_u3 = ubound(sphi_a_ext, 3)
955
956 lb_max => basis_parameter(jkind)%lmax
957 lb_min => basis_parameter(jkind)%lmin
958 npgfb => basis_parameter(jkind)%npgf
959 nsetb = basis_parameter(jkind)%nset
960 zetb => basis_parameter(jkind)%zet
961 nsgfb => basis_parameter(jkind)%nsgf
962 sphi_b_ext => basis_parameter(jkind)%sphi_ext(:, :, :, :)
963 nsgfl_b => basis_parameter(jkind)%nsgfl
964 sphi_b_u1 = ubound(sphi_b_ext, 1)
965 sphi_b_u2 = ubound(sphi_b_ext, 2)
966 sphi_b_u3 = ubound(sphi_b_ext, 3)
967
968 i_atom = atom_of_kind(iatom)
969 forces_map(1, 1) = ikind
970 forces_map(1, 2) = i_atom
971 j_atom = atom_of_kind(jatom)
972 forces_map(2, 1) = jkind
973 forces_map(2, 2) = j_atom
974
975 DO i_list_kl = 1, list_kl%n_element
976 katom = list_kl%elements(i_list_kl)%pair(1)
977 latom = list_kl%elements(i_list_kl)%pair(2)
978
979 !All four centers equivalent => zero-contribution
980!VIIRAL IF((iatom==jatom .AND. iatom==katom .AND. iatom==latom)) CYCLE
981 IF (.NOT. (katom + latom <= iatom + jatom)) cycle
982 IF (((iatom + jatom) == (katom + latom)) .AND. (katom < iatom)) cycle
983
984 i_set_list_kl_start = list_kl%elements(i_list_kl)%set_bounds(1)
985 i_set_list_kl_stop = list_kl%elements(i_list_kl)%set_bounds(2)
986 kkind = list_kl%elements(i_list_kl)%kind_pair(1)
987 lkind = list_kl%elements(i_list_kl)%kind_pair(2)
988 rc = list_kl%elements(i_list_kl)%r1
989 rd = list_kl%elements(i_list_kl)%r2
990 rcd2 = list_kl%elements(i_list_kl)%dist2
991
992 IF (screen_pmat_forces) THEN
993 pmax_atom = max(shm_pmax_atom(katom, iatom) + &
994 shm_pmax_atom(latom, jatom), &
995 shm_pmax_atom(latom, iatom) + &
996 shm_pmax_atom(katom, jatom))
997 ELSE
998 pmax_atom = 0.0_dp
999 END IF
1000
1001 IF ((screen_coeffs_kind(jkind, ikind)%x(1)*rab2 + &
1002 screen_coeffs_kind(jkind, ikind)%x(2)) + &
1003 (screen_coeffs_kind(lkind, kkind)%x(1)*rcd2 + &
1004 screen_coeffs_kind(lkind, kkind)%x(2)) + pmax_atom < log10_eps_schwarz) cycle
1005
1006 IF (.NOT. (shm_is_assoc_atomic_block(latom, iatom) >= 1 .AND. &
1007 shm_is_assoc_atomic_block(katom, iatom) >= 1 .AND. &
1008 shm_is_assoc_atomic_block(katom, jatom) >= 1 .AND. &
1009 shm_is_assoc_atomic_block(latom, jatom) >= 1)) cycle
1010 k_atom = atom_of_kind(katom)
1011 forces_map(3, 1) = kkind
1012 forces_map(3, 2) = k_atom
1013
1014 l_atom = atom_of_kind(latom)
1015 forces_map(4, 1) = lkind
1016 forces_map(4, 2) = l_atom
1017
1018 IF (my_nspins == 1) THEN
1019 fac = 0.25_dp*hf_fraction
1020 ELSE
1021 fac = 0.5_dp*hf_fraction
1022 END IF
1023 !calculate symmetry_factor
1024 symm_fac = 0.25_dp
1025 IF (iatom == jatom) symm_fac = symm_fac*2.0_dp
1026 IF (katom == latom) symm_fac = symm_fac*2.0_dp
1027 IF (iatom == katom .AND. jatom == latom .AND. &
1028 iatom /= jatom .AND. katom /= latom) symm_fac = symm_fac*2.0_dp
1029 IF (iatom == katom .AND. iatom == jatom .AND. &
1030 katom == latom) symm_fac = symm_fac*2.0_dp
1031
1032 symm_fac = 1.0_dp/symm_fac
1033 fac = fac*symm_fac
1034
1035 lc_max => basis_parameter(kkind)%lmax
1036 lc_min => basis_parameter(kkind)%lmin
1037 npgfc => basis_parameter(kkind)%npgf
1038 zetc => basis_parameter(kkind)%zet
1039 nsgfc => basis_parameter(kkind)%nsgf
1040 sphi_c_ext => basis_parameter(kkind)%sphi_ext(:, :, :, :)
1041 nsgfl_c => basis_parameter(kkind)%nsgfl
1042 sphi_c_u1 = ubound(sphi_c_ext, 1)
1043 sphi_c_u2 = ubound(sphi_c_ext, 2)
1044 sphi_c_u3 = ubound(sphi_c_ext, 3)
1045
1046 ld_max => basis_parameter(lkind)%lmax
1047 ld_min => basis_parameter(lkind)%lmin
1048 npgfd => basis_parameter(lkind)%npgf
1049 zetd => basis_parameter(lkind)%zet
1050 nsgfd => basis_parameter(lkind)%nsgf
1051 sphi_d_ext => basis_parameter(lkind)%sphi_ext(:, :, :, :)
1052 nsgfl_d => basis_parameter(lkind)%nsgfl
1053 sphi_d_u1 = ubound(sphi_d_ext, 1)
1054 sphi_d_u2 = ubound(sphi_d_ext, 2)
1055 sphi_d_u3 = ubound(sphi_d_ext, 3)
1056
1057 atomic_offset_bd = shm_atomic_block_offset(jatom, latom)
1058 atomic_offset_bc = shm_atomic_block_offset(jatom, katom)
1059 atomic_offset_ad = shm_atomic_block_offset(iatom, latom)
1060 atomic_offset_ac = shm_atomic_block_offset(iatom, katom)
1061
1062 IF (jatom < latom) THEN
1063 offset_bd_set => shm_set_offset(:, :, lkind, jkind)
1064 ELSE
1065 offset_bd_set => shm_set_offset(:, :, jkind, lkind)
1066 END IF
1067 IF (jatom < katom) THEN
1068 offset_bc_set => shm_set_offset(:, :, kkind, jkind)
1069 ELSE
1070 offset_bc_set => shm_set_offset(:, :, jkind, kkind)
1071 END IF
1072 IF (iatom < latom) THEN
1073 offset_ad_set => shm_set_offset(:, :, lkind, ikind)
1074 ELSE
1075 offset_ad_set => shm_set_offset(:, :, ikind, lkind)
1076 END IF
1077 IF (iatom < katom) THEN
1078 offset_ac_set => shm_set_offset(:, :, kkind, ikind)
1079 ELSE
1080 offset_ac_set => shm_set_offset(:, :, ikind, kkind)
1081 END IF
1082
1083 IF (screen_pmat_forces) THEN
1084 swap_id = 16
1085 kind_kind_idx = int(get_1d_idx(kkind, ikind, int(nkind, int_8)))
1086 IF (ikind >= kkind) THEN
1087 ptr_p_1 => shm_initial_p(kind_kind_idx)%p_kind(:, :, &
1088 actual_x_data%map_atom_to_kind_atom(katom), &
1089 actual_x_data%map_atom_to_kind_atom(iatom))
1090 ELSE
1091 ptr_p_1 => shm_initial_p(kind_kind_idx)%p_kind(:, :, &
1092 actual_x_data%map_atom_to_kind_atom(iatom), &
1093 actual_x_data%map_atom_to_kind_atom(katom))
1094 swap_id = swap_id + 1
1095 END IF
1096 kind_kind_idx = int(get_1d_idx(lkind, jkind, int(nkind, int_8)))
1097 IF (jkind >= lkind) THEN
1098 ptr_p_2 => shm_initial_p(kind_kind_idx)%p_kind(:, :, &
1099 actual_x_data%map_atom_to_kind_atom(latom), &
1100 actual_x_data%map_atom_to_kind_atom(jatom))
1101 ELSE
1102 ptr_p_2 => shm_initial_p(kind_kind_idx)%p_kind(:, :, &
1103 actual_x_data%map_atom_to_kind_atom(jatom), &
1104 actual_x_data%map_atom_to_kind_atom(latom))
1105 swap_id = swap_id + 2
1106 END IF
1107 kind_kind_idx = int(get_1d_idx(lkind, ikind, int(nkind, int_8)))
1108 IF (ikind >= lkind) THEN
1109 ptr_p_3 => shm_initial_p(kind_kind_idx)%p_kind(:, :, &
1110 actual_x_data%map_atom_to_kind_atom(latom), &
1111 actual_x_data%map_atom_to_kind_atom(iatom))
1112 ELSE
1113 ptr_p_3 => shm_initial_p(kind_kind_idx)%p_kind(:, :, &
1114 actual_x_data%map_atom_to_kind_atom(iatom), &
1115 actual_x_data%map_atom_to_kind_atom(latom))
1116 swap_id = swap_id + 4
1117 END IF
1118 kind_kind_idx = int(get_1d_idx(kkind, jkind, int(nkind, int_8)))
1119 IF (jkind >= kkind) THEN
1120 ptr_p_4 => shm_initial_p(kind_kind_idx)%p_kind(:, :, &
1121 actual_x_data%map_atom_to_kind_atom(katom), &
1122 actual_x_data%map_atom_to_kind_atom(jatom))
1123 ELSE
1124 ptr_p_4 => shm_initial_p(kind_kind_idx)%p_kind(:, :, &
1125 actual_x_data%map_atom_to_kind_atom(jatom), &
1126 actual_x_data%map_atom_to_kind_atom(katom))
1127 swap_id = swap_id + 8
1128 END IF
1129 END IF
1130
1131 !! At this stage, check for memory used in compression
1132
1133 IF (actual_x_data%memory_parameter%recalc_forces) THEN
1134 IF (treat_forces_in_core) THEN
1135 ! ** We know the maximum amount of integrals that we can store per MPI-process
1136 ! ** Now we need to sum the current memory usage among all openMP threads
1137 ! ** We can just read what is currently stored on the corresponding x_data type
1138 ! ** If this is thread i and it tries to read the data from thread j, that is
1139 ! ** currently writing that data, we just dont care, because the possible error
1140 ! ** is of the order of CACHE_SIZE
1141 mem_compression_counter = 0
1142 DO i = 1, n_threads
1143!$OMP ATOMIC READ
1144 tmp_i4 = my_x_data(irep, i)%memory_parameter%actual_memory_usage
1145 mem_compression_counter = mem_compression_counter + &
1146 tmp_i4*memory_parameter%cache_size
1147 END DO
1148 IF (mem_compression_counter + memory_parameter%final_comp_counter_energy &
1149 > memory_parameter%max_compression_counter) THEN
1150 buffer_overflow = .true.
1151 IF (do_dynamic_load_balancing) THEN
1152 distribution_forces%ram_counter = counter
1153 ELSE
1154 memory_parameter%ram_counter_forces = counter
1155 END IF
1156 ELSE
1157 counter = counter + 1
1158 buffer_overflow = .false.
1159 END IF
1160 END IF
1161 ELSE
1162 IF (treat_forces_in_core) THEN
1163 IF (do_dynamic_load_balancing) THEN
1164 IF (distribution_forces%ram_counter == counter) THEN
1165 buffer_overflow = .true.
1166 ELSE
1167 counter = counter + 1
1168 buffer_overflow = .false.
1169 END IF
1170 ELSE
1171 IF (memory_parameter%ram_counter_forces == counter) THEN
1172 buffer_overflow = .true.
1173 ELSE
1174 counter = counter + 1
1175 buffer_overflow = .false.
1176 END IF
1177 END IF
1178 END IF
1179 END IF
1180
1181 DO i_set_list_ij = i_set_list_ij_start, i_set_list_ij_stop
1182 iset = set_list_ij(i_set_list_ij)%pair(1)
1183 jset = set_list_ij(i_set_list_ij)%pair(2)
1184
1185 ncob = npgfb(jset)*ncoset(lb_max(jset))
1186 max_val1 = screen_coeffs_set(jset, iset, jkind, ikind)%x(1)*rab2 + &
1187 screen_coeffs_set(jset, iset, jkind, ikind)%x(2)
1188 !! Near field screening
1189 IF (max_val1 + (screen_coeffs_kind(lkind, kkind)%x(1)*rcd2 + &
1190 screen_coeffs_kind(lkind, kkind)%x(2)) + pmax_atom < log10_eps_schwarz) cycle
1191
1192 DO i_set_list_kl = i_set_list_kl_start, i_set_list_kl_stop
1193 kset = set_list_kl(i_set_list_kl)%pair(1)
1194 lset = set_list_kl(i_set_list_kl)%pair(2)
1195
1196 max_val2_set = (screen_coeffs_set(lset, kset, lkind, kkind)%x(1)*rcd2 + &
1197 screen_coeffs_set(lset, kset, lkind, kkind)%x(2))
1198 max_val2 = max_val1 + max_val2_set
1199
1200 !! Near field screening
1201 IF (max_val2 + pmax_atom < log10_eps_schwarz) cycle
1202
1203 IF (screen_pmat_forces) THEN
1204 CALL get_pmax_val(ptr_p_1, ptr_p_2, ptr_p_3, ptr_p_4, &
1205 iset, jset, kset, lset, &
1206 pmax_tmp, swap_id)
1207
1208 log10_pmax = log_2 + pmax_tmp
1209 ELSE
1210 log10_pmax = 0.0_dp
1211 END IF
1212
1213 max_val2 = max_val2 + log10_pmax
1214 IF (max_val2 < log10_eps_schwarz) cycle
1215
1216 pmax_entry = exp(log10_pmax*ln_10)
1217 !! store current number of integrals, update total number and number of integrals in buffer
1218 current_counter = nsgfa(iset)*nsgfb(jset)*nsgfc(kset)*nsgfd(lset)*12
1219 IF (buffer_overflow) THEN
1220 neris_onthefly = neris_onthefly + current_counter
1221 END IF
1222
1223 !! Get integrals from buffer and update Kohn-Sham matrix
1224 IF (.NOT. buffer_overflow .AND. .NOT. actual_x_data%memory_parameter%recalc_forces) THEN
1225 nints = current_counter
1226 CALL hfx_get_single_cache_element(estimate_to_store_int, 6, &
1227 maxval_cache, maxval_container, memory_parameter%actual_memory_usage, &
1228 use_disk_storage)
1229 spherical_estimate = set_exponent(1.0_dp, estimate_to_store_int + 1)
1230! IF (spherical_estimate*pmax_entry < eps_schwarz) CYCLE
1231 IF (.NOT. use_virial) THEN
1232 IF (spherical_estimate*pmax_entry < eps_schwarz) cycle
1233 END IF
1234 nbits = exponent(anint(spherical_estimate*pmax_entry/eps_storage)) + 1
1235 buffer_left = nints
1236 buffer_start = 1
1237 neris_incore = neris_incore + int(nints, int_8)
1238 DO WHILE (buffer_left > 0)
1239 buffer_size = min(buffer_left, cache_size)
1240 CALL hfx_get_mult_cache_elements(primitive_forces(buffer_start), &
1241 buffer_size, nbits, &
1242 integral_caches(nbits), &
1243 integral_containers(nbits), &
1244 eps_storage, pmax_entry, &
1245 memory_parameter%actual_memory_usage, &
1246 use_disk_storage)
1247 buffer_left = buffer_left - buffer_size
1248 buffer_start = buffer_start + buffer_size
1249 END DO
1250 END IF
1251 !! Calculate integrals if we run out of buffer or the geometry did change
1252 IF (actual_x_data%memory_parameter%recalc_forces .OR. buffer_overflow) THEN
1253 sphi_a_ext_set => sphi_a_ext(:, :, :, iset)
1254 sphi_b_ext_set => sphi_b_ext(:, :, :, jset)
1255 sphi_c_ext_set => sphi_c_ext(:, :, :, kset)
1256 sphi_d_ext_set => sphi_d_ext(:, :, :, lset)
1257 max_contraction_val = max_contraction(iset, iatom)* &
1258 max_contraction(jset, jatom)* &
1259 max_contraction(kset, katom)* &
1260 max_contraction(lset, latom)* &
1261 pmax_entry
1262 tmp_r_1 => radii_pgf(:, :, jset, iset, jkind, ikind)
1263 tmp_r_2 => radii_pgf(:, :, lset, kset, lkind, kkind)
1264 tmp_screen_pgf1 => screen_coeffs_pgf(:, :, jset, iset, jkind, ikind)
1265 tmp_screen_pgf2 => screen_coeffs_pgf(:, :, lset, kset, lkind, kkind)
1266
1267 CALL forces4(actual_x_data%eri4_context, ra, rb, rc, rd, npgfa(iset), npgfb(jset), &
1268 npgfc(kset), npgfd(lset), &
1269 la_min(iset), la_max(iset), lb_min(jset), lb_max(jset), &
1270 lc_min(kset), lc_max(kset), ld_min(lset), ld_max(lset), &
1271 nsgfa(iset), nsgfb(jset), nsgfc(kset), nsgfd(lset), &
1272 sphi_a_u1, sphi_a_u2, sphi_a_u3, &
1273 sphi_b_u1, sphi_b_u2, sphi_b_u3, &
1274 sphi_c_u1, sphi_c_u2, sphi_c_u3, &
1275 sphi_d_u1, sphi_d_u2, sphi_d_u3, &
1276 zeta(1:npgfa(iset), iset), zetb(1:npgfb(jset), jset), &
1277 zetc(1:npgfc(kset), kset), zetd(1:npgfd(lset), lset), &
1278 primitive_forces, &
1279 potential_parameter, &
1280 actual_x_data%neighbor_cells, &
1281 screen_coeffs_set(jset, iset, jkind, ikind)%x, &
1282 screen_coeffs_set(lset, kset, lkind, kkind)%x, eps_schwarz, &
1283 max_contraction_val, cartesian_estimate, cell, neris_tmp, &
1284 log10_pmax, log10_eps_schwarz, &
1285 tmp_r_1, tmp_r_2, tmp_screen_pgf1, tmp_screen_pgf2, &
1286 pgf_list_ij, pgf_list_kl, nsgfl_a(:, iset), nsgfl_b(:, jset), &
1287 nsgfl_c(:, kset), nsgfl_d(:, lset), &
1288 sphi_a_ext_set, sphi_b_ext_set, sphi_c_ext_set, sphi_d_ext_set, &
1289 ede_work, ede_work2, ede_work_forces, &
1290 ede_buffer1, ede_buffer2, ede_primitives_tmp, &
1291 nimages, do_periodic, use_virial, ede_work_virial, ede_work2_virial, &
1292 ede_primitives_tmp_virial, primitive_forces_virial, &
1293 cartesian_estimate_virial)
1294
1295 nints = nsgfa(iset)*nsgfb(jset)*nsgfc(kset)*nsgfd(lset)*12
1296 neris_total = neris_total + nints
1297 nprim_ints = nprim_ints + neris_tmp
1298! IF (cartesian_estimate == 0.0_dp) cartesian_estimate = TINY(cartesian_estimate)
1299! estimate_to_store_int = EXPONENT(cartesian_estimate)
1300! estimate_to_store_int = MAX(estimate_to_store_int, -15_int_8)
1301! cartesian_estimate = SET_EXPONENT(1.0_dp, estimate_to_store_int+1)
1302! IF (.NOT. buffer_overflow .AND. actual_x_data%memory_parameter%recalc_forces) THEN
1303! IF (cartesian_estimate < eps_schwarz) THEN
1304! CALL hfx_add_single_cache_element( &
1305! estimate_to_store_int, 6, &
1306! maxval_cache, maxval_container, memory_parameter%actual_memory_usage, &
1307! use_disk_storage, max_val_memory)
1308! END IF
1309! END IF
1310!
1311! IF (.NOT. use_virial) THEN
1312! IF (cartesian_estimate < eps_schwarz) CYCLE
1313! END IF
1314
1315 !! Compress the array for storage
1316 spherical_estimate = 0.0_dp
1317 IF (cartesian_estimate /= 0.0_dp) THEN
1318 DO i = 1, nints
1319 spherical_estimate = max(spherical_estimate, abs(primitive_forces(i)))
1320 END DO
1321 END IF
1322
1323 spherical_estimate_virial = 0.0_dp
1324 IF (use_virial .AND. cartesian_estimate_virial /= 0.0_dp) THEN
1325 DO i = 1, 3*nints
1326 spherical_estimate_virial = max(spherical_estimate_virial, abs(primitive_forces_virial(i)))
1327 END DO
1328 END IF
1329
1330 IF (spherical_estimate == 0.0_dp) spherical_estimate = tiny(spherical_estimate)
1331 estimate_to_store_int = exponent(spherical_estimate)
1332 estimate_to_store_int = max(estimate_to_store_int, -15_int_8)
1333 IF (.NOT. buffer_overflow .AND. actual_x_data%memory_parameter%recalc_forces) THEN
1334 CALL hfx_add_single_cache_element(estimate_to_store_int, 6, &
1335 maxval_cache, maxval_container, &
1336 memory_parameter%actual_memory_usage, &
1337 use_disk_storage, max_val_memory)
1338 END IF
1339 spherical_estimate = set_exponent(1.0_dp, estimate_to_store_int + 1)
1340 IF (.NOT. use_virial) THEN
1341 IF (spherical_estimate*pmax_entry < eps_schwarz) cycle
1342 END IF
1343 IF (.NOT. buffer_overflow) THEN
1344 nbits = exponent(anint(spherical_estimate*pmax_entry/eps_storage)) + 1
1345 buffer_left = nints
1346 buffer_start = 1
1347! neris_incore = neris_incore+nints
1348 neris_incore = neris_incore + int(nints, int_8)
1349
1350 DO WHILE (buffer_left > 0)
1351 buffer_size = min(buffer_left, cache_size)
1352 CALL hfx_add_mult_cache_elements(primitive_forces(buffer_start), &
1353 buffer_size, nbits, &
1354 integral_caches(nbits), &
1355 integral_containers(nbits), &
1356 eps_storage, pmax_entry, &
1357 memory_parameter%actual_memory_usage, &
1358 use_disk_storage)
1359 buffer_left = buffer_left - buffer_size
1360 buffer_start = buffer_start + buffer_size
1361 END DO
1362 ELSE
1363 !! In order to be consistent with in-core part, round all the eris wrt. eps_schwarz
1364 !! but only if we treat forces in-core
1365 IF (treat_forces_in_core .AND. cartesian_estimate /= 0.0_dp) THEN
1366 DO i = 1, nints
1367 primitive_forces(i) = primitive_forces(i)*pmax_entry
1368 IF (abs(primitive_forces(i)) > eps_storage) THEN
1369 primitive_forces(i) = anint(primitive_forces(i)/eps_storage, dp)*eps_storage/pmax_entry
1370 ELSE
1371 primitive_forces(i) = 0.0_dp
1372 END IF
1373 END DO
1374 END IF
1375 END IF
1376 IF (cartesian_estimate == 0.0_dp .AND. &
1377 (.NOT. use_virial .OR. cartesian_estimate_virial == 0.0_dp)) cycle
1378 END IF
1379 IF (with_resp_density) THEN
1380 CALL prefetch_density_matrix(nsgfa(iset), nsgfb(jset), nsgfc(kset), nsgfd(lset), &
1381 full_density_alpha(:, 1), pbd_buf, pbc_buf, pad_buf, pac_buf, &
1382 iatom, jatom, katom, latom, &
1383 iset, jset, kset, lset, offset_bd_set, offset_bc_set, &
1384 offset_ad_set, offset_ac_set, atomic_offset_bd, atomic_offset_bc, &
1385 atomic_offset_ad, atomic_offset_ac, is_anti_symmetric)
1386 CALL prefetch_density_matrix(nsgfa(iset), nsgfb(jset), nsgfc(kset), nsgfd(lset), &
1387 full_density_resp, pbd_buf_resp, pbc_buf_resp, pad_buf_resp, pac_buf_resp, &
1388 iatom, jatom, katom, latom, &
1389 iset, jset, kset, lset, offset_bd_set, offset_bc_set, &
1390 offset_ad_set, offset_ac_set, atomic_offset_bd, atomic_offset_bc, &
1391 atomic_offset_ad, atomic_offset_ac, is_anti_symmetric)
1392 ELSE
1393 CALL prefetch_density_matrix(nsgfa(iset), nsgfb(jset), nsgfc(kset), nsgfd(lset), &
1394 full_density_alpha(:, 1), pbd_buf, pbc_buf, pad_buf, pac_buf, &
1395 iatom, jatom, katom, latom, &
1396 iset, jset, kset, lset, offset_bd_set, offset_bc_set, &
1397 offset_ad_set, offset_ac_set, atomic_offset_bd, atomic_offset_bc, &
1398 atomic_offset_ad, atomic_offset_ac, is_anti_symmetric)
1399 END IF
1400 IF (my_nspins == 2) THEN
1401 IF (with_resp_density) THEN
1402 CALL prefetch_density_matrix(nsgfa(iset), nsgfb(jset), nsgfc(kset), nsgfd(lset), &
1403 full_density_beta(:, 1), pbd_buf_beta, pbc_buf_beta, &
1404 pad_buf_beta, pac_buf_beta, iatom, jatom, katom, latom, &
1405 iset, jset, kset, lset, offset_bd_set, offset_bc_set, &
1406 offset_ad_set, offset_ac_set, atomic_offset_bd, atomic_offset_bc, &
1407 atomic_offset_ad, atomic_offset_ac, is_anti_symmetric)
1408 CALL prefetch_density_matrix(nsgfa(iset), nsgfb(jset), nsgfc(kset), nsgfd(lset), &
1409 full_density_resp_beta, pbd_buf_resp_beta, pbc_buf_resp_beta, &
1410 pad_buf_resp_beta, pac_buf_resp_beta, iatom, jatom, katom, latom, &
1411 iset, jset, kset, lset, offset_bd_set, offset_bc_set, &
1412 offset_ad_set, offset_ac_set, atomic_offset_bd, atomic_offset_bc, &
1413 atomic_offset_ad, atomic_offset_ac, is_anti_symmetric)
1414 ELSE
1415 CALL prefetch_density_matrix(nsgfa(iset), nsgfb(jset), nsgfc(kset), nsgfd(lset), &
1416 full_density_beta(:, 1), pbd_buf_beta, pbc_buf_beta, pad_buf_beta, &
1417 pac_buf_beta, iatom, jatom, katom, latom, &
1418 iset, jset, kset, lset, offset_bd_set, offset_bc_set, &
1419 offset_ad_set, offset_ac_set, atomic_offset_bd, atomic_offset_bc, &
1420 atomic_offset_ad, atomic_offset_ac, is_anti_symmetric)
1421 END IF
1422 END IF
1423 IF (spherical_estimate*pmax_entry >= eps_schwarz) THEN
1424 DO coord = 1, 12
1425 t2 => primitive_forces((coord - 1)*nsgfa(iset)*nsgfb(jset)*nsgfc(kset)*nsgfd(lset) + 1: &
1426 coord*nsgfa(iset)*nsgfb(jset)*nsgfc(kset)*nsgfd(lset))
1427
1428 IF (with_resp_density) THEN
1429 CALL update_forces(nsgfa(iset), nsgfb(jset), nsgfc(kset), nsgfd(lset), &
1430 pbd_buf, pbc_buf, pad_buf, pac_buf, fac, &
1431 t2, force, forces_map, coord, &
1432 pbd_buf_resp, pbc_buf_resp, pad_buf_resp, pac_buf_resp, &
1433 my_resp_only)
1434 ELSE
1435 CALL update_forces(nsgfa(iset), nsgfb(jset), nsgfc(kset), nsgfd(lset), &
1436 pbd_buf, pbc_buf, pad_buf, pac_buf, fac, &
1437 t2, force, forces_map, coord)
1438 END IF
1439 IF (my_nspins == 2) THEN
1440 IF (with_resp_density) THEN
1441 CALL update_forces(nsgfa(iset), nsgfb(jset), nsgfc(kset), nsgfd(lset), &
1442 pbd_buf_beta, pbc_buf_beta, pad_buf_beta, pac_buf_beta, &
1443 fac, t2, force, forces_map, coord, &
1444 pbd_buf_resp_beta, pbc_buf_resp_beta, &
1445 pad_buf_resp_beta, pac_buf_resp_beta, &
1446 my_resp_only)
1447 ELSE
1448 CALL update_forces(nsgfa(iset), nsgfb(jset), nsgfc(kset), nsgfd(lset), &
1449 pbd_buf_beta, pbc_buf_beta, pad_buf_beta, pac_buf_beta, fac, &
1450 t2, force, forces_map, coord)
1451 END IF
1452 END IF
1453 END DO !coord
1454 END IF
1455 IF (use_virial .AND. spherical_estimate_virial*pmax_entry >= eps_schwarz) THEN
1456 DO coord = 1, 12
1457 DO i = 1, 3
1458 t2 => primitive_forces_virial( &
1459 ((i - 1)*12 + coord - 1)*nsgfa(iset)*nsgfb(jset)*nsgfc(kset)*nsgfd(lset) + 1: &
1460 ((i - 1)*12 + coord)*nsgfa(iset)*nsgfb(jset)*nsgfc(kset)*nsgfd(lset))
1461 IF (with_resp_density) THEN
1462 CALL update_virial(nsgfa(iset), nsgfb(jset), nsgfc(kset), nsgfd(lset), &
1463 pbd_buf, pbc_buf, pad_buf, pac_buf, fac, &
1464 t2, tmp_virial, coord, i, &
1465 pbd_buf_resp, pbc_buf_resp, pad_buf_resp, &
1466 pac_buf_resp, my_resp_only)
1467 ELSE
1468 CALL update_virial(nsgfa(iset), nsgfb(jset), nsgfc(kset), nsgfd(lset), &
1469 pbd_buf, pbc_buf, pad_buf, pac_buf, fac, &
1470 t2, tmp_virial, coord, i)
1471 END IF
1472 IF (my_nspins == 2) THEN
1473 IF (with_resp_density) THEN
1474 CALL update_virial(nsgfa(iset), nsgfb(jset), nsgfc(kset), nsgfd(lset), &
1475 pbd_buf_beta, pbc_buf_beta, pad_buf_beta, pac_buf_beta, &
1476 fac, t2, tmp_virial, coord, i, &
1477 pbd_buf_resp_beta, pbc_buf_resp_beta, &
1478 pad_buf_resp_beta, pac_buf_resp_beta, &
1479 my_resp_only)
1480 ELSE
1481 CALL update_virial(nsgfa(iset), nsgfb(jset), nsgfc(kset), nsgfd(lset), &
1482 pbd_buf_beta, pbc_buf_beta, pad_buf_beta, pac_buf_beta, &
1483 fac, t2, tmp_virial, coord, i)
1484 END IF
1485 END IF
1486 END DO
1487 END DO !coord
1488 END IF
1489
1490 END DO !i_set_list_kl
1491 END DO !i_set_list_ij
1492 END DO !i_list_kl
1493 END DO !i_list_ij
1494 END DO atomic_blocks
1495 bintime_stop = m_walltime()
1496 distribution_forces%time_forces = bintime_stop - bintime_start
1497!$OMP MASTER
1498 CALL timestop(handle_bin)
1499!$OMP END MASTER
1500 END DO !bin
1501
1502!$OMP MASTER
1503 logger => cp_get_default_logger()
1504 do_print_load_balance_info = .false.
1505 do_print_load_balance_info = btest(cp_print_key_should_output(logger%iter_info, hfx_section, &
1506 "LOAD_BALANCE%PRINT/LOAD_BALANCE_INFO"), cp_p_file)
1507!$OMP END MASTER
1508!$OMP BARRIER
1509 IF (do_print_load_balance_info) THEN
1510 iw = -1
1511!$OMP MASTER
1512 iw = cp_print_key_unit_nr(logger, hfx_section, "LOAD_BALANCE%PRINT/LOAD_BALANCE_INFO", &
1513 extension=".scfLog")
1514!$OMP END MASTER
1515
1516 CALL collect_load_balance_info(para_env, actual_x_data, iw, n_threads, i_thread, &
1518
1519!$OMP MASTER
1520 CALL cp_print_key_finished_output(iw, logger, hfx_section, &
1521 "LOAD_BALANCE%PRINT/LOAD_BALANCE_INFO")
1522!$OMP END MASTER
1523 END IF
1524
1525 IF (use_virial) THEN
1526 DO i = 1, 3
1527 DO j = 1, 3
1528 DO k = 1, 3
1529!$OMP ATOMIC
1530 virial%pv_fock_4c(i, j) = virial%pv_fock_4c(i, j) + tmp_virial(i, k)*cell%hmat(j, k)
1531 END DO
1532 END DO
1533 END DO
1534 END IF
1535
1536!$OMP BARRIER
1537 !! Get some number about ERIS
1538!$OMP ATOMIC
1539 shm_neris_total = shm_neris_total + neris_total
1540!$OMP ATOMIC
1541 shm_neris_onthefly = shm_neris_onthefly + neris_onthefly
1542!$OMP ATOMIC
1543 shm_nprim_ints = shm_nprim_ints + nprim_ints
1544
1545 storage_counter_integrals = memory_parameter%actual_memory_usage* &
1546 memory_parameter%cache_size
1547 stor_count_max_val = max_val_memory*memory_parameter%cache_size
1548!$OMP ATOMIC
1549 shm_storage_counter_integrals = shm_storage_counter_integrals + storage_counter_integrals
1550!$OMP ATOMIC
1551 shm_neris_incore = shm_neris_incore + neris_incore
1552!$OMP ATOMIC
1553 shm_stor_count_max_val = shm_stor_count_max_val + stor_count_max_val
1554!$OMP BARRIER
1555
1556 ! IF(with_resp_density) THEN
1557 ! ! restore original load_balance_parameter
1558 ! actual_x_data%load_balance_parameter = load_balance_parameter_energy
1559 ! DEALLOCATE(load_balance_parameter_energy)
1560 ! END IF
1561
1562!$OMP MASTER
1563 !! Print some memeory information if this is the first step
1564 IF (actual_x_data%memory_parameter%recalc_forces) THEN
1565 tmp_i8(1:6) = [shm_storage_counter_integrals, shm_neris_onthefly, shm_neris_incore, &
1566 shm_neris_total, shm_nprim_ints, shm_stor_count_max_val]
1567 CALL para_env%sum(tmp_i8)
1568 shm_storage_counter_integrals = tmp_i8(1)
1569 shm_neris_onthefly = tmp_i8(2)
1570 shm_neris_incore = tmp_i8(3)
1571 shm_neris_total = tmp_i8(4)
1572 shm_nprim_ints = tmp_i8(5)
1573 shm_stor_count_max_val = tmp_i8(6)
1574 mem_eris = (shm_storage_counter_integrals + 128*1024 - 1)/1024/128
1575 compression_factor = real(shm_neris_incore, dp)/real(shm_storage_counter_integrals, dp)
1576 mem_max_val = (shm_stor_count_max_val + 128*1024 - 1)/1024/128
1577
1578 IF (shm_neris_incore == 0) THEN
1579 mem_eris = 0
1580 compression_factor = 0.0_dp
1581 END IF
1582
1583 logger => cp_get_default_logger()
1584
1585 iw = cp_print_key_unit_nr(logger, hfx_section, "HF_INFO", &
1586 extension=".scfLog")
1587 IF (iw > 0) THEN
1588 WRITE (unit=iw, fmt="(/,(T3,A,T65,I16))") &
1589 "HFX_MEM_INFO| Number of cart. primitive DERIV's calculated: ", shm_nprim_ints
1590
1591 WRITE (unit=iw, fmt="((T3,A,T60,I21))") &
1592 "HFX_MEM_INFO| Number of sph. DERIV's calculated: ", shm_neris_total
1593
1594 WRITE (unit=iw, fmt="((T3,A,T60,I21))") &
1595 "HFX_MEM_INFO| Number of sph. DERIV's stored in-core: ", shm_neris_incore
1596
1597 WRITE (unit=iw, fmt="((T3,A,T62,I19))") &
1598 "HFX_MEM_INFO| Number of sph. DERIV's calculated on the fly: ", shm_neris_onthefly
1599
1600 WRITE (unit=iw, fmt="((T3,A,T60,I21))") &
1601 "HFX_MEM_INFO| Total memory consumption DERIV's RAM [MiB]: ", mem_eris
1602
1603 WRITE (unit=iw, fmt="((T3,A,T60,I21))") &
1604 "HFX_MEM_INFO| Whereof max-vals [MiB]: ", mem_max_val
1605
1606 WRITE (unit=iw, fmt="((T3,A,T60,F21.2),/)") &
1607 "HFX_MEM_INFO| Total compression factor DERIV's RAM: ", compression_factor
1608 END IF
1609
1610 CALL cp_print_key_finished_output(iw, logger, hfx_section, &
1611 "HF_INFO")
1612 END IF
1613!$OMP END MASTER
1614
1615 !! flush caches if the geometry changed
1616 IF (do_dynamic_load_balancing) THEN
1617 my_bin_size = SIZE(actual_x_data%distribution_forces)
1618 ELSE
1619 my_bin_size = 1
1620 END IF
1621
1622 IF (actual_x_data%memory_parameter%recalc_forces) THEN
1623 IF (treat_forces_in_core) THEN
1624 DO bin = 1, my_bin_size
1625 maxval_cache => actual_x_data%store_forces%maxval_cache(bin)
1626 maxval_container => actual_x_data%store_forces%maxval_container(bin)
1627 integral_caches => actual_x_data%store_forces%integral_caches(:, bin)
1628 integral_containers => actual_x_data%store_forces%integral_containers(:, bin)
1629 CALL hfx_flush_last_cache(bits_max_val, maxval_cache, maxval_container, memory_parameter%actual_memory_usage, &
1630 .false.)
1631 DO i = 1, 64
1632 CALL hfx_flush_last_cache(i, integral_caches(i), integral_containers(i), &
1633 memory_parameter%actual_memory_usage, .false.)
1634 END DO
1635 END DO
1636 END IF
1637 END IF
1638 !! reset all caches except we calculate all on the fly
1639 IF (treat_forces_in_core) THEN
1640 DO bin = 1, my_bin_size
1641 maxval_cache => actual_x_data%store_forces%maxval_cache(bin)
1642 maxval_container => actual_x_data%store_forces%maxval_container(bin)
1643 integral_caches => actual_x_data%store_forces%integral_caches(:, bin)
1644 integral_containers => actual_x_data%store_forces%integral_containers(:, bin)
1645
1646 CALL hfx_reset_cache_and_container(maxval_cache, maxval_container, memory_parameter%actual_memory_usage, .false.)
1647 DO i = 1, 64
1648 CALL hfx_reset_cache_and_container(integral_caches(i), integral_containers(i), &
1649 memory_parameter%actual_memory_usage, &
1650 .false.)
1651 END DO
1652 END DO
1653 END IF
1654
1655 IF (actual_x_data%memory_parameter%recalc_forces) THEN
1656 actual_x_data%memory_parameter%recalc_forces = .false.
1657 END IF
1658
1659!$OMP BARRIER
1660!$OMP MASTER
1661 CALL timestop(handle_main)
1662!$OMP END MASTER
1663!$OMP BARRIER
1664 DEALLOCATE (last_sgf_global)
1665!$OMP MASTER
1666 DEALLOCATE (full_density_alpha)
1667 IF (with_resp_density) THEN
1668 DEALLOCATE (full_density_resp)
1669 END IF
1670 IF (my_nspins == 2) THEN
1671 DEALLOCATE (full_density_beta)
1672 IF (with_resp_density) THEN
1673 DEALLOCATE (full_density_resp_beta)
1674 END IF
1675 END IF
1676 IF (do_dynamic_load_balancing) THEN
1677 DEALLOCATE (actual_x_data%task_list)
1678 END IF
1679!$OMP END MASTER
1680 DEALLOCATE (primitive_forces)
1681 DEALLOCATE (atom_of_kind, kind_of)
1682 DEALLOCATE (max_contraction)
1683 DEALLOCATE (pbd_buf)
1684 DEALLOCATE (pbc_buf)
1685 DEALLOCATE (pad_buf)
1686 DEALLOCATE (pac_buf)
1687
1688 IF (with_resp_density) THEN
1689 DEALLOCATE (pbd_buf_resp)
1690 DEALLOCATE (pbc_buf_resp)
1691 DEALLOCATE (pad_buf_resp)
1692 DEALLOCATE (pac_buf_resp)
1693 END IF
1694
1695 DO i = 1, max_pgf**2
1696 DEALLOCATE (pgf_list_ij(i)%image_list)
1697 DEALLOCATE (pgf_list_kl(i)%image_list)
1698 END DO
1699
1700 DEALLOCATE (pgf_list_ij)
1701 DEALLOCATE (pgf_list_kl)
1702
1703 DEALLOCATE (set_list_ij, set_list_kl)
1704
1705 DEALLOCATE (primitive_forces_virial)
1706
1707 DEALLOCATE (ede_work, ede_work2, ede_work_forces, ede_buffer1, ede_buffer2, ede_primitives_tmp)
1708
1709 DEALLOCATE (ede_work_virial, ede_work2_virial, ede_primitives_tmp_virial)
1710
1711 DEALLOCATE (nimages)
1712
1713 IF (my_nspins == 2) THEN
1714 DEALLOCATE (pbd_buf_beta, pbc_buf_beta, pad_buf_beta, pac_buf_beta)
1715 IF (with_resp_density) THEN
1716 DEALLOCATE (pbd_buf_resp_beta)
1717 DEALLOCATE (pbc_buf_resp_beta)
1718 DEALLOCATE (pad_buf_resp_beta)
1719 DEALLOCATE (pac_buf_resp_beta)
1720 END IF
1721 END IF
1722
1723!$OMP END PARALLEL
1724
1725 CALL timestop(handle)
1726
1727 END SUBROUTINE derivatives_four_center
1728
1729! **************************************************************************************************
1730!> \brief Given a 2d index pair, this function returns a 1d index pair for
1731!> a symmetric upper triangle NxN matrix
1732!> The compiler should inline this function, therefore it appears in
1733!> several modules
1734!> \param i 2d index
1735!> \param j 2d index
1736!> \param N matrix size
1737!> \return ...
1738!> \par History
1739!> 03.2009 created [Manuel Guidon]
1740!> \author Manuel Guidon
1741! **************************************************************************************************
1742 PURE FUNCTION get_1d_idx(i, j, N)
1743 INTEGER, INTENT(IN) :: i, j
1744 INTEGER(int_8), INTENT(IN) :: n
1745 INTEGER(int_8) :: get_1d_idx
1746
1747 INTEGER(int_8) :: min_ij
1748
1749 min_ij = min(i, j)
1750 get_1d_idx = min_ij*n + max(i, j) - (min_ij - 1)*min_ij/2 - n
1751
1752 END FUNCTION get_1d_idx
1753
1754! **************************************************************************************************
1755!> \brief This routine prefetches density matrix elements, i.e. reshuffles the
1756!> data in a way that they can be accessed later on in a cache friendly
1757!> way
1758!> \param ma_max Size of matrix blocks
1759!> \param mb_max Size of matrix blocks
1760!> \param mc_max Size of matrix blocks
1761!> \param md_max Size of matrix blocks
1762!> \param density ...
1763!> \param pbd buffer that will contain P(b,d)
1764!> \param pbc buffer that will contain P(b,c)
1765!> \param pad buffer that will contain P(a,d)
1766!> \param pac buffer that will contain P(a,c)
1767!> \param iatom ...
1768!> \param jatom ...
1769!> \param katom ...
1770!> \param latom ...
1771!> \param iset ...
1772!> \param jset ...
1773!> \param kset ...
1774!> \param lset ...
1775!> \param offset_bd_set ...
1776!> \param offset_bc_set ...
1777!> \param offset_ad_set ...
1778!> \param offset_ac_set ...
1779!> \param atomic_offset_bd ...
1780!> \param atomic_offset_bc ...
1781!> \param atomic_offset_ad ...
1782!> \param atomic_offset_ac ...
1783!> \param anti_symmetric ...
1784!> \par History
1785!> 03.2009 created [Manuel Guidon]
1786!> \author Manuel Guidon
1787! **************************************************************************************************
1788 SUBROUTINE prefetch_density_matrix(ma_max, mb_max, mc_max, md_max, &
1789 density, pbd, pbc, pad, pac, &
1790 iatom, jatom, katom, latom, &
1791 iset, jset, kset, lset, offset_bd_set, offset_bc_set, &
1792 offset_ad_set, offset_ac_set, atomic_offset_bd, atomic_offset_bc, &
1793 atomic_offset_ad, atomic_offset_ac, anti_symmetric)
1794
1795 INTEGER, INTENT(IN) :: ma_max, mb_max, mc_max, md_max
1796 REAL(dp), DIMENSION(:), INTENT(IN) :: density
1797 REAL(dp), DIMENSION(*), INTENT(INOUT) :: pbd, pbc, pad, pac
1798 INTEGER, INTENT(IN) :: iatom, jatom, katom, latom, iset, jset, &
1799 kset, lset
1800 INTEGER, DIMENSION(:, :), POINTER :: offset_bd_set, offset_bc_set, &
1801 offset_ad_set, offset_ac_set
1802 INTEGER, INTENT(IN) :: atomic_offset_bd, atomic_offset_bc, &
1803 atomic_offset_ad, atomic_offset_ac
1804 LOGICAL :: anti_symmetric
1805
1806 INTEGER :: i, j, ma, mb, mc, md, offset_ac, &
1807 offset_ad, offset_bc, offset_bd
1808 REAL(dp) :: fac
1809
1810 fac = 1.0_dp
1811 IF (anti_symmetric) fac = -1.0_dp
1812 IF (jatom >= latom) THEN
1813 i = 1
1814 offset_bd = offset_bd_set(jset, lset) + atomic_offset_bd - 1
1815 j = offset_bd
1816 DO md = 1, md_max
1817 DO mb = 1, mb_max
1818 pbd(i) = density(j)*fac
1819 i = i + 1
1820 j = j + 1
1821 END DO
1822 END DO
1823 ELSE
1824 i = 1
1825 offset_bd = offset_bd_set(lset, jset) + atomic_offset_bd - 1
1826 DO md = 1, md_max
1827 j = offset_bd + md - 1
1828 DO mb = 1, mb_max
1829 pbd(i) = density(j)
1830 i = i + 1
1831 j = j + md_max
1832 END DO
1833 END DO
1834 END IF
1835 IF (jatom >= katom) THEN
1836 i = 1
1837 offset_bc = offset_bc_set(jset, kset) + atomic_offset_bc - 1
1838 j = offset_bc
1839 DO mc = 1, mc_max
1840 DO mb = 1, mb_max
1841 pbc(i) = density(j)*fac
1842 i = i + 1
1843 j = j + 1
1844 END DO
1845 END DO
1846 ELSE
1847 i = 1
1848 offset_bc = offset_bc_set(kset, jset) + atomic_offset_bc - 1
1849 DO mc = 1, mc_max
1850 j = offset_bc + mc - 1
1851 DO mb = 1, mb_max
1852 pbc(i) = density(j)
1853 i = i + 1
1854 j = j + mc_max
1855 END DO
1856 END DO
1857 END IF
1858 IF (iatom >= latom) THEN
1859 i = 1
1860 offset_ad = offset_ad_set(iset, lset) + atomic_offset_ad - 1
1861 j = offset_ad
1862 DO md = 1, md_max
1863 DO ma = 1, ma_max
1864 pad(i) = density(j)*fac
1865 i = i + 1
1866 j = j + 1
1867 END DO
1868 END DO
1869 ELSE
1870 i = 1
1871 offset_ad = offset_ad_set(lset, iset) + atomic_offset_ad - 1
1872 DO md = 1, md_max
1873 j = offset_ad + md - 1
1874 DO ma = 1, ma_max
1875 pad(i) = density(j)
1876 i = i + 1
1877 j = j + md_max
1878 END DO
1879 END DO
1880 END IF
1881 IF (iatom >= katom) THEN
1882 i = 1
1883 offset_ac = offset_ac_set(iset, kset) + atomic_offset_ac - 1
1884 j = offset_ac
1885 DO mc = 1, mc_max
1886 DO ma = 1, ma_max
1887 pac(i) = density(j)*fac
1888 i = i + 1
1889 j = j + 1
1890 END DO
1891 END DO
1892 ELSE
1893 i = 1
1894 offset_ac = offset_ac_set(kset, iset) + atomic_offset_ac - 1
1895 DO mc = 1, mc_max
1896 j = offset_ac + mc - 1
1897 DO ma = 1, ma_max
1898 pac(i) = density(j)
1899 i = i + 1
1900 j = j + mc_max
1901 END DO
1902 END DO
1903 END IF
1904 END SUBROUTINE prefetch_density_matrix
1905
1906! **************************************************************************************************
1907!> \brief This routine updates the forces using buffered density matrices
1908!> \param ma_max Size of matrix blocks
1909!> \param mb_max Size of matrix blocks
1910!> \param mc_max Size of matrix blocks
1911!> \param md_max Size of matrix blocks
1912!> \param pbd buffer that will contain P(b,d)
1913!> \param pbc buffer that will contain P(b,c)
1914!> \param pad buffer that will contain P(a,d)
1915!> \param pac buffer that will contain P(a,c)
1916!> \param fac mulitplication factor (spin, symmetry)
1917!> \param prim primitive forces
1918!> \param force storage loacation for forces
1919!> \param forces_map index table
1920!> \param coord which of the 12 coords to be updated
1921!> \param pbd_resp ...
1922!> \param pbc_resp ...
1923!> \param pad_resp ...
1924!> \param pac_resp ...
1925!> \param resp_only ...
1926!> \par History
1927!> 03.2009 created [Manuel Guidon]
1928!> \author Manuel Guidon
1929! **************************************************************************************************
1930 SUBROUTINE update_forces(ma_max, mb_max, mc_max, md_max, &
1931 pbd, pbc, pad, pac, fac, &
1932 prim, force, forces_map, coord, &
1933 pbd_resp, pbc_resp, pad_resp, pac_resp, resp_only)
1934
1935 INTEGER, INTENT(IN) :: ma_max, mb_max, mc_max, md_max
1936 REAL(dp), DIMENSION(*), INTENT(IN) :: pbd, pbc, pad, pac
1937 REAL(dp), INTENT(IN) :: fac
1938 REAL(dp), DIMENSION(ma_max*mb_max*mc_max*md_max), &
1939 INTENT(IN) :: prim
1940 TYPE(qs_force_type), DIMENSION(:), POINTER :: force
1941 INTEGER, INTENT(IN) :: forces_map(4, 2), coord
1942 REAL(dp), DIMENSION(*), INTENT(IN), OPTIONAL :: pbd_resp, pbc_resp, pad_resp, pac_resp
1943 LOGICAL, INTENT(IN), OPTIONAL :: resp_only
1944
1945 INTEGER :: ma, mb, mc, md, p_index
1946 LOGICAL :: full_force, with_resp_density
1947 REAL(dp) :: temp1, temp1_resp, temp3, temp3_resp, &
1948 temp4, teresp
1949
1950 with_resp_density = .false.
1951 IF (PRESENT(pbd_resp) .AND. &
1952 PRESENT(pbc_resp) .AND. &
1953 PRESENT(pad_resp) .AND. &
1954 PRESENT(pac_resp)) with_resp_density = .true.
1955
1956 IF (with_resp_density) THEN
1957 full_force = .true.
1958 IF (PRESENT(resp_only)) full_force = .NOT. resp_only
1959 p_index = 0
1960 temp4 = 0.0_dp
1961 DO md = 1, md_max
1962 DO mc = 1, mc_max
1963 DO mb = 1, mb_max
1964 temp1 = pbc((mc - 1)*mb_max + mb)*fac
1965 temp3 = pbd((md - 1)*mb_max + mb)*fac
1966 temp1_resp = pbc_resp((mc - 1)*mb_max + mb)*fac
1967 temp3_resp = pbd_resp((md - 1)*mb_max + mb)*fac
1968 DO ma = 1, ma_max
1969 p_index = p_index + 1
1970 ! HF-SCF
1971 IF (full_force) THEN
1972 teresp = temp1*pad((md - 1)*ma_max + ma) + &
1973 temp3*pac((mc - 1)*ma_max + ma)
1974 ELSE
1975 teresp = 0.0_dp
1976 END IF
1977 ! RESP+HF
1978 teresp = teresp + &
1979 pac((mc - 1)*ma_max + ma)*temp3_resp + &
1980 pac_resp((mc - 1)*ma_max + ma)*temp3 + &
1981 pad((md - 1)*ma_max + ma)*temp1_resp + &
1982 pad_resp((md - 1)*ma_max + ma)*temp1
1983 temp4 = temp4 + teresp*prim(p_index)
1984 END DO !ma
1985 END DO !mb
1986 END DO !mc
1987 END DO !md
1988 ELSE
1989 p_index = 0
1990 temp4 = 0.0_dp
1991 DO md = 1, md_max
1992 DO mc = 1, mc_max
1993 DO mb = 1, mb_max
1994 temp1 = pbc((mc - 1)*mb_max + mb)*fac
1995 temp3 = pbd((md - 1)*mb_max + mb)*fac
1996 DO ma = 1, ma_max
1997 p_index = p_index + 1
1998 teresp = temp1*pad((md - 1)*ma_max + ma) + &
1999 temp3*pac((mc - 1)*ma_max + ma)
2000 temp4 = temp4 + teresp*prim(p_index)
2001 END DO !ma
2002 END DO !mb
2003 END DO !mc
2004 END DO !md
2005 END IF
2006
2007!$OMP ATOMIC
2008 force(forces_map((coord - 1)/3 + 1, 1))%fock_4c(mod(coord - 1, 3) + 1, &
2009 forces_map((coord - 1)/3 + 1, 2)) = &
2010 force(forces_map((coord - 1)/3 + 1, 1))%fock_4c(mod(coord - 1, 3) + 1, &
2011 forces_map((coord - 1)/3 + 1, 2)) - &
2012 temp4
2013
2014 END SUBROUTINE update_forces
2015
2016! **************************************************************************************************
2017!> \brief This routine updates the virial using buffered density matrices
2018!> \param ma_max Size of matrix blocks
2019!> \param mb_max Size of matrix blocks
2020!> \param mc_max Size of matrix blocks
2021!> \param md_max Size of matrix blocks
2022!> \param pbd buffer that will contain P(b,d)
2023!> \param pbc buffer that will contain P(b,c)
2024!> \param pad buffer that will contain P(a,d)
2025!> \param pac buffer that will contain P(a,c)
2026!> \param fac mulitplication factor (spin, symmetry)
2027!> \param prim primitive forces
2028!> \param tmp_virial ...
2029!> \param coord which of the 12 coords to be updated
2030!> \param l ...
2031!> \param pbd_resp ...
2032!> \param pbc_resp ...
2033!> \param pad_resp ...
2034!> \param pac_resp ...
2035!> \par History
2036!> 03.2009 created [Manuel Guidon]
2037!> \author Manuel Guidon
2038! **************************************************************************************************
2039 SUBROUTINE update_virial(ma_max, mb_max, mc_max, md_max, &
2040 pbd, pbc, pad, pac, fac, &
2041 prim, tmp_virial, coord, l, &
2042 pbd_resp, pbc_resp, pad_resp, pac_resp, resp_only)
2043
2044 INTEGER, INTENT(IN) :: ma_max, mb_max, mc_max, md_max
2045 REAL(dp), DIMENSION(*), INTENT(IN) :: pbd, pbc, pad, pac
2046 REAL(dp), INTENT(IN) :: fac
2047 REAL(dp), DIMENSION(ma_max*mb_max*mc_max*md_max), &
2048 INTENT(IN) :: prim
2049 REAL(dp) :: tmp_virial(3, 3)
2050 INTEGER, INTENT(IN) :: coord, l
2051 REAL(dp), DIMENSION(*), INTENT(IN), OPTIONAL :: pbd_resp, pbc_resp, pad_resp, pac_resp
2052 LOGICAL, INTENT(IN), OPTIONAL :: resp_only
2053
2054 INTEGER :: i, j, ma, mb, mc, md, p_index
2055 LOGICAL :: with_resp_density, full_force
2056 REAL(dp) :: temp1, temp1_resp, temp3, temp3_resp, &
2057 temp4, teresp
2058
2059 with_resp_density = .false.
2060 IF (PRESENT(pbd_resp) .AND. &
2061 PRESENT(pbc_resp) .AND. &
2062 PRESENT(pad_resp) .AND. &
2063 PRESENT(pac_resp)) with_resp_density = .true.
2064
2065 IF (with_resp_density) THEN
2066 full_force = .true.
2067 IF (PRESENT(resp_only)) full_force = .NOT. resp_only
2068 p_index = 0
2069 temp4 = 0.0_dp
2070 DO md = 1, md_max
2071 DO mc = 1, mc_max
2072 DO mb = 1, mb_max
2073 temp1 = pbc((mc - 1)*mb_max + mb)*fac
2074 temp3 = pbd((md - 1)*mb_max + mb)*fac
2075 temp1_resp = pbc_resp((mc - 1)*mb_max + mb)*fac
2076 temp3_resp = pbd_resp((md - 1)*mb_max + mb)*fac
2077 DO ma = 1, ma_max
2078 p_index = p_index + 1
2079 ! HF-SCF
2080 IF (full_force) THEN
2081 teresp = temp1*pad((md - 1)*ma_max + ma) + &
2082 temp3*pac((mc - 1)*ma_max + ma)
2083 ELSE
2084 teresp = 0.0_dp
2085 END IF
2086 ! RESP+HF
2087 teresp = teresp + &
2088 pac((mc - 1)*ma_max + ma)*temp3_resp + &
2089 pac_resp((mc - 1)*ma_max + ma)*temp3 + &
2090 pad((md - 1)*ma_max + ma)*temp1_resp + &
2091 pad_resp((md - 1)*ma_max + ma)*temp1
2092 temp4 = temp4 + teresp*prim(p_index)
2093 END DO !ma
2094 END DO !mb
2095 END DO !mc
2096 END DO !md
2097 ELSE
2098 p_index = 0
2099 temp4 = 0.0_dp
2100 DO md = 1, md_max
2101 DO mc = 1, mc_max
2102 DO mb = 1, mb_max
2103 temp1 = pbc((mc - 1)*mb_max + mb)*fac
2104 temp3 = pbd((md - 1)*mb_max + mb)*fac
2105 DO ma = 1, ma_max
2106 p_index = p_index + 1
2107 teresp = temp1*pad((md - 1)*ma_max + ma) + &
2108 temp3*pac((mc - 1)*ma_max + ma)
2109 temp4 = temp4 + teresp*prim(p_index)
2110 END DO !ma
2111 END DO !mb
2112 END DO !mc
2113 END DO !md
2114 END IF
2115
2116 j = l
2117 i = mod(coord - 1, 3) + 1
2118 tmp_virial(i, j) = tmp_virial(i, j) - temp4
2119 END SUBROUTINE update_virial
2120
2121
2122! **************************************************************************************************
2123!> \brief This routine calculates the maximum density matrix element, when
2124!> screening on an initial density matrix is applied. Due to symmetry of
2125!> the ERI's, there are always 4 matrix elements to be considered.
2126!> CASE 0-15 belong to an energy calculation (linear screening)
2127!> CASE 16-31 belong to a force calculation (square screening)
2128!> \param ptr_p_1 Pointers to atomic density matrices
2129!> \param ptr_p_2 Pointers to atomic density matrices
2130!> \param ptr_p_3 Pointers to atomic density matrices
2131!> \param ptr_p_4 Pointers to atomic density matrices
2132!> \param iset Current set
2133!> \param jset Current set
2134!> \param kset Current set
2135!> \param lset Current set
2136!> \param pmax_val value to be calculated
2137!> \param swap_id Defines how the matrices are accessed
2138!> \par History
2139!> 06.2009 created [Manuel Guidon]
2140!> \author Manuel Guidon
2141! **************************************************************************************************
2142PURE SUBROUTINE get_pmax_val(ptr_p_1, ptr_p_2, ptr_p_3, ptr_p_4, iset, jset, kset, lset, pmax_val, swap_id)
2143
2144 REAL(dp), DIMENSION(:, :), POINTER :: ptr_p_1, ptr_p_2, ptr_p_3, ptr_p_4
2145 INTEGER, INTENT(IN) :: iset, jset, kset, lset
2146
2147 REAL(dp), INTENT(OUT) :: pmax_val
2148 INTEGER, INTENT(IN) :: swap_id
2149
2150 REAL(dp) :: pmax_1, pmax_2, pmax_3, pmax_4
2151
2152 SELECT CASE (swap_id)
2153 CASE (0)
2154 pmax_1 = ptr_p_1(kset, iset)
2155 pmax_2 = ptr_p_2(lset, jset)
2156 pmax_3 = ptr_p_3(lset, iset)
2157 pmax_4 = ptr_p_4(kset, jset)
2158 pmax_val = max(pmax_1, pmax_2, pmax_3, pmax_4)
2159 CASE (1)
2160 pmax_1 = ptr_p_1(iset, kset)
2161 pmax_2 = ptr_p_2(lset, jset)
2162 pmax_3 = ptr_p_3(lset, iset)
2163 pmax_4 = ptr_p_4(kset, jset)
2164 pmax_val = max(pmax_1, pmax_2, pmax_3, pmax_4)
2165 CASE (2)
2166 pmax_1 = ptr_p_1(kset, iset)
2167 pmax_2 = ptr_p_2(jset, lset)
2168 pmax_3 = ptr_p_3(lset, iset)
2169 pmax_4 = ptr_p_4(kset, jset)
2170 pmax_val = max(pmax_1, pmax_2, pmax_3, pmax_4)
2171 CASE (3)
2172 pmax_1 = ptr_p_1(iset, kset)
2173 pmax_2 = ptr_p_2(jset, lset)
2174 pmax_3 = ptr_p_3(lset, iset)
2175 pmax_4 = ptr_p_4(kset, jset)
2176 pmax_val = max(pmax_1, pmax_2, pmax_3, pmax_4)
2177 CASE (4)
2178 pmax_1 = ptr_p_1(kset, iset)
2179 pmax_2 = ptr_p_2(lset, jset)
2180 pmax_3 = ptr_p_3(iset, lset)
2181 pmax_4 = ptr_p_4(kset, jset)
2182 pmax_val = max(pmax_1, pmax_2, pmax_3, pmax_4)
2183 CASE (5)
2184 pmax_1 = ptr_p_1(iset, kset)
2185 pmax_2 = ptr_p_2(lset, jset)
2186 pmax_3 = ptr_p_3(iset, lset)
2187 pmax_4 = ptr_p_4(kset, jset)
2188 pmax_val = max(pmax_1, pmax_2, pmax_3, pmax_4)
2189 CASE (6)
2190 pmax_1 = ptr_p_1(kset, iset)
2191 pmax_2 = ptr_p_2(jset, lset)
2192 pmax_3 = ptr_p_3(iset, lset)
2193 pmax_4 = ptr_p_4(kset, jset)
2194 pmax_val = max(pmax_1, pmax_2, pmax_3, pmax_4)
2195 CASE (7)
2196 pmax_1 = ptr_p_1(iset, kset)
2197 pmax_2 = ptr_p_2(jset, lset)
2198 pmax_3 = ptr_p_3(iset, lset)
2199 pmax_4 = ptr_p_4(kset, jset)
2200 pmax_val = max(pmax_1, pmax_2, pmax_3, pmax_4)
2201 CASE (8)
2202 pmax_1 = ptr_p_1(kset, iset)
2203 pmax_2 = ptr_p_2(lset, jset)
2204 pmax_3 = ptr_p_3(lset, iset)
2205 pmax_4 = ptr_p_4(jset, kset)
2206 pmax_val = max(pmax_1, pmax_2, pmax_3, pmax_4)
2207 CASE (9)
2208 pmax_1 = ptr_p_1(iset, kset)
2209 pmax_2 = ptr_p_2(lset, jset)
2210 pmax_3 = ptr_p_3(lset, iset)
2211 pmax_4 = ptr_p_4(jset, kset)
2212 pmax_val = max(pmax_1, pmax_2, pmax_3, pmax_4)
2213 CASE (10)
2214 pmax_1 = ptr_p_1(kset, iset)
2215 pmax_2 = ptr_p_2(jset, lset)
2216 pmax_3 = ptr_p_3(lset, iset)
2217 pmax_4 = ptr_p_4(jset, kset)
2218 pmax_val = max(pmax_1, pmax_2, pmax_3, pmax_4)
2219 CASE (11)
2220 pmax_1 = ptr_p_1(iset, kset)
2221 pmax_2 = ptr_p_2(jset, lset)
2222 pmax_3 = ptr_p_3(lset, iset)
2223 pmax_4 = ptr_p_4(jset, kset)
2224 pmax_val = max(pmax_1, pmax_2, pmax_3, pmax_4)
2225 CASE (12)
2226 pmax_1 = ptr_p_1(kset, iset)
2227 pmax_2 = ptr_p_2(lset, jset)
2228 pmax_3 = ptr_p_3(iset, lset)
2229 pmax_4 = ptr_p_4(jset, kset)
2230 pmax_val = max(pmax_1, pmax_2, pmax_3, pmax_4)
2231 CASE (13)
2232 pmax_1 = ptr_p_1(iset, kset)
2233 pmax_2 = ptr_p_2(lset, jset)
2234 pmax_3 = ptr_p_3(iset, lset)
2235 pmax_4 = ptr_p_4(jset, kset)
2236 pmax_val = max(pmax_1, pmax_2, pmax_3, pmax_4)
2237 CASE (14)
2238 pmax_1 = ptr_p_1(kset, iset)
2239 pmax_2 = ptr_p_2(jset, lset)
2240 pmax_3 = ptr_p_3(iset, lset)
2241 pmax_4 = ptr_p_4(jset, kset)
2242 pmax_val = max(pmax_1, pmax_2, pmax_3, pmax_4)
2243 CASE (15)
2244 pmax_1 = ptr_p_1(iset, kset)
2245 pmax_2 = ptr_p_2(jset, lset)
2246 pmax_3 = ptr_p_3(iset, lset)
2247 pmax_4 = ptr_p_4(jset, kset)
2248 pmax_val = max(pmax_1, pmax_2, pmax_3, pmax_4)
2249 CASE (16)
2250 pmax_1 = ptr_p_1(kset, iset)
2251 pmax_2 = ptr_p_2(lset, jset)
2252 pmax_3 = ptr_p_3(lset, iset)
2253 pmax_4 = ptr_p_4(kset, jset)
2254 pmax_val = max(pmax_1 + pmax_2, pmax_3 + pmax_4)
2255 CASE (17)
2256 pmax_1 = ptr_p_1(iset, kset)
2257 pmax_2 = ptr_p_2(lset, jset)
2258 pmax_3 = ptr_p_3(lset, iset)
2259 pmax_4 = ptr_p_4(kset, jset)
2260 pmax_val = max(pmax_1 + pmax_2, pmax_3 + pmax_4)
2261 CASE (18)
2262 pmax_1 = ptr_p_1(kset, iset)
2263 pmax_2 = ptr_p_2(jset, lset)
2264 pmax_3 = ptr_p_3(lset, iset)
2265 pmax_4 = ptr_p_4(kset, jset)
2266 pmax_val = max(pmax_1 + pmax_2, pmax_3 + pmax_4)
2267 CASE (19)
2268 pmax_1 = ptr_p_1(iset, kset)
2269 pmax_2 = ptr_p_2(jset, lset)
2270 pmax_3 = ptr_p_3(lset, iset)
2271 pmax_4 = ptr_p_4(kset, jset)
2272 pmax_val = max(pmax_1 + pmax_2, pmax_3 + pmax_4)
2273 CASE (20)
2274 pmax_1 = ptr_p_1(kset, iset)
2275 pmax_2 = ptr_p_2(lset, jset)
2276 pmax_3 = ptr_p_3(iset, lset)
2277 pmax_4 = ptr_p_4(kset, jset)
2278 pmax_val = max(pmax_1 + pmax_2, pmax_3 + pmax_4)
2279 CASE (21)
2280 pmax_1 = ptr_p_1(iset, kset)
2281 pmax_2 = ptr_p_2(lset, jset)
2282 pmax_3 = ptr_p_3(iset, lset)
2283 pmax_4 = ptr_p_4(kset, jset)
2284 pmax_val = max(pmax_1 + pmax_2, pmax_3 + pmax_4)
2285 CASE (22)
2286 pmax_1 = ptr_p_1(kset, iset)
2287 pmax_2 = ptr_p_2(jset, lset)
2288 pmax_3 = ptr_p_3(iset, lset)
2289 pmax_4 = ptr_p_4(kset, jset)
2290 pmax_val = max(pmax_1 + pmax_2, pmax_3 + pmax_4)
2291 CASE (23)
2292 pmax_1 = ptr_p_1(iset, kset)
2293 pmax_2 = ptr_p_2(jset, lset)
2294 pmax_3 = ptr_p_3(iset, lset)
2295 pmax_4 = ptr_p_4(kset, jset)
2296 pmax_val = max(pmax_1 + pmax_2, pmax_3 + pmax_4)
2297 CASE (24)
2298 pmax_1 = ptr_p_1(kset, iset)
2299 pmax_2 = ptr_p_2(lset, jset)
2300 pmax_3 = ptr_p_3(lset, iset)
2301 pmax_4 = ptr_p_4(jset, kset)
2302 pmax_val = max(pmax_1 + pmax_2, pmax_3 + pmax_4)
2303 CASE (25)
2304 pmax_1 = ptr_p_1(iset, kset)
2305 pmax_2 = ptr_p_2(lset, jset)
2306 pmax_3 = ptr_p_3(lset, iset)
2307 pmax_4 = ptr_p_4(jset, kset)
2308 pmax_val = max(pmax_1 + pmax_2, pmax_3 + pmax_4)
2309 CASE (26)
2310 pmax_1 = ptr_p_1(kset, iset)
2311 pmax_2 = ptr_p_2(jset, lset)
2312 pmax_3 = ptr_p_3(lset, iset)
2313 pmax_4 = ptr_p_4(jset, kset)
2314 pmax_val = max(pmax_1 + pmax_2, pmax_3 + pmax_4)
2315 CASE (27)
2316 pmax_1 = ptr_p_1(iset, kset)
2317 pmax_2 = ptr_p_2(jset, lset)
2318 pmax_3 = ptr_p_3(lset, iset)
2319 pmax_4 = ptr_p_4(jset, kset)
2320 pmax_val = max(pmax_1 + pmax_2, pmax_3 + pmax_4)
2321 CASE (28)
2322 pmax_1 = ptr_p_1(kset, iset)
2323 pmax_2 = ptr_p_2(lset, jset)
2324 pmax_3 = ptr_p_3(iset, lset)
2325 pmax_4 = ptr_p_4(jset, kset)
2326 pmax_val = max(pmax_1 + pmax_2, pmax_3 + pmax_4)
2327 CASE (29)
2328 pmax_1 = ptr_p_1(iset, kset)
2329 pmax_2 = ptr_p_2(lset, jset)
2330 pmax_3 = ptr_p_3(iset, lset)
2331 pmax_4 = ptr_p_4(jset, kset)
2332 pmax_val = max(pmax_1 + pmax_2, pmax_3 + pmax_4)
2333 CASE (30)
2334 pmax_1 = ptr_p_1(kset, iset)
2335 pmax_2 = ptr_p_2(jset, lset)
2336 pmax_3 = ptr_p_3(iset, lset)
2337 pmax_4 = ptr_p_4(jset, kset)
2338 pmax_val = max(pmax_1 + pmax_2, pmax_3 + pmax_4)
2339 CASE (31)
2340 pmax_1 = ptr_p_1(iset, kset)
2341 pmax_2 = ptr_p_2(jset, lset)
2342 pmax_3 = ptr_p_3(iset, lset)
2343 pmax_4 = ptr_p_4(jset, kset)
2344 pmax_val = max(pmax_1 + pmax_2, pmax_3 + pmax_4)
2345 END SELECT
2346
2347END SUBROUTINE get_pmax_val
2348
2349
2350END MODULE hfx_derivatives
static GRID_HOST_DEVICE int modulo(int a, int m)
Equivalent of Fortran's MODULO, which always return a positive number. https://gcc....
Types and set/get functions for auxiliary density matrix methods.
Definition admm_types.F:15
Define the atomic kind types and their sub types.
subroutine, public get_atomic_kind_set(atomic_kind_set, atom_of_kind, kind_of, natom_of_kind, maxatom, natom, nshell, fist_potential_present, shell_present, shell_adiabatic, shell_check_distance, damping_present)
Get attributes of an atomic kind set.
Handles all functions related to the CELL.
Definition cell_types.F:15
Defines control structures, which contain the parameters and the settings for the DFT-based calculati...
character function, public dbcsr_get_matrix_type(matrix)
...
Utility routines to open and close files.
Definition cp_files.F:22
subroutine, public open_file(file_name, unit_number, file_status, file_form, file_action, file_position, file_pad, file_access, debug)
Opens a file and returns its logical unit number.
Definition cp_files.F:197
subroutine, public close_file(unit_number, file_status)
Closes an open file given by its logical unit number.
Definition cp_files.F:64
various routines to log and control the output. The idea is that decisions about where to log should ...
type(cp_logger_type) function, pointer, public cp_get_default_logger()
returns the default logger
routines to handle the output, The idea is to remove the decision of wheter to output and what to out...
subroutine, public cp_print_key_finished_output(unit_nr, logger, basis_section, print_key_path, local, ignore_should_output, on_file, mpi_io)
should be called after you finish working with a unit obtained with cp_print_key_unit_nr,...
integer, parameter, public cp_p_file
integer function, public cp_print_key_should_output(iteration_info, basis_section, print_key_path, used_print_key, first_time)
returns what should be done with the given property if btest(res,cp_p_store) then the property should...
integer function, public cp_print_key_unit_nr(logger, basis_section, print_key_path, extension, middle_name, local, log_filename, ignore_should_output, file_form, file_position, file_action, file_status, do_backup, on_file, is_new_file, mpi_io, fout, file_access)
...
Prepare and evaluate screened four-center Gaussian integrals and derivatives.
subroutine, public forces4(context, ra, rb, rc, rd, npgfa, npgfb, npgfc, npgfd, la_min, la_max, lb_min, lb_max, lc_min, lc_max, ld_min, ld_max, nsgfa, nsgfb, nsgfc, nsgfd, sphi_a_u1, sphi_a_u2, sphi_a_u3, sphi_b_u1, sphi_b_u2, sphi_b_u3, sphi_c_u1, sphi_c_u2, sphi_c_u3, sphi_d_u1, sphi_d_u2, sphi_d_u3, zeta, zetb, zetc, zetd, primitive_integrals, potential_parameter, neighbor_cells, screen1, screen2, eps_schwarz, max_contraction_val, cart_estimate, cell, neris_tmp, log10_pmax, log10_eps_schwarz, r1_pgf, r2_pgf, pgf1, pgf2, pgf_list_ij, pgf_list_kl, nsgfl_a, nsgfl_b, nsgfl_c, nsgfl_d, sphi_a_ext, sphi_b_ext, sphi_c_ext, sphi_d_ext, ede_work, ede_work2, ede_work_forces, ede_buffer1, ede_buffer2, ede_primitives_tmp, nimages, do_periodic, use_virial, ede_work_virial, ede_work2_virial, ede_primitives_tmp_virial, primitive_integrals_virial, cart_estimate_virial)
...
Routines for data exchange between MPI processes.
subroutine, public get_full_density(para_env, full_density, rho, number_of_p_entries, block_offset, kind_of, basis_parameter, get_max_vals_spin, rho_beta, antisymmetric)
Collects full density matrix from all CPUs
routines and types for Hartree-Fock-Exchange
subroutine, public hfx_add_single_cache_element(value, nbits, cache, container, memory_usage, use_disk_storage, max_val_memory)
This routine adds an int_8 value to a cache. If the cache is full a compression routine is invoked an...
subroutine, public hfx_get_mult_cache_elements(values, nints, nbits, cache, container, eps_schwarz, pmax_entry, memory_usage, use_disk_storage)
This routine returns a bunch real values from a cache. If the cache is empty a decompression routine ...
subroutine, public hfx_flush_last_cache(nbits, cache, container, memory_usage, use_disk_storage)
This routine compresses the last probably not yet compressed cache into a container
subroutine, public hfx_get_single_cache_element(value, nbits, cache, container, memory_usage, use_disk_storage)
This routine returns an int_8 value from a cache. If the cache is empty a decompression routine is in...
subroutine, public hfx_decompress_first_cache(nbits, cache, container, memory_usage, use_disk_storage)
This routine decompresses the first bunch of data in a container and copies them into a cache
subroutine, public hfx_add_mult_cache_elements(values, nints, nbits, cache, container, eps_schwarz, pmax_entry, memory_usage, use_disk_storage)
This routine adds an a few real values to a cache. If the cache is full a compression routine is invo...
subroutine, public hfx_reset_cache_and_container(cache, container, memory_usage, do_disk_storage)
This routine resets the containers list pointer to the first element and moves the element counters o...
Routines to calculate derivatives with respect to basis function origin.
subroutine, public derivatives_four_center(qs_env, rho_ao, rho_ao_resp, hfx_section, para_env, irep, use_virial, adiabatic_rescale_factor, resp_only, external_x_data, nspins)
computes four center derivatives for a full basis set and updates the forcesfock_4c arrays....
Routines for optimizing load balance between processes in HFX calculations.
subroutine, public collect_load_balance_info(para_env, x_data, iw, n_threads, i_thread, eval_type)
...
subroutine, public hfx_load_balance(x_data, eps_schwarz, particle_set, max_set, para_env, coeffs_set, coeffs_kind, is_assoc_atomic_block_global, do_periodic, load_balance_parameter, kind_of, basis_parameter, pmax_set, pmax_atom, i_thread, n_threads, cell, do_p_screening, map_atom_to_kind_atom, nkind, eval_type, pmax_block, use_virial)
Distributes the computation of eri's to all available processes.
subroutine, public hfx_update_load_balance(x_data, para_env, load_balance_parameter, i_thread, n_threads, eval_type)
Cheap way of redistributing the eri's.
Routines for optimizing load balance between processes in HFX calculations.
subroutine, public build_atomic_pair_list(natom, atomic_pair_list, kind_of, basis_parameter, particle_set, do_periodic, coeffs_kind, coeffs_kind_max0, log10_eps_schwarz, cell, blocks)
...
subroutine, public build_pair_list(natom, list, set_list, i_start, i_end, j_start, j_end, kind_of, basis_parameter, particle_set, do_periodic, coeffs_set, coeffs_kind, coeffs_kind_max0, log10_eps_schwarz, cell, pmax_blocks, atomic_pair_list)
...
Several screening methods used in HFX calcualtions.
subroutine, public update_pmax_mat(pmax_set, map_atom_to_kind_atom, set_offset, atomic_block_offset, pmax_atom, full_density_alpha, full_density_beta, natom, kind_of, basis_parameter, nkind, is_assoc_atomic_block, nspins)
updates the maximum of the density matrix in compressed form for screening purposes
Types and set/get functions for HFX.
Definition hfx_types.F:16
subroutine, public hfx_init_container(container, memory_usage, do_disk_storage)
This routine deletes all list entries in a container in order to deallocate the memory.
Definition hfx_types.F:2543
real(dp), parameter, public log_zero
Definition hfx_types.F:123
subroutine, public alloc_containers(data, bin_size)
...
Definition hfx_types.F:2935
subroutine, public dealloc_containers(data, memory_usage)
...
Definition hfx_types.F:2902
collects all constants needed in input so that they can be used without circular dependencies
integer, parameter, public hfx_do_eval_forces
integer, parameter, public do_potential_truncated
integer, parameter, public do_potential_mix_cl_trunc
objects that represent the structure of input sections and the data contained in an input section
Defines the basic variable types.
Definition kinds.F:23
integer, parameter, public int_8
Definition kinds.F:54
integer, parameter, public dp
Definition kinds.F:34
Machine interface based on Fortran 2003 and POSIX.
Definition machine.F:17
real(kind=dp) function, public m_walltime()
returns time from a real-time clock, protected against rolling early/easily
Definition machine.F:144
Definition of mathematical constants and functions.
real(kind=dp), dimension(0:maxfac), parameter, public fac
Interface to the message passing library MPI.
Provides Cartesian and spherical orbital pointers and indices.
integer, dimension(:), allocatable, public nco
integer, dimension(:), allocatable, public ncoset
integer, dimension(:), allocatable, public nso
Define the data structure for the particle information.
subroutine, public get_qs_env(qs_env, atomic_kind_set, qs_kind_set, cell, super_cell, cell_ref, use_ref_cell, kpoints, dft_control, mos, sab_orb, sab_all, qmmm, qmmm_periodic, mimic, sac_ae, sac_ppl, sac_lri, sap_ppnl, sab_vdw, sab_scp, sap_oce, sab_lrc, sab_se, sab_xtbe, sab_tbe, sab_core, sab_xb, sab_xtb_pp, sab_xtb_nonbond, sab_almo, sab_kp, sab_kp_nosym, sab_cneo, particle_set, energy, force, matrix_h, matrix_h_im, matrix_ks, matrix_ks_im, matrix_vxc, run_rtp, rtp, matrix_h_kp, matrix_h_im_kp, matrix_ks_kp, matrix_ks_im_kp, matrix_vxc_kp, kinetic_kp, matrix_s_kp, matrix_w_kp, matrix_s_ri_aux_kp, matrix_s, matrix_s_ri_aux, matrix_w, matrix_p_mp2, matrix_p_mp2_admm, 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.
Radial fundamentals for Gaussian two-electron integrals. Entry m+1 stores order m....
subroutine, public r12_fundamentals_init(m_max, potential_parameter, para_env)
Prepare shared radial evaluator tables before entering a threaded evaluation region.
All kind of helpful little routines.
Definition util.F:14
stores some data used in wavefunction fitting
Definition admm_types.F:120
Provides all information about an atomic kind.
Type defining parameters related to the simulation cell.
Definition cell_types.F:60
type of a logger, at the moment it contains just a print level starting at which level it should be l...
stores some data used in construction of Kohn-Sham matrix
Definition hfx_types.F:474
stores all the informations relevant to an mpi environment