LCOV - code coverage report
Current view: top level - src - gw_integrals.F (source / functions) Hit Total Coverage
Test: CP2K Regtests (git:2fce0f8) Lines: 188 191 98.4 %
Date: 2024-12-21 06:28:57 Functions: 1 1 100.0 %

          Line data    Source code
       1             : !--------------------------------------------------------------------------------------------------!
       2             : !   CP2K: A general program to perform molecular dynamics simulations                              !
       3             : !   Copyright 2000-2024 CP2K developers group <https://cp2k.org>                                   !
       4             : !                                                                                                  !
       5             : !   SPDX-License-Identifier: GPL-2.0-or-later                                                      !
       6             : !--------------------------------------------------------------------------------------------------!
       7             : 
       8             : ! **************************************************************************************************
       9             : !> \brief Utility method to build 3-center integrals for small cell GW
      10             : ! **************************************************************************************************
      11             : MODULE gw_integrals
      12             :    USE OMP_LIB,                         ONLY: omp_get_thread_num
      13             :    USE ai_contraction_sphi,             ONLY: abc_contract_xsmm
      14             :    USE atomic_kind_types,               ONLY: atomic_kind_type,&
      15             :                                               get_atomic_kind_set
      16             :    USE basis_set_types,                 ONLY: get_gto_basis_set,&
      17             :                                               gto_basis_set_p_type,&
      18             :                                               gto_basis_set_type
      19             :    USE cell_types,                      ONLY: cell_type,&
      20             :                                               get_cell,&
      21             :                                               pbc
      22             :    USE cp_array_utils,                  ONLY: cp_2d_r_p_type
      23             :    USE cp_control_types,                ONLY: dft_control_type
      24             :    USE cp_files,                        ONLY: close_file,&
      25             :                                               open_file
      26             :    USE gamma,                           ONLY: init_md_ftable
      27             :    USE input_constants,                 ONLY: do_potential_coulomb,&
      28             :                                               do_potential_id,&
      29             :                                               do_potential_short,&
      30             :                                               do_potential_truncated
      31             :    USE kinds,                           ONLY: dp
      32             :    USE libint_2c_3c,                    ONLY: cutoff_screen_factor,&
      33             :                                               eri_3center,&
      34             :                                               libint_potential_type
      35             :    USE libint_wrapper,                  ONLY: cp_libint_cleanup_3eri,&
      36             :                                               cp_libint_init_3eri,&
      37             :                                               cp_libint_set_contrdepth,&
      38             :                                               cp_libint_t
      39             :    USE message_passing,                 ONLY: mp_para_env_type
      40             :    USE orbital_pointers,                ONLY: ncoset
      41             :    USE particle_types,                  ONLY: particle_type
      42             :    USE qs_environment_types,            ONLY: get_qs_env,&
      43             :                                               qs_environment_type
      44             :    USE qs_kind_types,                   ONLY: qs_kind_type
      45             :    USE t_c_g0,                          ONLY: get_lmax_init,&
      46             :                                               init
      47             : 
      48             : !$ USE OMP_LIB, ONLY: omp_get_max_threads, omp_get_thread_num
      49             : #include "./base/base_uses.f90"
      50             : 
      51             :    IMPLICIT NONE
      52             : 
      53             :    PRIVATE
      54             : 
      55             :    CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'gw_integrals'
      56             : 
      57             :    PUBLIC :: build_3c_integral_block
      58             : 
      59             : CONTAINS
      60             : 
      61             : ! **************************************************************************************************
      62             : !> \brief ...
      63             : !> \param int_3c ...
      64             : !> \param qs_env ...
      65             : !> \param potential_parameter ...
      66             : !> \param basis_j ...
      67             : !> \param basis_k ...
      68             : !> \param basis_i ...
      69             : !> \param cell_j ...
      70             : !> \param cell_k ...
      71             : !> \param cell_i ...
      72             : !> \param atom_j ...
      73             : !> \param atom_k ...
      74             : !> \param atom_i ...
      75             : !> \param j_bf_start_from_atom ...
      76             : !> \param k_bf_start_from_atom ...
      77             : !> \param i_bf_start_from_atom ...
      78             : ! **************************************************************************************************
      79       71829 :    SUBROUTINE build_3c_integral_block(int_3c, qs_env, potential_parameter, &
      80       23943 :                                       basis_j, basis_k, basis_i, &
      81             :                                       cell_j, cell_k, cell_i, atom_j, atom_k, atom_i, &
      82       23943 :                                       j_bf_start_from_atom, k_bf_start_from_atom, &
      83       23943 :                                       i_bf_start_from_atom)
      84             : 
      85             :       REAL(KIND=dp), DIMENSION(:, :, :)                  :: int_3c
      86             :       TYPE(qs_environment_type), POINTER                 :: qs_env
      87             :       TYPE(libint_potential_type), INTENT(IN)            :: potential_parameter
      88             :       TYPE(gto_basis_set_p_type), DIMENSION(:)           :: basis_j, basis_k, basis_i
      89             :       INTEGER, DIMENSION(3), INTENT(IN), OPTIONAL        :: cell_j, cell_k, cell_i
      90             :       INTEGER, INTENT(IN), OPTIONAL                      :: atom_j, atom_k, atom_i
      91             :       INTEGER, DIMENSION(:), OPTIONAL                    :: j_bf_start_from_atom, &
      92             :                                                             k_bf_start_from_atom, &
      93             :                                                             i_bf_start_from_atom
      94             : 
      95             :       CHARACTER(LEN=*), PARAMETER :: routineN = 'build_3c_integral_block'
      96             : 
      97             :       INTEGER :: at_i, at_j, at_k, block_end_i, block_end_j, block_end_k, block_start_i, &
      98             :          block_start_j, block_start_k, egfi, handle, i, i_offset, ibasis, ikind, ilist, imax, is, &
      99             :          iset, j_offset, jkind, js, jset, k_offset, kkind, ks, kset, m_max, max_ncoi, max_ncoj, &
     100             :          max_ncok, max_nset, max_nsgfi, max_nsgfj, max_nsgfk, maxli, maxlj, maxlk, natom, nbasis, &
     101             :          ncoi, ncoj, ncok, nseti, nsetj, nsetk, op_ij, op_jk, sgfi, sgfj, sgfk, unit_id
     102       23943 :       INTEGER, ALLOCATABLE, DIMENSION(:)                 :: kind_of
     103             :       INTEGER, DIMENSION(3)                              :: my_cell_i, my_cell_j, my_cell_k
     104       23943 :       INTEGER, DIMENSION(:), POINTER                     :: lmax_i, lmax_j, lmax_k, lmin_i, lmin_j, &
     105       23943 :                                                             lmin_k, npgfi, npgfj, npgfk, nsgfi, &
     106       23943 :                                                             nsgfj, nsgfk
     107       23943 :       INTEGER, DIMENSION(:, :), POINTER                  :: first_sgf_i, first_sgf_j, first_sgf_k
     108             :       REAL(KIND=dp)                                      :: dij, dik, djk, dr_ij, dr_ik, dr_jk, &
     109             :                                                             kind_radius_i, kind_radius_j, &
     110             :                                                             kind_radius_k, sijk_ext
     111       23943 :       REAL(KIND=dp), ALLOCATABLE, DIMENSION(:)           :: ccp_buffer, cpp_buffer, &
     112       23943 :                                                             max_contraction_i, max_contraction_j, &
     113       23943 :                                                             max_contraction_k
     114       23943 :       REAL(KIND=dp), ALLOCATABLE, DIMENSION(:, :, :)     :: sijk, sijk_contr
     115             :       REAL(KIND=dp), DIMENSION(3)                        :: ri, rij, rik, rj, rjk, rk
     116             :       REAL(KIND=dp), DIMENSION(3, 3)                     :: hmat
     117       23943 :       REAL(KIND=dp), DIMENSION(:), POINTER               :: set_radius_i, set_radius_j, set_radius_k
     118       23943 :       REAL(KIND=dp), DIMENSION(:, :), POINTER            :: rpgf_i, rpgf_j, rpgf_k, sphi_i, sphi_j, &
     119       23943 :                                                             sphi_k, zeti, zetj, zetk
     120       23943 :       TYPE(atomic_kind_type), DIMENSION(:), POINTER      :: atomic_kind_set
     121             :       TYPE(cell_type), POINTER                           :: cell
     122       23943 :       TYPE(cp_2d_r_p_type), DIMENSION(:, :), POINTER     :: spi, spk, tspj
     123             :       TYPE(cp_libint_t)                                  :: lib
     124             :       TYPE(dft_control_type), POINTER                    :: dft_control
     125             :       TYPE(gto_basis_set_type), POINTER                  :: basis_set
     126             :       TYPE(mp_para_env_type), POINTER                    :: para_env
     127       23943 :       TYPE(particle_type), DIMENSION(:), POINTER         :: particle_set
     128       23943 :       TYPE(qs_kind_type), DIMENSION(:), POINTER          :: qs_kind_set
     129             : 
     130       23943 :       CALL timeset(routineN, handle)
     131             : 
     132       23943 :       op_ij = potential_parameter%potential_type
     133       23943 :       op_jk = do_potential_id
     134             : 
     135       23943 :       dr_ij = 0.0_dp; dr_jk = 0.0_dp; dr_ik = 0.0_dp
     136             : 
     137       23943 :       IF (op_ij == do_potential_truncated .OR. op_ij == do_potential_short) THEN
     138       23943 :          dr_ij = potential_parameter%cutoff_radius*cutoff_screen_factor
     139       23943 :          dr_ik = potential_parameter%cutoff_radius*cutoff_screen_factor
     140           0 :       ELSEIF (op_ij == do_potential_coulomb) THEN
     141           0 :          dr_ij = 1000000.0_dp
     142           0 :          dr_ik = 1000000.0_dp
     143             :       END IF
     144             : 
     145       23943 :       NULLIFY (qs_kind_set, atomic_kind_set)
     146             : 
     147             :       ! get stuff
     148             :       CALL get_qs_env(qs_env, atomic_kind_set=atomic_kind_set, qs_kind_set=qs_kind_set, cell=cell, &
     149             :                       natom=natom, dft_control=dft_control, para_env=para_env, &
     150       23943 :                       particle_set=particle_set)
     151       23943 :       CALL get_atomic_kind_set(atomic_kind_set=atomic_kind_set, kind_of=kind_of)
     152       23943 :       CALL get_cell(cell=cell, h=hmat)
     153             : 
     154             :       !Need the max l for each basis for libint and max nset, nco and nsgf for LIBXSMM contraction
     155       23943 :       nbasis = SIZE(basis_i)
     156       23943 :       max_nsgfi = 0
     157       23943 :       max_ncoi = 0
     158       23943 :       max_nset = 0
     159       23943 :       maxli = 0
     160       71817 :       DO ibasis = 1, nbasis
     161             :          CALL get_gto_basis_set(gto_basis_set=basis_i(ibasis)%gto_basis_set, maxl=imax, &
     162       47874 :                                 nset=iset, nsgf_set=nsgfi, npgf=npgfi)
     163       47874 :          maxli = MAX(maxli, imax)
     164       47874 :          max_nset = MAX(max_nset, iset)
     165      119727 :          max_nsgfi = MAX(max_nsgfi, MAXVAL(nsgfi))
     166      191544 :          max_ncoi = MAX(max_ncoi, MAXVAL(npgfi)*ncoset(maxli))
     167             :       END DO
     168             :       max_nsgfj = 0
     169             :       max_ncoj = 0
     170             :       maxlj = 0
     171       71817 :       DO ibasis = 1, nbasis
     172             :          CALL get_gto_basis_set(gto_basis_set=basis_j(ibasis)%gto_basis_set, maxl=imax, &
     173       47874 :                                 nset=jset, nsgf_set=nsgfj, npgf=npgfj)
     174       47874 :          maxlj = MAX(maxlj, imax)
     175       47874 :          max_nset = MAX(max_nset, jset)
     176      143610 :          max_nsgfj = MAX(max_nsgfj, MAXVAL(nsgfj))
     177      215427 :          max_ncoj = MAX(max_ncoj, MAXVAL(npgfj)*ncoset(maxlj))
     178             :       END DO
     179             :       max_nsgfk = 0
     180             :       max_ncok = 0
     181             :       maxlk = 0
     182       71817 :       DO ibasis = 1, nbasis
     183             :          CALL get_gto_basis_set(gto_basis_set=basis_k(ibasis)%gto_basis_set, maxl=imax, &
     184       47874 :                                 nset=kset, nsgf_set=nsgfk, npgf=npgfk)
     185       47874 :          maxlk = MAX(maxlk, imax)
     186       47874 :          max_nset = MAX(max_nset, kset)
     187      143610 :          max_nsgfk = MAX(max_nsgfk, MAXVAL(nsgfk))
     188      215427 :          max_ncok = MAX(max_ncok, MAXVAL(npgfk)*ncoset(maxlk))
     189             :       END DO
     190       23943 :       m_max = maxli + maxlj + maxlk
     191             : 
     192             :       !To minimize expensive memory opsand generally optimize contraction, pre-allocate
     193             :       !contiguous sphi arrays (and transposed in the cas of sphi_i)
     194             : 
     195       23943 :       NULLIFY (tspj, spi, spk)
     196      766104 :       ALLOCATE (spi(max_nset, nbasis), tspj(max_nset, nbasis), spk(max_nset, nbasis))
     197             : 
     198       71817 :       DO ibasis = 1, nbasis
     199      215463 :          DO iset = 1, max_nset
     200      143646 :             NULLIFY (spi(iset, ibasis)%array)
     201      143646 :             NULLIFY (tspj(iset, ibasis)%array)
     202             : 
     203      191520 :             NULLIFY (spk(iset, ibasis)%array)
     204             :          END DO
     205             :       END DO
     206             : 
     207       95772 :       DO ilist = 1, 3
     208      239394 :          DO ibasis = 1, nbasis
     209      143622 :             IF (ilist == 1) basis_set => basis_i(ibasis)%gto_basis_set
     210      143622 :             IF (ilist == 2) basis_set => basis_j(ibasis)%gto_basis_set
     211      143622 :             IF (ilist == 3) basis_set => basis_k(ibasis)%gto_basis_set
     212             : 
     213      478776 :             DO iset = 1, basis_set%nset
     214             : 
     215      263325 :                ncoi = basis_set%npgf(iset)*ncoset(basis_set%lmax(iset))
     216      263325 :                sgfi = basis_set%first_sgf(1, iset)
     217      263325 :                egfi = sgfi + basis_set%nsgf_set(iset) - 1
     218             : 
     219      406947 :                IF (ilist == 1) THEN
     220      287412 :                   ALLOCATE (spi(iset, ibasis)%array(ncoi, basis_set%nsgf_set(iset)))
     221      982407 :                   spi(iset, ibasis)%array(:, :) = basis_set%sphi(1:ncoi, sgfi:egfi)
     222             : 
     223      191472 :                ELSE IF (ilist == 2) THEN
     224      382944 :                   ALLOCATE (tspj(iset, ibasis)%array(basis_set%nsgf_set(iset), ncoi))
     225     6030960 :                   tspj(iset, ibasis)%array(:, :) = TRANSPOSE(basis_set%sphi(1:ncoi, sgfi:egfi))
     226             : 
     227             :                ELSE
     228      382944 :                   ALLOCATE (spk(iset, ibasis)%array(ncoi, basis_set%nsgf_set(iset)))
     229     5121438 :                   spk(iset, ibasis)%array(:, :) = basis_set%sphi(1:ncoi, sgfi:egfi)
     230             :                END IF
     231             : 
     232             :             END DO !iset
     233             :          END DO !ibasis
     234             :       END DO !ilist
     235             : 
     236             :       !Init the truncated Coulomb operator
     237       23943 :       IF (op_ij == do_potential_truncated .OR. op_jk == do_potential_truncated) THEN
     238             : 
     239       23943 :          IF (m_max > get_lmax_init()) THEN
     240           6 :             IF (para_env%mepos == 0) THEN
     241           3 :                CALL open_file(unit_number=unit_id, file_name=potential_parameter%filename)
     242             :             END IF
     243           6 :             CALL init(m_max, unit_id, para_env%mepos, para_env)
     244           6 :             IF (para_env%mepos == 0) THEN
     245           3 :                CALL close_file(unit_id)
     246             :             END IF
     247             :          END IF
     248             :       END IF
     249             : 
     250       23943 :       CALL init_md_ftable(nmax=m_max)
     251             : 
     252       23943 :       CALL cp_libint_init_3eri(lib, MAX(maxli, maxlj, maxlk))
     253       23943 :       CALL cp_libint_set_contrdepth(lib, 1)
     254             : 
     255             :       !pre-allocate contraction buffers
     256      119715 :       ALLOCATE (cpp_buffer(max_nsgfj*max_ncok), ccp_buffer(max_nsgfj*max_nsgfk*max_ncoi))
     257     1406271 :       int_3c(:, :, :) = 0.0_dp
     258             : 
     259             :       ! loop over all RI atoms
     260       88704 :       DO at_i = 1, natom
     261             : 
     262             :          ! loop over all AO atoms
     263      268851 :          DO at_j = 1, natom
     264             : 
     265             :             ! loop over all AO atoms
     266      757077 :             DO at_k = 1, natom
     267             : 
     268      512169 :                IF (PRESENT(atom_i)) THEN
     269      512073 :                   IF (at_i .NE. atom_i) CYCLE
     270             :                END IF
     271      180195 :                IF (PRESENT(atom_j)) THEN
     272      180099 :                   IF (at_j .NE. atom_j) CYCLE
     273             :                END IF
     274       64833 :                IF (PRESENT(atom_k)) THEN
     275       64737 :                   IF (at_k .NE. atom_k) CYCLE
     276             :                END IF
     277             : 
     278       24027 :                my_cell_i(1:3) = 0
     279       24027 :                IF (PRESENT(cell_i)) my_cell_i(1:3) = cell_i(1:3)
     280       24027 :                my_cell_j(1:3) = 0
     281       24027 :                IF (PRESENT(cell_j)) my_cell_j(1:3) = cell_j(1:3)
     282       24027 :                my_cell_k(1:3) = 0
     283       24027 :                IF (PRESENT(cell_k)) my_cell_k(1:3) = cell_k(1:3)
     284             : 
     285      480540 :                ri = pbc(particle_set(at_i)%r(1:3), cell) + MATMUL(hmat, REAL(my_cell_i, dp))
     286      480540 :                rj = pbc(particle_set(at_j)%r(1:3), cell) + MATMUL(hmat, REAL(my_cell_j, dp))
     287      480540 :                rk = pbc(particle_set(at_k)%r(1:3), cell) + MATMUL(hmat, REAL(my_cell_k, dp))
     288             : 
     289       96108 :                rjk(1:3) = rk(1:3) - rj(1:3)
     290       96108 :                rij(1:3) = rj(1:3) - ri(1:3)
     291       96108 :                rik(1:3) = rk(1:3) - ri(1:3)
     292             : 
     293       96108 :                djk = NORM2(rjk)
     294       96108 :                dij = NORM2(rij)
     295       96108 :                dik = NORM2(rik)
     296             : 
     297       24027 :                ikind = kind_of(at_i)
     298       24027 :                jkind = kind_of(at_j)
     299       24027 :                kkind = kind_of(at_k)
     300             : 
     301             :                CALL get_gto_basis_set(basis_i(ikind)%gto_basis_set, first_sgf=first_sgf_i, &
     302             :                                       lmax=lmax_i, lmin=lmin_i, npgf=npgfi, nset=nseti, &
     303             :                                       nsgf_set=nsgfi, pgf_radius=rpgf_i, set_radius=set_radius_i, &
     304       24027 :                                       sphi=sphi_i, zet=zeti, kind_radius=kind_radius_i)
     305             : 
     306             :                CALL get_gto_basis_set(basis_j(jkind)%gto_basis_set, first_sgf=first_sgf_j, &
     307             :                                       lmax=lmax_j, lmin=lmin_j, npgf=npgfj, nset=nsetj, &
     308             :                                       nsgf_set=nsgfj, pgf_radius=rpgf_j, set_radius=set_radius_j, &
     309       24027 :                                       sphi=sphi_j, zet=zetj, kind_radius=kind_radius_j)
     310             : 
     311             :                CALL get_gto_basis_set(basis_k(kkind)%gto_basis_set, first_sgf=first_sgf_k, &
     312             :                                       lmax=lmax_k, lmin=lmin_k, npgf=npgfk, nset=nsetk, &
     313             :                                       nsgf_set=nsgfk, pgf_radius=rpgf_k, set_radius=set_radius_k, &
     314       24027 :                                       sphi=sphi_k, zet=zetk, kind_radius=kind_radius_k)
     315             : 
     316       24027 :                IF (kind_radius_j + kind_radius_i + dr_ij < dij) CYCLE
     317       12465 :                IF (kind_radius_j + kind_radius_k + dr_jk < djk) CYCLE
     318        6835 :                IF (kind_radius_k + kind_radius_i + dr_ik < dik) CYCLE
     319             : 
     320       14433 :                ALLOCATE (max_contraction_i(nseti))
     321       11855 :                max_contraction_i = 0.0_dp
     322       11855 :                DO iset = 1, nseti
     323        7044 :                   sgfi = first_sgf_i(1, iset)
     324             :                   max_contraction_i(iset) = MAXVAL((/(SUM(ABS(sphi_i(:, i))), i=sgfi, &
     325       78209 :                                                       sgfi + nsgfi(iset) - 1)/))
     326             :                END DO
     327             : 
     328       14433 :                ALLOCATE (max_contraction_j(nsetj))
     329       14518 :                max_contraction_j = 0.0_dp
     330       14518 :                DO jset = 1, nsetj
     331        9707 :                   sgfj = first_sgf_j(1, jset)
     332             :                   max_contraction_j(jset) = MAXVAL((/(SUM(ABS(sphi_j(:, i))), i=sgfj, &
     333      298025 :                                                       sgfj + nsgfj(jset) - 1)/))
     334             :                END DO
     335             : 
     336       14433 :                ALLOCATE (max_contraction_k(nsetk))
     337       14518 :                max_contraction_k = 0.0_dp
     338       14518 :                DO kset = 1, nsetk
     339        9707 :                   sgfk = first_sgf_k(1, kset)
     340             :                   max_contraction_k(kset) = MAXVAL((/(SUM(ABS(sphi_k(:, i))), i=sgfk, &
     341      298025 :                                                       sgfk + nsgfk(kset) - 1)/))
     342             :                END DO
     343             : 
     344       11855 :                DO iset = 1, nseti
     345             : 
     346       25715 :                   DO jset = 1, nsetj
     347             : 
     348       13860 :                      IF (set_radius_j(jset) + set_radius_i(iset) + dr_ij < dij) CYCLE
     349             : 
     350       41124 :                      DO kset = 1, nsetk
     351             : 
     352       22752 :                         IF (set_radius_j(jset) + set_radius_k(kset) + dr_jk < djk) CYCLE
     353       17426 :                         IF (set_radius_k(kset) + set_radius_i(iset) + dr_ik < dik) CYCLE
     354             : 
     355       15112 :                         ncoi = npgfi(iset)*ncoset(lmax_i(iset))
     356       15112 :                         ncoj = npgfj(jset)*ncoset(lmax_j(jset))
     357       15112 :                         ncok = npgfk(kset)*ncoset(lmax_k(kset))
     358             : 
     359       15112 :                         sgfi = first_sgf_i(1, iset)
     360       15112 :                         sgfj = first_sgf_j(1, jset)
     361       15112 :                         sgfk = first_sgf_k(1, kset)
     362             : 
     363       15112 :                         IF (ncoj*ncok*ncoi .LE. 0) CYCLE
     364       75560 :                         ALLOCATE (sijk(ncoj, ncok, ncoi))
     365     2036647 :                         sijk(:, :, :) = 0.0_dp
     366             : 
     367       15112 :                         is = iset
     368       15112 :                         js = jset
     369       15112 :                         ks = kset
     370             : 
     371             :                         CALL eri_3center(sijk, &
     372             :                                          lmin_j(js), lmax_j(js), npgfj(js), zetj(:, js), &
     373             :                                          rpgf_j(:, js), rj, &
     374             :                                          lmin_k(ks), lmax_k(ks), npgfk(ks), zetk(:, ks), &
     375             :                                          rpgf_k(:, ks), rk, &
     376             :                                          lmin_i(is), lmax_i(is), npgfi(is), zeti(:, is), &
     377             :                                          rpgf_i(:, is), ri, &
     378             :                                          djk, dij, dik, lib, potential_parameter, &
     379       15112 :                                          int_abc_ext=sijk_ext)
     380             : 
     381       75560 :                         ALLOCATE (sijk_contr(nsgfj(jset), nsgfk(kset), nsgfi(iset)))
     382             :                         CALL abc_contract_xsmm(sijk_contr, sijk, tspj(jset, jkind)%array, &
     383             :                                                spk(kset, kkind)%array, spi(iset, ikind)%array, &
     384             :                                                ncoj, ncok, ncoi, nsgfj(jset), nsgfk(kset), &
     385       15112 :                                                nsgfi(iset), cpp_buffer, ccp_buffer)
     386       15112 :                         DEALLOCATE (sijk)
     387             : 
     388       15112 :                         IF (PRESENT(atom_j)) THEN
     389             :                            j_offset = 0
     390             :                         ELSE
     391         480 :                            CPASSERT(PRESENT(j_bf_start_from_atom))
     392         480 :                            j_offset = j_bf_start_from_atom(at_j) - 1
     393             :                         END IF
     394       15112 :                         IF (PRESENT(atom_k)) THEN
     395             :                            k_offset = 0
     396             :                         ELSE
     397         480 :                            CPASSERT(PRESENT(k_bf_start_from_atom))
     398         480 :                            k_offset = k_bf_start_from_atom(at_k) - 1
     399             :                         END IF
     400       15112 :                         IF (PRESENT(atom_i)) THEN
     401             :                            i_offset = 0
     402             :                         ELSE
     403         480 :                            CPASSERT(PRESENT(i_bf_start_from_atom))
     404         480 :                            i_offset = i_bf_start_from_atom(at_i) - 1
     405             :                         END IF
     406             : 
     407       15112 :                         block_start_j = sgfj + j_offset
     408       15112 :                         block_end_j = sgfj + nsgfj(jset) - 1 + j_offset
     409       15112 :                         block_start_k = sgfk + k_offset
     410       15112 :                         block_end_k = sgfk + nsgfk(kset) - 1 + k_offset
     411       15112 :                         block_start_i = sgfi + i_offset
     412       15112 :                         block_end_i = sgfi + nsgfi(iset) - 1 + i_offset
     413             : 
     414             :                         int_3c(block_start_j:block_end_j, &
     415             :                                block_start_k:block_end_k, &
     416             :                                block_start_i:block_end_i) = &
     417             :                            int_3c(block_start_j:block_end_j, &
     418             :                                   block_start_k:block_end_k, &
     419             :                                   block_start_i:block_end_i) + &
     420      207772 :                            sijk_contr(:, :, :)
     421       36612 :                         DEALLOCATE (sijk_contr)
     422             : 
     423             :                      END DO
     424             : 
     425             :                   END DO
     426             : 
     427             :                END DO
     428             : 
     429      208985 :                DEALLOCATE (max_contraction_i, max_contraction_j, max_contraction_k)
     430             : 
     431             :             END DO ! atom_k (AO)
     432             :          END DO ! atom_j (AO)
     433             :       END DO ! atom_i (RI)
     434             : 
     435       23943 :       CALL cp_libint_cleanup_3eri(lib)
     436             : 
     437       95796 :       DO iset = 1, max_nset
     438      239442 :          DO ibasis = 1, nbasis
     439      143646 :             IF (ASSOCIATED(spi(iset, ibasis)%array)) DEALLOCATE (spi(iset, ibasis)%array)
     440      143646 :             IF (ASSOCIATED(tspj(iset, ibasis)%array)) DEALLOCATE (tspj(iset, ibasis)%array)
     441             : 
     442      215499 :             IF (ASSOCIATED(spk(iset, ibasis)%array)) DEALLOCATE (spk(iset, ibasis)%array)
     443             :          END DO
     444             :       END DO
     445       23943 :       DEALLOCATE (spi, tspj, spk)
     446             : 
     447       23943 :       CALL timestop(handle)
     448             : 
     449       47886 :    END SUBROUTINE build_3c_integral_block
     450             : 
     451             : END MODULE
     452             : 

Generated by: LCOV version 1.15