LCOV - code coverage report
Current view: top level - src - qs_tensors_types.F (source / functions) Coverage Total Hit
Test: CP2K Regtests (git:1be8651) Lines: 98.5 % 201 198
Test Date: 2026-11-24 01:22:08 Functions: 75.0 % 12 9

            Line data    Source code
       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 Utility methods to build 3-center integral tensors of various types.
      10              : ! **************************************************************************************************
      11              : 
      12              : MODULE qs_tensors_types
      13              :    USE atomic_kind_types,               ONLY: atomic_kind_type,&
      14              :                                               get_atomic_kind_set
      15              :    USE basis_set_types,                 ONLY: get_gto_basis_set,&
      16              :                                               gto_basis_set_p_type
      17              :    USE cp_array_utils,                  ONLY: cp_1d_i_p_type
      18              :    USE cp_blacs_env,                    ONLY: cp_blacs_env_create,&
      19              :                                               cp_blacs_env_release,&
      20              :                                               cp_blacs_env_type
      21              :    USE dbt_api,                         ONLY: dbt_create,&
      22              :                                               dbt_default_distvec,&
      23              :                                               dbt_distribution_destroy,&
      24              :                                               dbt_distribution_new,&
      25              :                                               dbt_distribution_type,&
      26              :                                               dbt_mp_environ_pgrid,&
      27              :                                               dbt_pgrid_type,&
      28              :                                               dbt_type
      29              :    USE distribution_2d_types,           ONLY: distribution_2d_create_prv => distribution_2d_create,&
      30              :                                               distribution_2d_release,&
      31              :                                               distribution_2d_type
      32              :    USE message_passing,                 ONLY: mp_cart_type,&
      33              :                                               mp_comm_type,&
      34              :                                               mp_para_env_release,&
      35              :                                               mp_para_env_type
      36              :    USE particle_types,                  ONLY: particle_type
      37              :    USE qs_neighbor_list_types,          ONLY: neighbor_list_iterator_p_type,&
      38              :                                               neighbor_list_set_p_type
      39              : #include "./base/base_uses.f90"
      40              : 
      41              :    IMPLICIT NONE
      42              : 
      43              :    PRIVATE
      44              : 
      45              :    CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'qs_tensors_types'
      46              : 
      47              :    PUBLIC :: distribution_3d_type, neighbor_list_3c_type, neighbor_list_3c_iterator_type, &
      48              :              distribution_2d_create, distribution_3d_create, distribution_3d_destroy, &
      49              :              split_block_sizes, create_3c_tensor, create_2c_tensor, contiguous_tensor_dist, pgf_block_sizes, &
      50              :              create_tensor_batches
      51              : 
      52              :    INTEGER, PARAMETER, PUBLIC :: symmetric_none = 0, symmetric_ij = 1, symmetric_jk = 2, symmetrik_ik = 3, symmetric_ijk = 4
      53              : 
      54              :    INTEGER, PARAMETER, PUBLIC :: default_block_size = 64
      55              :    !! default block size for dense tensors, this block size should be covered by DBCSR/libcusmm
      56              : 
      57              :    TYPE distribution_3d_type
      58              :       TYPE(distribution_2d_type), POINTER :: dist_2d_1 => NULL(), dist_2d_2 => NULL()
      59              :       TYPE(mp_comm_type) :: comm_3d = mp_comm_type(), comm_2d_1 = mp_comm_type(), comm_2d_2 = mp_comm_type()
      60              :       LOGICAL :: owns_comm = .FALSE.
      61              :    END TYPE distribution_3d_type
      62              : 
      63              :    TYPE neighbor_list_3c_type
      64              :       TYPE(neighbor_list_set_p_type), DIMENSION(:), POINTER :: ij_list => NULL(), jk_list => NULL()
      65              :       INTEGER :: sym = symmetric_none
      66              :       TYPE(distribution_3d_type) :: dist_3d = distribution_3d_type()
      67              :       LOGICAL :: owns_dist = .FALSE.
      68              :    END TYPE neighbor_list_3c_type
      69              : 
      70              :    TYPE neighbor_list_3c_iterator_type
      71              :       TYPE(neighbor_list_iterator_p_type), DIMENSION(:), POINTER :: iter_ij => NULL()
      72              :       TYPE(neighbor_list_iterator_p_type), DIMENSION(:), POINTER :: iter_jk => NULL()
      73              :       INTEGER                                                    :: iter_level = 0
      74              :       TYPE(neighbor_list_3c_type)                                :: ijk_nl = neighbor_list_3c_type()
      75              :       INTEGER, DIMENSION(2)                                      :: bounds_i = 0, bounds_j = 0, bounds_k = 0
      76              :       ! pairs taken in turn (neighbor_list_3c_iterate with a shared counter): index and ticket
      77              :       INTEGER                                                    :: ipair = -1, my_pair = -1
      78              :    END TYPE neighbor_list_3c_iterator_type
      79              : 
      80              : CONTAINS
      81              : ! **************************************************************************************************
      82              : !> \brief Create a 3d distribution
      83              : !> \param dist_3d 3d distribution object
      84              : !> \param dist1 distribution vector along 1st process grid dimension
      85              : !> \param dist2 distribution vector along 2nd process grid dimension
      86              : !> \param dist3 distribution vector along 3rd process grid dimension
      87              : !> \param nkind ...
      88              : !> \param particle_set ...
      89              : !> \param mp_comm_3d MPI communicator with a 3d cartesian topology
      90              : !> \param own_comm Whether mp_comm_3d should be owned by dist_3d (default false)
      91              : ! **************************************************************************************************
      92         1138 :    SUBROUTINE distribution_3d_create(dist_3d, dist1, dist2, dist3, nkind, particle_set, mp_comm_3d, own_comm)
      93              :       TYPE(distribution_3d_type)                         :: dist_3d
      94              :       INTEGER, DIMENSION(:), INTENT(IN)                  :: dist1, dist2, dist3
      95              :       INTEGER, INTENT(IN)                                :: nkind
      96              :       TYPE(particle_type), DIMENSION(:), POINTER         :: particle_set
      97              :       TYPE(mp_cart_type), INTENT(IN)                     :: mp_comm_3d
      98              :       LOGICAL, INTENT(IN), OPTIONAL                      :: own_comm
      99              : 
     100              :       CHARACTER(len=*), PARAMETER :: routineN = 'distribution_3d_create'
     101              : 
     102              :       INTEGER                                            :: handle
     103              :       INTEGER, DIMENSION(2)                              :: mp_coor_1, mp_coor_2
     104         1138 :       TYPE(mp_cart_type)                                 :: comm_2d_1, comm_2d_2
     105              : 
     106         1138 :       CALL timeset(routineN, handle)
     107              : 
     108         1138 :       IF (PRESENT(own_comm)) THEN
     109         1138 :          IF (own_comm) dist_3d%comm_3d = mp_comm_3d
     110         1138 :          dist_3d%owns_comm = own_comm
     111              :       ELSE
     112            0 :          dist_3d%owns_comm = .FALSE.
     113              :       END IF
     114              : 
     115         1138 :       CALL comm_2d_1%from_sub(mp_comm_3d, [.TRUE., .TRUE., .FALSE.])
     116         1138 :       CALL comm_2d_2%from_sub(mp_comm_3d, [.FALSE., .TRUE., .TRUE.])
     117              : 
     118         3414 :       mp_coor_1 = comm_2d_1%mepos_cart
     119         3414 :       mp_coor_2 = comm_2d_2%mepos_cart
     120              : 
     121         1138 :       CPASSERT(mp_coor_1(2) == mp_coor_2(1))
     122              : 
     123         1138 :       CALL distribution_2d_create(dist_3d%dist_2d_1, dist1, dist2, nkind, particle_set, comm_2d_1)
     124         1138 :       CALL distribution_2d_create(dist_3d%dist_2d_2, dist2, dist3, nkind, particle_set, comm_2d_2)
     125              : 
     126         1138 :       dist_3d%comm_2d_1 = comm_2d_1
     127         1138 :       dist_3d%comm_2d_2 = comm_2d_2
     128              : 
     129         1138 :       CALL timestop(handle)
     130         1138 :    END SUBROUTINE distribution_3d_create
     131              : 
     132              : ! **************************************************************************************************
     133              : !> \brief Destroy a 3d distribution
     134              : !> \param dist ...
     135              : ! **************************************************************************************************
     136         1138 :    SUBROUTINE distribution_3d_destroy(dist)
     137              :       TYPE(distribution_3d_type)                         :: dist
     138              : 
     139              :       CHARACTER(len=*), PARAMETER :: routineN = 'distribution_3d_destroy'
     140              : 
     141              :       INTEGER                                            :: handle
     142              : 
     143         1138 :       CALL timeset(routineN, handle)
     144         1138 :       CALL distribution_2d_release(dist%dist_2d_1)
     145         1138 :       CALL distribution_2d_release(dist%dist_2d_2)
     146         1138 :       CALL dist%comm_2d_1%free()
     147         1138 :       CALL dist%comm_2d_2%free()
     148         1138 :       IF (dist%owns_comm) CALL dist%comm_3d%free()
     149              : 
     150         1138 :       NULLIFY (dist%dist_2d_1, dist%dist_2d_2)
     151              : 
     152         1138 :       CALL timestop(handle)
     153         1138 :    END SUBROUTINE distribution_3d_destroy
     154              : 
     155              : ! **************************************************************************************************
     156              : !> \brief Create a 2d distribution. This mainly wraps distribution_2d_create
     157              : !>        for consistency with distribution_3d_create.
     158              : !> \param dist_2d 2d distribution object
     159              : !> \param dist1 distribution vector along 1st process grid dimension
     160              : !> \param dist2 distribution vector along 2nd process grid dimension
     161              : !> \param nkind ...
     162              : !> \param particle_set ...
     163              : !> \param mp_comm_2d MPI communicator with a 3d cartesian topology
     164              : !> \param blacs_env_ext ...
     165              : ! **************************************************************************************************
     166         8167 :    SUBROUTINE distribution_2d_create(dist_2d, dist1, dist2, nkind, particle_set, mp_comm_2d, blacs_env_ext)
     167              :       TYPE(distribution_2d_type), POINTER                :: dist_2d
     168              :       INTEGER, DIMENSION(:), INTENT(IN)                  :: dist1, dist2
     169              :       INTEGER, INTENT(IN)                                :: nkind
     170              :       TYPE(particle_type), DIMENSION(:), POINTER         :: particle_set
     171              :       TYPE(mp_cart_type), INTENT(IN), OPTIONAL           :: mp_comm_2d
     172              :       TYPE(cp_blacs_env_type), OPTIONAL, POINTER         :: blacs_env_ext
     173              : 
     174              :       CHARACTER(len=*), PARAMETER :: routineN = 'distribution_2d_create'
     175              : 
     176              :       INTEGER                                            :: handle, iatom, ikind, n, natom
     177         8167 :       INTEGER, ALLOCATABLE, DIMENSION(:)                 :: nparticle_local_col, nparticle_local_row
     178              :       INTEGER, DIMENSION(2)                              :: mp_coor, mp_dims
     179         8167 :       INTEGER, DIMENSION(:, :), POINTER                  :: dist1_prv, dist2_prv
     180         8167 :       TYPE(cp_1d_i_p_type), DIMENSION(:), POINTER        :: local_particle_col, local_particle_row
     181              :       TYPE(cp_blacs_env_type), POINTER                   :: blacs_env
     182              :       TYPE(mp_para_env_type), POINTER                    :: para_env
     183              : 
     184         8167 :       NULLIFY (blacs_env, local_particle_col, local_particle_row, para_env)
     185              : 
     186         8167 :       CALL timeset(routineN, handle)
     187              : 
     188         8167 :       CPASSERT(PRESENT(mp_comm_2d) .OR. PRESENT(blacs_env_ext))
     189              : 
     190         8167 :       IF (PRESENT(mp_comm_2d)) THEN
     191         6828 :          mp_dims = mp_comm_2d%num_pe_cart
     192         6828 :          mp_coor = mp_comm_2d%mepos_cart
     193         2276 :          ALLOCATE (para_env)
     194         2276 :          para_env = mp_comm_2d
     195              :          CALL cp_blacs_env_create(blacs_env, para_env, &
     196         2276 :                                   grid_2d=mp_dims)
     197              : 
     198         2276 :          CPASSERT(blacs_env%mepos(1) == mp_coor(1))
     199         2276 :          CPASSERT(blacs_env%mepos(2) == mp_coor(2))
     200         2276 :          CALL mp_para_env_release(para_env)
     201              :       END IF
     202              : 
     203         8167 :       IF (PRESENT(blacs_env_ext)) THEN
     204         5891 :          blacs_env => blacs_env_ext
     205         5891 :          mp_coor(1) = blacs_env%mepos(1)
     206         5891 :          mp_coor(2) = blacs_env%mepos(2)
     207              :       END IF
     208              : 
     209         8167 :       natom = SIZE(particle_set)
     210        32668 :       ALLOCATE (dist1_prv(natom, 2), dist2_prv(natom, 2))
     211        25897 :       dist1_prv(:, 1) = dist1
     212        25897 :       dist2_prv(:, 1) = dist2
     213              : 
     214        57964 :       ALLOCATE (local_particle_col(nkind), local_particle_row(nkind))
     215        32668 :       ALLOCATE (nparticle_local_row(nkind), nparticle_local_col(nkind))
     216         8167 :       nparticle_local_row = 0; nparticle_local_col = 0
     217              : 
     218        25897 :       DO iatom = 1, natom
     219        17730 :          ikind = particle_set(iatom)%atomic_kind%kind_number
     220              : 
     221        17730 :          IF (dist1_prv(iatom, 1) == mp_coor(1)) nparticle_local_row(ikind) = nparticle_local_row(ikind) + 1
     222        25897 :          IF (dist2_prv(iatom, 1) == mp_coor(2)) nparticle_local_col(ikind) = nparticle_local_col(ikind) + 1
     223              :       END DO
     224              : 
     225        20815 :       DO ikind = 1, nkind
     226        12648 :          n = nparticle_local_row(ikind)
     227        36826 :          ALLOCATE (local_particle_row(ikind)%array(n))
     228              : 
     229        12648 :          n = nparticle_local_col(ikind)
     230        46049 :          ALLOCATE (local_particle_col(ikind)%array(n))
     231              :       END DO
     232              : 
     233         8167 :       nparticle_local_row = 0; nparticle_local_col = 0
     234        25897 :       DO iatom = 1, natom
     235        17730 :          ikind = particle_set(iatom)%atomic_kind%kind_number
     236              : 
     237        17730 :          IF (dist1_prv(iatom, 1) == mp_coor(1)) THEN
     238        15366 :             nparticle_local_row(ikind) = nparticle_local_row(ikind) + 1
     239        15366 :             local_particle_row(ikind)%array(nparticle_local_row(ikind)) = iatom
     240              :          END IF
     241        25897 :          IF (dist2_prv(iatom, 1) == mp_coor(2)) THEN
     242        17488 :             nparticle_local_col(ikind) = nparticle_local_col(ikind) + 1
     243        17488 :             local_particle_col(ikind)%array(nparticle_local_col(ikind)) = iatom
     244              :          END IF
     245              :       END DO
     246              : 
     247              :       CALL distribution_2d_create_prv(dist_2d, row_distribution_ptr=dist1_prv, &
     248              :                                       col_distribution_ptr=dist2_prv, local_rows_ptr=local_particle_row, &
     249         8167 :                                       local_cols_ptr=local_particle_col, blacs_env=blacs_env)
     250              : 
     251         8167 :       IF (.NOT. PRESENT(blacs_env_ext)) THEN
     252         2276 :          CALL cp_blacs_env_release(blacs_env)
     253              :       END IF
     254              : 
     255         8167 :       CALL timestop(handle)
     256        16334 :    END SUBROUTINE distribution_2d_create
     257              : 
     258              : ! **************************************************************************************************
     259              : !> \brief contiguous distribution of weighted elements
     260              : !> \param nel ...
     261              : !> \param nbin ...
     262              : !> \param weights ...
     263              : !> \param limits_start ...
     264              : !> \param limits_end ...
     265              : !> \param dist ...
     266              : ! **************************************************************************************************
     267         2244 :    SUBROUTINE contiguous_tensor_dist(nel, nbin, weights, limits_start, limits_end, dist)
     268              :       INTEGER, INTENT(IN)                                :: nel
     269              :       INTEGER, INTENT(INOUT)                             :: nbin
     270              :       INTEGER, DIMENSION(nel), INTENT(IN)                :: weights
     271              :       INTEGER, ALLOCATABLE, DIMENSION(:), INTENT(OUT), &
     272              :          OPTIONAL                                        :: limits_start, limits_end
     273              :       INTEGER, DIMENSION(nel), INTENT(OUT), OPTIONAL     :: dist
     274              : 
     275              :       INTEGER                                            :: el_end, el_start, end_weight, ibin, &
     276              :                                                             nel_div, nel_rem, nel_split, nel_w, &
     277              :                                                             w_partialsum
     278         2244 :       INTEGER, ALLOCATABLE, DIMENSION(:)                 :: lim_e, lim_s
     279              : 
     280         8976 :       ALLOCATE (lim_s(nbin), lim_e(nbin))
     281         2244 :       lim_s = 0; lim_e = 0
     282              : 
     283        13936 :       nel_w = SUM(weights)
     284         2244 :       nel_div = nel_w/nbin
     285         2244 :       nel_rem = MOD(nel_w, nbin)
     286              : 
     287         2244 :       w_partialsum = 0
     288         2244 :       el_end = 0
     289         2244 :       end_weight = 0
     290         6666 :       DO ibin = 1, nbin
     291         6666 :          nel_split = nel_div
     292         6666 :          IF (ibin <= nel_rem) THEN
     293         1690 :             nel_split = nel_split + 1
     294              :          END IF
     295         6666 :          el_start = el_end + 1
     296         6666 :          el_end = el_start
     297         6666 :          w_partialsum = w_partialsum + weights(el_end)
     298         6666 :          end_weight = end_weight + nel_split
     299        10844 :          DO WHILE (w_partialsum < end_weight)
     300              :             !IF (ABS(w_partialsum + weights(el_end) - end_weight) > ABS(w_partialsum - end_weight)) EXIT
     301         5026 :             el_end = el_end + 1
     302         5026 :             w_partialsum = w_partialsum + weights(el_end)
     303        10844 :             IF (el_end == nel) EXIT
     304              :          END DO
     305              : 
     306         6666 :          IF (PRESENT(dist)) dist(el_start:el_end) = ibin - 1
     307         6666 :          lim_s(ibin) = el_start
     308         6666 :          lim_e(ibin) = el_end
     309              : 
     310         6666 :          IF (el_end == nel) EXIT
     311              :       END DO
     312              : 
     313         2244 :       IF (PRESENT(limits_start) .AND. PRESENT(limits_end)) THEN
     314        13398 :          ALLOCATE (limits_start(ibin)); limits_start(:ibin) = lim_s(:ibin)
     315        11154 :          ALLOCATE (limits_end(ibin)); limits_end(:ibin) = lim_e(:ibin)
     316              :       END IF
     317              : 
     318         2244 :       nbin = ibin
     319              : 
     320         2244 :    END SUBROUTINE contiguous_tensor_dist
     321              : 
     322              : ! **************************************************************************************************
     323              : !> \brief ...
     324              : !> \param t3c Create 3-center tensor with load balanced default distribution.
     325              : !> \param dist_1 ...
     326              : !> \param dist_2 ...
     327              : !> \param dist_3 ...
     328              : !> \param pgrid ...
     329              : !> \param sizes_1 ...
     330              : !> \param sizes_2 ...
     331              : !> \param sizes_3 ...
     332              : !> \param map1 ...
     333              : !> \param map2 ...
     334              : !> \param name ...
     335              : ! **************************************************************************************************
     336        83116 :    SUBROUTINE create_3c_tensor(t3c, dist_1, dist_2, dist_3, pgrid, sizes_1, sizes_2, sizes_3, map1, map2, name)
     337              :       TYPE(dbt_type), INTENT(OUT)                        :: t3c
     338              :       INTEGER, ALLOCATABLE, DIMENSION(:), INTENT(OUT)    :: dist_1, dist_2, dist_3
     339              :       TYPE(dbt_pgrid_type), INTENT(IN)                   :: pgrid
     340              :       INTEGER, DIMENSION(:), INTENT(IN)                  :: sizes_1, sizes_2, sizes_3, map1, map2
     341              :       CHARACTER(len=*), INTENT(IN)                       :: name
     342              : 
     343              :       CHARACTER(len=*), PARAMETER                        :: routineN = 'create_3c_tensor'
     344              : 
     345              :       INTEGER                                            :: handle, size_1, size_2, size_3
     346              :       INTEGER, DIMENSION(3)                              :: pcoord, pdims
     347        68004 :       TYPE(dbt_distribution_type)                        :: dist
     348              : 
     349         7556 :       CALL timeset(routineN, handle)
     350              : 
     351         7556 :       CALL dbt_mp_environ_pgrid(pgrid, pdims, pcoord)
     352              : 
     353         7556 :       size_1 = SIZE(sizes_1)
     354         7556 :       size_2 = SIZE(sizes_2)
     355         7556 :       size_3 = SIZE(sizes_3)
     356              : 
     357        22668 :       ALLOCATE (dist_1(size_1))
     358        22668 :       ALLOCATE (dist_2(size_2))
     359        22668 :       ALLOCATE (dist_3(size_3))
     360              : 
     361         7556 :       CALL dbt_default_distvec(size_1, pdims(1), sizes_1, dist_1)
     362         7556 :       CALL dbt_default_distvec(size_2, pdims(2), sizes_2, dist_2)
     363         7556 :       CALL dbt_default_distvec(size_3, pdims(3), sizes_3, dist_3)
     364              : 
     365         7556 :       CALL dbt_distribution_new(dist, pgrid, dist_1, dist_2, dist_3)
     366         7556 :       CALL dbt_create(t3c, name, dist, map1, map2, sizes_1, sizes_2, sizes_3)
     367         7556 :       CALL dbt_distribution_destroy(dist)
     368              : 
     369         7556 :       CALL timestop(handle)
     370        15112 :    END SUBROUTINE create_3c_tensor
     371              : 
     372              : ! **************************************************************************************************
     373              : !> \brief ...
     374              : !> \param t2c ...
     375              : !> \param dist_1 ...
     376              : !> \param dist_2 ...
     377              : !> \param pgrid ...
     378              : !> \param sizes_1 ...
     379              : !> \param sizes_2 ...
     380              : !> \param order ...
     381              : !> \param name ...
     382              : ! **************************************************************************************************
     383       121088 :    SUBROUTINE create_2c_tensor(t2c, dist_1, dist_2, pgrid, sizes_1, sizes_2, order, name)
     384              :       TYPE(dbt_type), INTENT(OUT)                        :: t2c
     385              :       INTEGER, ALLOCATABLE, DIMENSION(:), INTENT(OUT)    :: dist_1, dist_2
     386              :       TYPE(dbt_pgrid_type), INTENT(IN)                   :: pgrid
     387              :       INTEGER, DIMENSION(:), INTENT(IN)                  :: sizes_1, sizes_2
     388              :       INTEGER, DIMENSION(:), INTENT(IN), OPTIONAL        :: order
     389              :       CHARACTER(len=*), INTENT(IN)                       :: name
     390              : 
     391              :       CHARACTER(len=*), PARAMETER                        :: routineN = 'create_2c_tensor'
     392              : 
     393              :       INTEGER                                            :: handle, size_1, size_2
     394              :       INTEGER, DIMENSION(2)                              :: order_in, pcoord, pdims
     395        99072 :       TYPE(dbt_distribution_type)                        :: dist
     396              : 
     397        11008 :       CALL timeset(routineN, handle)
     398              : 
     399        11008 :       IF (PRESENT(order)) THEN
     400            0 :          order_in = order
     401              :       ELSE
     402        11008 :          order_in = [1, 2]
     403              :       END IF
     404              : 
     405        11008 :       CALL dbt_mp_environ_pgrid(pgrid, pdims, pcoord)
     406              : 
     407        11008 :       size_1 = SIZE(sizes_1)
     408        11008 :       size_2 = SIZE(sizes_2)
     409              : 
     410        33024 :       ALLOCATE (dist_1(size_1))
     411        33024 :       ALLOCATE (dist_2(size_2))
     412              : 
     413        11008 :       CALL dbt_default_distvec(size_1, pdims(1), sizes_1, dist_1)
     414        11008 :       CALL dbt_default_distvec(size_2, pdims(2), sizes_2, dist_2)
     415              : 
     416        11008 :       CALL dbt_distribution_new(dist, pgrid, dist_1, dist_2)
     417        33024 :       CALL dbt_create(t2c, name, dist, [order_in(1)], [order_in(2)], sizes_1, sizes_2)
     418        11008 :       CALL dbt_distribution_destroy(dist)
     419              : 
     420        11008 :       CALL timestop(handle)
     421        22016 :    END SUBROUTINE create_2c_tensor
     422              : 
     423              : ! **************************************************************************************************
     424              : !> \brief ...
     425              : !> \param blk_sizes ...
     426              : !> \param blk_sizes_split ...
     427              : !> \param max_size ...
     428              : ! **************************************************************************************************
     429         1360 :    SUBROUTINE split_block_sizes(blk_sizes, blk_sizes_split, max_size)
     430              :       INTEGER, DIMENSION(:), INTENT(IN)                  :: blk_sizes
     431              :       INTEGER, ALLOCATABLE, DIMENSION(:), INTENT(OUT)    :: blk_sizes_split
     432              :       INTEGER, INTENT(IN)                                :: max_size
     433              : 
     434              :       INTEGER                                            :: blk_remainder, i, isplit, isplit_sum, &
     435              :                                                             nsplit
     436              : 
     437         1360 :       isplit_sum = 0
     438         5392 :       DO i = 1, SIZE(blk_sizes)
     439         4032 :          nsplit = (blk_sizes(i) + max_size - 1)/max_size
     440         5392 :          isplit_sum = isplit_sum + nsplit
     441              :       END DO
     442              : 
     443         4080 :       ALLOCATE (blk_sizes_split(isplit_sum))
     444              : 
     445         1360 :       isplit_sum = 0
     446         5392 :       DO i = 1, SIZE(blk_sizes)
     447         4032 :          nsplit = (blk_sizes(i) + max_size - 1)/max_size
     448         4032 :          blk_remainder = blk_sizes(i)
     449         9710 :          DO isplit = 1, nsplit
     450         4318 :             isplit_sum = isplit_sum + 1
     451         4318 :             blk_sizes_split(isplit_sum) = MIN(max_size, blk_remainder)
     452         8350 :             blk_remainder = blk_remainder - max_size
     453              :          END DO
     454              :       END DO
     455              : 
     456         1360 :    END SUBROUTINE split_block_sizes
     457              : 
     458              : ! **************************************************************************************************
     459              : !> \brief ...
     460              : !> \param atomic_kind_set ...
     461              : !> \param basis ...
     462              : !> \param min_blk_size ...
     463              : !> \param pgf_blk_sizes ...
     464              : ! **************************************************************************************************
     465         1340 :    SUBROUTINE pgf_block_sizes(atomic_kind_set, basis, min_blk_size, pgf_blk_sizes)
     466              :       TYPE(atomic_kind_type), DIMENSION(:), POINTER      :: atomic_kind_set
     467              :       TYPE(gto_basis_set_p_type), DIMENSION(:), &
     468              :          INTENT(IN)                                      :: basis
     469              :       INTEGER, INTENT(IN)                                :: min_blk_size
     470              :       INTEGER, ALLOCATABLE, DIMENSION(:), INTENT(OUT)    :: pgf_blk_sizes
     471              : 
     472              :       INTEGER                                            :: blk_count, blk_count_prev, blk_size, &
     473              :                                                             iatom, ikind, iset, natom, nblk, nset
     474         1340 :       INTEGER, ALLOCATABLE, DIMENSION(:)                 :: kind_of, pgf_blk_sizes_tmp
     475         1340 :       INTEGER, DIMENSION(:), POINTER                     :: nsgf_set
     476              : 
     477         1340 :       CALL get_atomic_kind_set(atomic_kind_set, natom=natom, kind_of=kind_of)
     478              : 
     479         1340 :       nblk = 0
     480         4952 :       DO iatom = 1, natom
     481         3612 :          ikind = kind_of(iatom)
     482         3612 :          CALL get_gto_basis_set(basis(ikind)%gto_basis_set, nset=nset)
     483         4952 :          nblk = nblk + nset
     484              :       END DO
     485              : 
     486         4020 :       ALLOCATE (pgf_blk_sizes_tmp(nblk)); pgf_blk_sizes_tmp = 0
     487              : 
     488         1340 :       blk_count = 0
     489         1340 :       blk_size = 0
     490         4952 :       DO iatom = 1, natom
     491         3612 :          blk_count_prev = blk_count
     492         3612 :          ikind = kind_of(iatom)
     493         3612 :          CALL get_gto_basis_set(basis(ikind)%gto_basis_set, nset=nset, nsgf_set=nsgf_set)
     494        22472 :          DO iset = 1, nset
     495        18860 :             blk_size = blk_size + nsgf_set(iset)
     496        22472 :             IF (blk_size >= min_blk_size) THEN
     497        11960 :                blk_count = blk_count + 1
     498        11960 :                pgf_blk_sizes_tmp(blk_count) = pgf_blk_sizes_tmp(blk_count) + blk_size
     499        11960 :                blk_size = 0
     500              :             END IF
     501              :          END DO
     502         8564 :          IF (blk_size > 0) THEN
     503          890 :             IF (blk_count == blk_count_prev) blk_count = blk_count + 1
     504          890 :             pgf_blk_sizes_tmp(blk_count) = pgf_blk_sizes_tmp(blk_count) + blk_size
     505          890 :             blk_size = 0
     506              :          END IF
     507              :       END DO
     508              : 
     509         4020 :       ALLOCATE (pgf_blk_sizes(blk_count))
     510        13432 :       pgf_blk_sizes(:) = pgf_blk_sizes_tmp(:blk_count)
     511         2680 :    END SUBROUTINE pgf_block_sizes
     512              : 
     513              : ! **************************************************************************************************
     514              : !> \brief ...
     515              : !> \param sizes ...
     516              : !> \param nbatches ...
     517              : !> \param starts_array ...
     518              : !> \param ends_array ...
     519              : !> \param starts_array_block ...
     520              : !> \param ends_array_block ...
     521              : ! **************************************************************************************************
     522         2244 :    SUBROUTINE create_tensor_batches(sizes, nbatches, starts_array, ends_array, &
     523              :                                     starts_array_block, ends_array_block)
     524              :       INTEGER, DIMENSION(:), INTENT(IN)                  :: sizes
     525              :       INTEGER, INTENT(INOUT)                             :: nbatches
     526              :       INTEGER, ALLOCATABLE, DIMENSION(:), INTENT(OUT)    :: starts_array, ends_array, &
     527              :                                                             starts_array_block, ends_array_block
     528              : 
     529              :       INTEGER                                            :: bsum, imem, nblocks
     530              : 
     531         2244 :       nblocks = SIZE(sizes)
     532              : 
     533         2244 :       CALL contiguous_tensor_dist(nblocks, nbatches, sizes, limits_start=starts_array_block, limits_end=ends_array_block)
     534              : 
     535         6732 :       ALLOCATE (starts_array(nbatches))
     536         4488 :       ALLOCATE (ends_array(nbatches))
     537              : 
     538         2244 :       bsum = 0
     539         8910 :       DO imem = 1, nbatches
     540         6666 :          starts_array(imem) = bsum + 1
     541        18358 :          bsum = bsum + SUM(sizes(starts_array_block(imem):ends_array_block(imem)))
     542         8910 :          ends_array(imem) = bsum
     543              :       END DO
     544         2244 :    END SUBROUTINE create_tensor_batches
     545              : 
     546            0 : END MODULE qs_tensors_types
        

Generated by: LCOV version 2.0-1