110 irep, use_virial, adiabatic_rescale_factor, resp_only, &
111 external_x_data, nspins)
115 TYPE(
dbcsr_p_type),
DIMENSION(:),
POINTER :: rho_ao_resp
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
125 CHARACTER(LEN=*),
PARAMETER :: routinen =
'derivatives_four_center'
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, &
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, &
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, &
181 REAL(kind=
dp) :: coeffs_kind_max0
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
209 TYPE(
hfx_type),
POINTER :: actual_x_data
210 TYPE(
hfx_type),
DIMENSION(:, :),
POINTER :: my_x_data
213 DIMENSION(:) :: set_list_ij, set_list_kl
218 NULLIFY (dft_control, admm_env)
220 with_resp_density = .false.
221 IF (
ASSOCIATED(rho_ao_resp)) with_resp_density = .true.
223 my_resp_only = .false.
224 IF (
PRESENT(resp_only)) my_resp_only = resp_only
230 particle_set=particle_set, &
231 atomic_kind_set=atomic_kind_set, &
233 dft_control=dft_control)
235 IF (
PRESENT(nspins))
THEN
238 my_nspins = dft_control%nspins
240 nkimages = dft_control%nimages
241 cpassert(nkimages == 1)
243 my_x_data => qs_env%x_data
244 IF (
PRESENT(external_x_data)) my_x_data => external_x_data
247 IF (
SIZE(particle_set, 1) == 1)
THEN
248 IF (.NOT. use_virial)
RETURN
251 CALL timeset(routinen, handle)
253 nkind =
SIZE(atomic_kind_set, 1)
256 l_max = max(l_max, maxval(my_x_data(1, 1)%basis_parameter(ikind)%lmax))
266 shm_neris_onthefly = 0
267 shm_storage_counter_integrals = 0
269 shm_stor_count_max_val = 0
272 CALL get_qs_env(qs_env=qs_env, force=force, virial=virial)
274 my_adiabatic_rescale_factor = 1.0_dp
275 IF (
PRESENT(adiabatic_rescale_factor))
THEN
276 my_adiabatic_rescale_factor = adiabatic_rescale_factor
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
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
375 load_balance_parameter => actual_x_data%load_balance_parameter
376 basis_parameter => actual_x_data%basis_parameter
386 memory_parameter => actual_x_data%memory_parameter
388 cache_size = memory_parameter%cache_size
389 bits_max_val = memory_parameter%bits_max_val
391 use_disk_storage = .false.
394 atomic_kind_set=atomic_kind_set, &
395 particle_set=particle_set)
397 max_set = basis_info%max_set
398 max_am = basis_info%max_am
399 natom =
SIZE(particle_set, 1)
401 treat_forces_in_core = memory_parameter%treat_forces_in_core
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
410 IF (use_virial) eps_schwarz = eps_schwarz/actual_x_data%periodic_parameter%R_max_stress
411 log10_eps_schwarz = log10(eps_schwarz)
413 screen_pmat_forces = screening_parameter%do_p_screening_forces
415 IF (with_resp_density) screen_pmat_forces = .false.
417 eps_storage = eps_schwarz*memory_parameter%eps_storage_scaling
424 atom_of_kind=atom_of_kind, &
428 ALLOCATE (last_sgf_global(0:natom))
429 last_sgf_global(0) = 0
431 ikind = kind_of(iatom)
432 last_sgf_global(iatom) = last_sgf_global(iatom - 1) + basis_parameter(ikind)%nsgf_total
435 ALLOCATE (max_contraction(max_set, natom))
437 max_contraction = 0.0_dp
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
449 ncob = npgfb(jset)*
ncoset(lb_max(jset))
450 sgfb = first_sgfb(1, jset)
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))
458 ncpu = para_env%num_pe
459 n_processes = ncpu*n_threads
462 neris_total = 0_int_8
463 neris_incore = 0_int_8
464 neris_onthefly = 0_int_8
466 mem_max_val = 0_int_8
467 compression_factor = 0.0_dp
470 max_val_memory = 1_int_8
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
480 NULLIFY (full_density_alpha)
481 NULLIFY (full_density_beta)
482 ALLOCATE (full_density_alpha(shm_block_offset(ncpu + 1), nkimages))
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, &
488 kind_of, basis_parameter, get_max_vals_spin=.false., &
489 antisymmetric=is_anti_symmetric)
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, &
496 kind_of, basis_parameter, get_max_vals_spin=.false., &
497 antisymmetric=is_anti_symmetric)
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, &
504 kind_of, basis_parameter, get_max_vals_spin=.false., &
505 antisymmetric=is_anti_symmetric)
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, &
512 kind_of, basis_parameter, get_max_vals_spin=.false., &
513 antisymmetric=is_anti_symmetric)
517 CALL timestop(handle_getp)
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
527 actual_x_data%map_atom_to_kind_atom, &
528 actual_x_data%set_offset, &
529 actual_x_data%atomic_block_offset, &
531 full_density_alpha, full_density_beta, &
532 natom, kind_of, basis_parameter, &
533 nkind, actual_x_data%is_assoc_atomic_block, my_nspins)
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
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
558 CALL timeset(routinen//
"_load", handle_load)
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, &
570 actual_x_data%b_first_load_balance_forces = .false.
573 load_balance_parameter, &
578 CALL timestop(handle_load)
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
591 ncos_max = max(ncos_max,
ncoset(la_max(iset)))
592 nsgf_max = max(nsgf_max, nsgfa(iset))
597 ALLOCATE (primitive_forces(12*nsgf_max**4))
598 primitive_forces = 0.0_dp
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))
607 ALLOCATE (pgf_list_ij(i)%image_list(nneighbors))
608 ALLOCATE (pgf_list_kl(i)%image_list(nneighbors))
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))
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))
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))
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))
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))
699 CALL timeset(routinen//
"_main", handle_main)
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))
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)
714 IF (treat_forces_in_core)
THEN
715 buffer_overflow = .false.
717 buffer_overflow = .true.
720 do_dynamic_load_balancing = .true.
721 IF (n_threads == 1) do_dynamic_load_balancing = .false.
723 IF (do_dynamic_load_balancing)
THEN
724 my_bin_size =
SIZE(actual_x_data%distribution_forces)
729 IF (treat_forces_in_core)
THEN
731 IF (actual_x_data%memory_parameter%recalc_forces)
THEN
732 CALL dealloc_containers(actual_x_data%store_forces, memory_parameter%actual_memory_usage)
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.)
740 CALL hfx_init_container(integral_containers(i), memory_parameter%actual_memory_usage, .false.)
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)
753 memory_parameter%actual_memory_usage, .false.)
756 memory_parameter%actual_memory_usage, .false.)
764 IF (do_dynamic_load_balancing)
THEN
768 shm_total_bins = shm_total_bins +
SIZE(my_x_data(irep, i)%distribution_forces)
770 ALLOCATE (tmp_task_list(shm_total_bins))
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
782 ALLOCATE (tmp_task_list_cost(shm_total_bins))
783 ALLOCATE (tmp_index(shm_total_bins))
785 DO i = 1, shm_total_bins
786 tmp_task_list_cost(i) = tmp_task_list(i)%cost
789 CALL sort(tmp_task_list_cost, shm_total_bins, tmp_index)
791 ALLOCATE (actual_x_data%task_list(shm_total_bins))
793 DO i = 1, shm_total_bins
794 actual_x_data%task_list(i) = tmp_task_list(tmp_index(shm_total_bins - i + 1))
797 shm_task_list => actual_x_data%task_list
800 DEALLOCATE (tmp_task_list_cost, tmp_index, tmp_task_list)
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))
817 shm_atomic_pair_list => actual_x_data%atomic_pair_list_forces
818 IF (actual_x_data%memory_parameter%recalc_forces)
THEN
820 do_periodic, screen_coeffs_kind, coeffs_kind_max0, log10_eps_schwarz, cell, &
821 actual_x_data%blocks)
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
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)
836 integral_containers => actual_x_data%store_forces%integral_containers(:, 1)
837 integral_caches => actual_x_data%store_forces%integral_caches(:, 1)
841 nblocks = load_balance_parameter%nblocks
847 IF (.NOT. do_dynamic_load_balancing)
THEN
849 IF (bin > my_bin_size)
THEN
855 distribution_forces => actual_x_data%distribution_forces(bin)
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)
869 distribution_forces => my_x_data(irep, my_thread_id)%distribution_forces(my_bin_id)
872 IF (actual_x_data%memory_parameter%recalc_forces)
THEN
873 distribution_forces%ram_counter = huge(distribution_forces%ram_counter)
883 IF (.NOT. do_it) cycle
885 CALL timeset(routinen//
"_bin", handle_bin)
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
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
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))
919 IF (2.0_dp*coeffs_kind_max0 + pmax_blocks < log10_eps_schwarz) cycle atomic_blocks
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)
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)
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
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)
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)
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
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)
981 IF (.NOT. (katom + latom <= iatom + jatom)) cycle
982 IF (((iatom + jatom) == (katom + latom)) .AND. (katom < iatom)) cycle
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
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))
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
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
1014 l_atom = atom_of_kind(latom)
1015 forces_map(4, 1) = lkind
1016 forces_map(4, 2) = l_atom
1018 IF (my_nspins == 1)
THEN
1019 fac = 0.25_dp*hf_fraction
1021 fac = 0.5_dp*hf_fraction
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
1032 symm_fac = 1.0_dp/symm_fac
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)
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)
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)
1062 IF (jatom < latom)
THEN
1063 offset_bd_set => shm_set_offset(:, :, lkind, jkind)
1065 offset_bd_set => shm_set_offset(:, :, jkind, lkind)
1067 IF (jatom < katom)
THEN
1068 offset_bc_set => shm_set_offset(:, :, kkind, jkind)
1070 offset_bc_set => shm_set_offset(:, :, jkind, kkind)
1072 IF (iatom < latom)
THEN
1073 offset_ad_set => shm_set_offset(:, :, lkind, ikind)
1075 offset_ad_set => shm_set_offset(:, :, ikind, lkind)
1077 IF (iatom < katom)
THEN
1078 offset_ac_set => shm_set_offset(:, :, kkind, ikind)
1080 offset_ac_set => shm_set_offset(:, :, ikind, kkind)
1083 IF (screen_pmat_forces)
THEN
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))
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
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))
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
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))
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
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))
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
1133 IF (actual_x_data%memory_parameter%recalc_forces)
THEN
1134 IF (treat_forces_in_core)
THEN
1141 mem_compression_counter = 0
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
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
1154 memory_parameter%ram_counter_forces = counter
1157 counter = counter + 1
1158 buffer_overflow = .false.
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.
1167 counter = counter + 1
1168 buffer_overflow = .false.
1171 IF (memory_parameter%ram_counter_forces == counter)
THEN
1172 buffer_overflow = .true.
1174 counter = counter + 1
1175 buffer_overflow = .false.
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)
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)
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
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)
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
1201 IF (max_val2 + pmax_atom < log10_eps_schwarz) cycle
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, &
1208 log10_pmax = log_2 + pmax_tmp
1213 max_val2 = max_val2 + log10_pmax
1214 IF (max_val2 < log10_eps_schwarz) cycle
1216 pmax_entry = exp(log10_pmax*ln_10)
1218 current_counter = nsgfa(iset)*nsgfb(jset)*nsgfc(kset)*nsgfd(lset)*12
1219 IF (buffer_overflow)
THEN
1220 neris_onthefly = neris_onthefly + current_counter
1224 IF (.NOT. buffer_overflow .AND. .NOT. actual_x_data%memory_parameter%recalc_forces)
THEN
1225 nints = current_counter
1227 maxval_cache, maxval_container, memory_parameter%actual_memory_usage, &
1229 spherical_estimate = set_exponent(1.0_dp, estimate_to_store_int + 1)
1231 IF (.NOT. use_virial)
THEN
1232 IF (spherical_estimate*pmax_entry < eps_schwarz) cycle
1234 nbits = exponent(anint(spherical_estimate*pmax_entry/eps_storage)) + 1
1237 neris_incore = neris_incore + int(nints,
int_8)
1238 DO WHILE (buffer_left > 0)
1239 buffer_size = min(buffer_left, cache_size)
1241 buffer_size, nbits, &
1242 integral_caches(nbits), &
1243 integral_containers(nbits), &
1244 eps_storage, pmax_entry, &
1245 memory_parameter%actual_memory_usage, &
1247 buffer_left = buffer_left - buffer_size
1248 buffer_start = buffer_start + buffer_size
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)* &
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)
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), &
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)
1295 nints = nsgfa(iset)*nsgfb(jset)*nsgfc(kset)*nsgfd(lset)*12
1296 neris_total = neris_total + nints
1297 nprim_ints = nprim_ints + neris_tmp
1316 spherical_estimate = 0.0_dp
1317 IF (cartesian_estimate /= 0.0_dp)
THEN
1319 spherical_estimate = max(spherical_estimate, abs(primitive_forces(i)))
1323 spherical_estimate_virial = 0.0_dp
1324 IF (use_virial .AND. cartesian_estimate_virial /= 0.0_dp)
THEN
1326 spherical_estimate_virial = max(spherical_estimate_virial, abs(primitive_forces_virial(i)))
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
1335 maxval_cache, maxval_container, &
1336 memory_parameter%actual_memory_usage, &
1337 use_disk_storage, max_val_memory)
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
1343 IF (.NOT. buffer_overflow)
THEN
1344 nbits = exponent(anint(spherical_estimate*pmax_entry/eps_storage)) + 1
1348 neris_incore = neris_incore + int(nints,
int_8)
1350 DO WHILE (buffer_left > 0)
1351 buffer_size = min(buffer_left, cache_size)
1353 buffer_size, nbits, &
1354 integral_caches(nbits), &
1355 integral_containers(nbits), &
1356 eps_storage, pmax_entry, &
1357 memory_parameter%actual_memory_usage, &
1359 buffer_left = buffer_left - buffer_size
1360 buffer_start = buffer_start + buffer_size
1365 IF (treat_forces_in_core .AND. cartesian_estimate /= 0.0_dp)
THEN
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
1371 primitive_forces(i) = 0.0_dp
1376 IF (cartesian_estimate == 0.0_dp .AND. &
1377 (.NOT. use_virial .OR. cartesian_estimate_virial == 0.0_dp)) cycle
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)
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)
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)
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)
1423 IF (spherical_estimate*pmax_entry >= eps_schwarz)
THEN
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))
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, &
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)
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, &
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)
1455 IF (use_virial .AND. spherical_estimate_virial*pmax_entry >= eps_schwarz)
THEN
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)
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)
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, &
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)
1494 END DO atomic_blocks
1496 distribution_forces%time_forces = bintime_stop - bintime_start
1498 CALL timestop(handle_bin)
1504 do_print_load_balance_info = .false.
1506 "LOAD_BALANCE%PRINT/LOAD_BALANCE_INFO"),
cp_p_file)
1509 IF (do_print_load_balance_info)
THEN
1513 extension=
".scfLog")
1521 "LOAD_BALANCE%PRINT/LOAD_BALANCE_INFO")
1525 IF (use_virial)
THEN
1530 virial%pv_fock_4c(i, j) = virial%pv_fock_4c(i, j) + tmp_virial(i, k)*cell%hmat(j, k)
1539 shm_neris_total = shm_neris_total + neris_total
1541 shm_neris_onthefly = shm_neris_onthefly + neris_onthefly
1543 shm_nprim_ints = shm_nprim_ints + nprim_ints
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
1549 shm_storage_counter_integrals = shm_storage_counter_integrals + storage_counter_integrals
1551 shm_neris_incore = shm_neris_incore + neris_incore
1553 shm_stor_count_max_val = shm_stor_count_max_val + stor_count_max_val
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
1578 IF (shm_neris_incore == 0)
THEN
1580 compression_factor = 0.0_dp
1586 extension=
".scfLog")
1588 WRITE (unit=iw, fmt=
"(/,(T3,A,T65,I16))") &
1589 "HFX_MEM_INFO| Number of cart. primitive DERIV's calculated: ", shm_nprim_ints
1591 WRITE (unit=iw, fmt=
"((T3,A,T60,I21))") &
1592 "HFX_MEM_INFO| Number of sph. DERIV's calculated: ", shm_neris_total
1594 WRITE (unit=iw, fmt=
"((T3,A,T60,I21))") &
1595 "HFX_MEM_INFO| Number of sph. DERIV's stored in-core: ", shm_neris_incore
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
1600 WRITE (unit=iw, fmt=
"((T3,A,T60,I21))") &
1601 "HFX_MEM_INFO| Total memory consumption DERIV's RAM [MiB]: ", mem_eris
1603 WRITE (unit=iw, fmt=
"((T3,A,T60,I21))") &
1604 "HFX_MEM_INFO| Whereof max-vals [MiB]: ", mem_max_val
1606 WRITE (unit=iw, fmt=
"((T3,A,T60,F21.2),/)") &
1607 "HFX_MEM_INFO| Total compression factor DERIV's RAM: ", compression_factor
1616 IF (do_dynamic_load_balancing)
THEN
1617 my_bin_size =
SIZE(actual_x_data%distribution_forces)
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, &
1633 memory_parameter%actual_memory_usage, .false.)
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)
1649 memory_parameter%actual_memory_usage, &
1655 IF (actual_x_data%memory_parameter%recalc_forces)
THEN
1656 actual_x_data%memory_parameter%recalc_forces = .false.
1661 CALL timestop(handle_main)
1664 DEALLOCATE (last_sgf_global)
1666 DEALLOCATE (full_density_alpha)
1667 IF (with_resp_density)
THEN
1668 DEALLOCATE (full_density_resp)
1670 IF (my_nspins == 2)
THEN
1671 DEALLOCATE (full_density_beta)
1672 IF (with_resp_density)
THEN
1673 DEALLOCATE (full_density_resp_beta)
1676 IF (do_dynamic_load_balancing)
THEN
1677 DEALLOCATE (actual_x_data%task_list)
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)
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)
1695 DO i = 1, max_pgf**2
1696 DEALLOCATE (pgf_list_ij(i)%image_list)
1697 DEALLOCATE (pgf_list_kl(i)%image_list)
1700 DEALLOCATE (pgf_list_ij)
1701 DEALLOCATE (pgf_list_kl)
1703 DEALLOCATE (set_list_ij, set_list_kl)
1705 DEALLOCATE (primitive_forces_virial)
1707 DEALLOCATE (ede_work, ede_work2, ede_work_forces, ede_buffer1, ede_buffer2, ede_primitives_tmp)
1709 DEALLOCATE (ede_work_virial, ede_work2_virial, ede_primitives_tmp_virial)
1711 DEALLOCATE (nimages)
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)
1725 CALL timestop(handle)