LCOV - code coverage report
Current view: top level - src/dbt - dbt_unittest.F (source / functions) Coverage Total Hit
Test: CP2K Regtests (git:1be8651) Lines: 99.3 % 426 423
Test Date: 2026-11-24 01:22:08 Functions: 100.0 % 2 2

            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 Block tensor unit test
      10              : !> \author Patrick Seewald
      11              : ! **************************************************************************************************
      12            2 : PROGRAM dbt_unittest
      13            2 :    USE cp_dbcsr_api,                    ONLY: dbcsr_finalize_lib,&
      14              :                                               dbcsr_init_lib
      15              :    USE dbm_api,                         ONLY: dbm_library_finalize,&
      16              :                                               dbm_library_init,&
      17              :                                               dbm_library_print_stats
      18              :    USE dbt_api,                         ONLY: dbt_library_finalize,&
      19              :                                               dbt_library_init,&
      20              :                                               dbt_library_print_stats
      21              :    USE dbt_test,                        ONLY: dbt_contract_test,&
      22              :                                               dbt_reset_randmat_seed,&
      23              :                                               dbt_setup_test_tensor,&
      24              :                                               dbt_test_formats
      25              :    USE dbt_types,                       ONLY: &
      26              :         dbt_create, dbt_default_distvec, dbt_destroy, dbt_distribution_destroy, &
      27              :         dbt_distribution_new, dbt_distribution_type, dbt_get_info, dbt_pgrid_create, &
      28              :         dbt_pgrid_destroy, dbt_pgrid_type, dbt_type, ndims_tensor
      29              :    USE kinds,                           ONLY: dp
      30              :    USE machine,                         ONLY: default_output_unit
      31              :    USE message_passing,                 ONLY: mp_comm_type,&
      32              :                                               mp_world_finalize,&
      33              :                                               mp_world_init
      34              :    USE offload_api,                     ONLY: offload_get_device_count,&
      35              :                                               offload_set_chosen_device
      36              : #include "../base/base_uses.f90"
      37              : 
      38              :    IMPLICIT NONE
      39              : 
      40              :    TYPE(mp_comm_type) :: mp_comm
      41              :    INTEGER                            :: mynode, io_unit
      42              :    INTEGER                            :: ndims, nblks_alloc, nblks_1, nblks_2, nblks_3, nblks_4, nblks_5, &
      43              :                                          nblks_alloc_1, nblks_alloc_2, nblks_alloc_3, nblks_alloc_4, nblks_alloc_5
      44            4 :    INTEGER, DIMENSION(:), ALLOCATABLE :: size_1, size_2, size_3, size_4, size_5, dist1_1, dist1_2, dist1_3, &
      45            4 :                                          dist2_1, dist2_2, dist3_1, dist3_2, dist3_3, dist4_1, dist4_2, &
      46            2 :                                          dist4_3, dist4_4, dist5_1, dist5_2, dist5_3
      47            2 :    INTEGER, DIMENSION(:), ALLOCATABLE :: blk_ind_1, blk_ind_2, blk_ind_3, blk_ind_4, blk_ind_1_1, blk_ind_2_1, &
      48            2 :                                          blk_ind_3_1, blk_ind_3_2, blk_ind_4_2, blk_ind_1_3, blk_ind_2_3, &
      49            2 :                                          blk_ind_4_3, blk_ind_1_4, blk_ind_2_4, blk_ind_4_4, blk_ind_5_4, &
      50            2 :                                          blk_ind_3_5, blk_ind_4_5, blk_ind_5_5
      51            2 :    INTEGER, DIMENSION(:), ALLOCATABLE :: map11, map31, map12, map32, map21, map22
      52              : 
      53              :    LOGICAL, PARAMETER                 :: verbose = .FALSE.
      54           38 :    TYPE(dbt_distribution_type)         :: dist1, dist2, dist3
      55           38 :    TYPE(dbt_type)            :: tensor_A, tensor_B, tensor_C
      56              : 
      57              :    LOGICAL, PARAMETER                 :: test_format = .TRUE.
      58              :    LOGICAL, PARAMETER                 :: test_contraction = .TRUE.
      59              :    INTEGER, DIMENSION(4)              :: pdims_4d
      60              :    INTEGER, DIMENSION(3)              :: pdims_3d
      61              :    INTEGER, DIMENSION(2)              :: pdims_2d
      62           14 :    TYPE(dbt_pgrid_type)           :: pgrid_2d, pgrid_3d, pgrid_4d
      63            2 :    INTEGER, DIMENSION(:), ALLOCATABLE :: bounds_t
      64            2 :    INTEGER, DIMENSION(:, :), ALLOCATABLE :: bounds, bounds_1, bounds_2
      65              : 
      66            2 :    CALL mp_world_init(mp_comm)
      67            2 :    mynode = mp_comm%mepos
      68              : 
      69              :    ! Select active offload device when available.
      70            2 :    IF (offload_get_device_count() > 0) THEN
      71            0 :       CALL offload_set_chosen_device(MOD(mynode, offload_get_device_count()))
      72              :    END IF
      73              : 
      74              :    ! set standard output parameters
      75            2 :    io_unit = -1
      76            2 :    IF (mynode == 0) io_unit = default_output_unit
      77              : 
      78            2 :    CALL dbcsr_init_lib(mp_comm%get_handle(), io_unit) ! Needed for DBM_VALIDATE_AGAINST_DBCSR.
      79            2 :    CALL dbm_library_init()
      80            2 :    CALL dbt_library_init()
      81              : 
      82            2 :    CALL dbt_reset_randmat_seed()
      83              : 
      84              :    ! Process grid
      85              : 
      86              :    IF (test_format) THEN
      87              : !--------------------------------------------------------------------------------------------------!
      88              : ! Test 1: Testing matrix representations of tensor rank 2                                                  !
      89              : !--------------------------------------------------------------------------------------------------!
      90            2 :       ndims = 2
      91              : 
      92              :       ! Number of blocks in each dimension
      93            2 :       nblks_1 = 14
      94            2 :       nblks_2 = 21
      95              : 
      96              :       ! Block sizes in each dimension
      97            2 :       ALLOCATE (size_1(nblks_1), size_2(nblks_2))
      98              : 
      99           30 :       size_1(:) = [3, 5, 1, 23, 2, 3, 1, 6, 3, 8, 2, 3, 5, 1]
     100           44 :       size_2(:) = [4, 2, 5, 3, 1, 5, 13, 5, 2, 4, 5, 6, 7, 2, 3, 1, 2, 6, 9, 12, 21]
     101              : 
     102              :       ! Number of non-zero blocks
     103            2 :       nblks_alloc = 12
     104            2 :       ALLOCATE (blk_ind_1(nblks_alloc), blk_ind_2(nblks_alloc))
     105              : 
     106              :       ! Indices of non-zero blocks (s.t. index of ith block is [blk_ind_1(i), blk_ind_2(i), ...])
     107           26 :       blk_ind_1(:) = [1, 1,  1,  2, 4,  4,  7,  10, 10, 10, 10, 13] !&
     108           26 :       blk_ind_2(:) = [1, 3, 11, 15, 4, 17, 21,   6,  9, 13, 19,  7] !&
     109              : 
     110              :       ! Test tensor formats
     111              :       CALL dbt_test_formats(ndims, mp_comm, io_unit, verbose, &
     112              :                             blk_size_1=size_1, blk_size_2=size_2, &
     113            2 :                             blk_ind_1=blk_ind_1, blk_ind_2=blk_ind_2)
     114              : 
     115            2 :       DEALLOCATE (size_1, size_2)
     116            2 :       DEALLOCATE (blk_ind_1, blk_ind_2)
     117              : 
     118              : !--------------------------------------------------------------------------------------------------!
     119              : ! Test 2: Testing matrix representations of tensor rank 3                                          !
     120              : !--------------------------------------------------------------------------------------------------!
     121            2 :       ndims = 3
     122              : 
     123              :       ! Number of blocks in each dimension
     124              :       nblks_1 = 4
     125              :       nblks_2 = 6
     126              :       nblks_3 = 3
     127              : 
     128              :       ! Block sizes in each dimension
     129            2 :       ALLOCATE (size_1(nblks_1), size_2(nblks_2), size_3(nblks_3))
     130              : 
     131           10 :       size_1(:) = [3, 1, 5, 2]
     132           14 :       size_2(:) = [1, 2, 5, 3, 2, 4]
     133            8 :       size_3(:) = [4, 2, 10]
     134              : 
     135              :       ! Number of non-zero blocks
     136            2 :       nblks_alloc = 6
     137            2 :       ALLOCATE (blk_ind_1(nblks_alloc), blk_ind_2(nblks_alloc), blk_ind_3(nblks_alloc))
     138              : 
     139              :       ! Indices of non-zero blocks (s.t. index of ith block is [blk_ind_1(i), blk_ind_2(i), ...])
     140           14 :       blk_ind_1(:) = [1, 1, 1, 2, 2, 2] !&
     141           14 :       blk_ind_2(:) = [2, 2, 4, 1, 1, 2] !&
     142           14 :       blk_ind_3(:) = [1, 3, 3, 2, 3, 2] !&
     143              : 
     144              :       ! Test tensor formats
     145              :       CALL dbt_test_formats(ndims, mp_comm, io_unit, verbose, &
     146              :                             blk_size_1=size_1, blk_size_2=size_2, blk_size_3=size_3, &
     147            2 :                             blk_ind_1=blk_ind_1, blk_ind_2=blk_ind_2, blk_ind_3=blk_ind_3)
     148              : 
     149            2 :       DEALLOCATE (size_1, size_2, size_3)
     150            2 :       DEALLOCATE (blk_ind_1, blk_ind_2, blk_ind_3)
     151              : 
     152              : !--------------------------------------------------------------------------------------------------!
     153              : ! Test 3: Testing matrix representations of tensor rank 4                                          !
     154              : !--------------------------------------------------------------------------------------------------!
     155            2 :       ndims = 4
     156              : 
     157              :       ! Number of blocks in each dimension
     158              :       nblks_1 = 2
     159              :       nblks_2 = 13
     160              :       nblks_3 = 7
     161              :       nblks_4 = 3
     162              : 
     163              :       ! Block sizes in each dimension
     164            2 :       ALLOCATE (size_1(nblks_1), size_2(nblks_2), size_3(nblks_3), size_4(nblks_4))
     165              : 
     166            6 :       size_1(:) = [5, 9]
     167           28 :       size_2(:) = [6, 2, 5, 12, 3, 1, 7, 2, 5, 17, 9, 3, 4]
     168           16 :       size_3(:) = [2, 7, 3, 8, 5, 15, 1]
     169            8 :       size_4(:) = [12, 5, 3]
     170              : 
     171              :       ! Number of non-zero blocks
     172            2 :       nblks_alloc = 19
     173            2 :       ALLOCATE (blk_ind_1(nblks_alloc), blk_ind_2(nblks_alloc), blk_ind_3(nblks_alloc), blk_ind_4(nblks_alloc))
     174              : 
     175              :       ! Indices of non-zero blocks (s.t. index of ith block is [blk_ind_1(i), blk_ind_2(i), ...])
     176           40 :       blk_ind_1(:) = [1, 1, 1, 1, 1, 1,  1,  1,  1,  1,  1, 2, 2, 2, 2, 2, 2, 2,  2] !&
     177           40 :       blk_ind_2(:) = [2, 2, 3, 4, 7, 7, 10, 11, 11, 12, 12, 1, 1, 3, 5, 6, 6, 9, 12] !&
     178           40 :       blk_ind_3(:) = [1, 4, 6, 3, 1, 4,  2,  5,  7,  3,  3, 1, 4, 7, 6, 4, 5, 2,  3] !&
     179           40 :       blk_ind_4(:) = [3, 2, 3, 1, 1, 2,  1,  3,  2,  2,  3, 1, 3, 2, 1, 1, 3, 2,  2] !&
     180              : 
     181              :       ! Test tensor formats
     182              :       CALL dbt_test_formats(ndims, mp_comm, io_unit, verbose, &
     183              :                             blk_size_1=size_1, blk_size_2=size_2, blk_size_3=size_3, blk_size_4=size_4, &
     184            2 :                             blk_ind_1=blk_ind_1, blk_ind_2=blk_ind_2, blk_ind_3=blk_ind_3, blk_ind_4=blk_ind_4)
     185              : 
     186            2 :       DEALLOCATE (size_1, size_2, size_3, size_4)
     187            2 :       DEALLOCATE (blk_ind_1, blk_ind_2, blk_ind_3, blk_ind_4)
     188              : 
     189              :    END IF
     190              :    IF (test_contraction) THEN
     191              : 
     192              : !--------------------------------------------------------------------------------------------------!
     193              : ! Preparations for tensor contraction tests                                                        !
     194              : !--------------------------------------------------------------------------------------------------!
     195              : 
     196            2 :       nblks_1 = 4
     197            2 :       nblks_2 = 11
     198            2 :       nblks_3 = 9
     199            2 :       nblks_4 = 5
     200            2 :       nblks_5 = 3
     201              : 
     202              :       ! Block sizes in each dimension
     203            2 :       ALLOCATE (size_1(nblks_1), size_2(nblks_2), size_3(nblks_3), size_4(nblks_4), size_5(nblks_5))
     204              : 
     205           10 :       size_1(:) = [3, 9, 12, 1]
     206           24 :       size_2(:) = [4, 2, 3, 1, 9, 2, 32, 10, 5, 8, 7]
     207           20 :       size_3(:) = [7, 3, 8, 7, 9, 5, 10, 23, 2]
     208           12 :       size_4(:) = [8, 1, 4, 13, 6]
     209            8 :       size_5(:) = [4, 2, 22]
     210              : 
     211            2 :       nblks_alloc_1 = 32
     212            2 :       ALLOCATE (blk_ind_1_1(nblks_alloc_1), blk_ind_2_1(nblks_alloc_1), blk_ind_3_1(nblks_alloc_1))
     213              : 
     214              :       blk_ind_1_1(:) = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, & !&
     215              :                         1, 2, 2, 2, 2, 2, 2, 2, 3, 3, & !&
     216              :                         3, 3, 3, 3, 3, 3, 3, 4, 4, 4, & !&
     217           66 :                         4, 4] !&
     218              : 
     219              :       blk_ind_2_1(:) = [ 3, 5, 5, 5, 6,  6,  7,  8, 10, 11, & !&
     220              :                         11, 1, 1, 4, 7,  7,  9, 10 , 2,  2, & !&
     221              :                          5, 6, 8, 8, 9, 11, 11,  2 , 4,  5, & !&
     222           66 :                          5, 8] !&
     223              : 
     224              :       blk_ind_3_1(:) = [7, 3, 5, 9, 6, 8, 2, 8, 3, 2, & !&
     225              :                         3, 1, 4, 6, 2, 7, 5, 8, 3, 7, & !&
     226              :                         1, 4, 3, 7, 8, 5, 8, 9, 6, 1, & !&
     227           66 :                         2, 7] !&
     228              : 
     229            2 :       nblks_alloc_2 = 12
     230            2 :       ALLOCATE (blk_ind_3_2(nblks_alloc_2), blk_ind_4_2(nblks_alloc_2))
     231              : 
     232              :       blk_ind_3_2(:) = [1, 1, 2, 2, 2, 4, 4, 5, 5, 6, & !&
     233           26 :                         8, 8] !&
     234              :       blk_ind_4_2(:) = [2, 3, 2, 4, 5, 3, 5, 1, 3, 3, & !&
     235           26 :                         1, 4] !&
     236              : 
     237            2 :       nblks_alloc_3 = 5
     238            2 :       ALLOCATE (blk_ind_1_3(nblks_alloc_3), blk_ind_2_3(nblks_alloc_3), blk_ind_4_3(nblks_alloc_3))
     239              : 
     240           12 :       blk_ind_1_3(:) = [1, 1, 2, 4, 4]
     241           12 :       blk_ind_2_3(:) = [2, 6, 6, 7, 9]
     242           12 :       blk_ind_4_3(:) = [1, 3, 4, 4, 5]
     243              : 
     244            2 :       nblks_alloc_4 = 36
     245            2 :       ALLOCATE (blk_ind_1_4(nblks_alloc_4))
     246            2 :       ALLOCATE (blk_ind_2_4(nblks_alloc_4))
     247            2 :       ALLOCATE (blk_ind_4_4(nblks_alloc_4))
     248            2 :       ALLOCATE (blk_ind_5_4(nblks_alloc_4))
     249              : 
     250              :       blk_ind_1_4(:) = [ 1, 1, 1, 1, 1, 2, 2, 2,  2,  2, & !&
     251              :                          2, 2, 2, 2, 2, 2, 2, 2,  2,  2, & !&
     252              :                          3, 3, 3, 3, 3, 3, 3, 3,  3,  3, & !&
     253           74 :                          4, 4, 4, 4, 4, 4] !&
     254              : 
     255              :       blk_ind_2_4(:) = [ 1, 3, 4, 6, 10,  2, 2, 4,  5,  5, & !&
     256              :                          6, 6, 6, 7,  7,  9, 9, 9, 10, 11, & !&
     257              :                          1, 3, 3, 4,  5,  6, 8, 9, 11, 11, & !&
     258           74 :                          1, 3, 4, 6, 10, 11] !&
     259              : 
     260              :       blk_ind_4_4(:) = [ 3, 5, 2, 3,  2,  3, 5, 1,  1,  4, & !&
     261              :                          2, 3, 4, 1,  4,  3, 4, 4,  2,  1, & !&
     262              :                          3, 1, 1, 3,  4,  3, 4, 2,  2,  3, & !&
     263           74 :                          1, 1, 3, 2,  5,  5] !&
     264              : 
     265              :       blk_ind_5_4(:) = [ 1, 3, 2, 1,  1,  2, 3,  1,  3, 1, & !&
     266              :                          2, 3, 2, 1,  3,  2, 3,  2,  1, 2, & !&
     267              :                          3, 1, 2, 3,  2,  2, 2,  3,  1, 2, & !&
     268           74 :                          1, 3, 2, 1,  3,  2] !&
     269              : 
     270            2 :       nblks_alloc_5 = 8
     271              : 
     272            2 :       ALLOCATE (blk_ind_3_5(nblks_alloc_5), blk_ind_4_5(nblks_alloc_5), blk_ind_5_5(nblks_alloc_5))
     273              : 
     274           18 :       blk_ind_3_5(:) = [2, 4, 5, 5, 5, 6, 6, 8]
     275           18 :       blk_ind_4_5(:) = [3, 2, 1, 1, 3, 2, 4, 5]
     276           18 :       blk_ind_5_5(:) = [3, 2, 1, 2, 3, 2, 1, 1]
     277              : 
     278            2 :       pdims_4d(:) = 0; pdims_3d(:) = 0; pdims_2d(:) = 0
     279            2 :       CALL dbt_pgrid_create(mp_comm, pdims_4d, pgrid_4d)
     280            2 :       CALL dbt_pgrid_create(mp_comm, pdims_3d, pgrid_3d)
     281            2 :       CALL dbt_pgrid_create(mp_comm, pdims_2d, pgrid_2d)
     282              : 
     283            2 :       ALLOCATE (dist1_1(nblks_1))
     284            2 :       CALL dbt_default_distvec(nblks_1, pdims_3d(1), size_1, dist1_1)
     285            2 :       ALLOCATE (dist1_2(nblks_2))
     286            2 :       CALL dbt_default_distvec(nblks_2, pdims_3d(2), size_2, dist1_2)
     287            2 :       ALLOCATE (dist1_3(nblks_3))
     288            2 :       CALL dbt_default_distvec(nblks_3, pdims_3d(3), size_3, dist1_3)
     289              : 
     290            2 :       ALLOCATE (dist2_1(nblks_3))
     291            2 :       CALL dbt_default_distvec(nblks_3, pdims_2d(1), size_3, dist2_1)
     292            2 :       ALLOCATE (dist2_2(nblks_4))
     293            2 :       CALL dbt_default_distvec(nblks_4, pdims_2d(2), size_4, dist2_2)
     294              : 
     295            2 :       ALLOCATE (dist3_1(nblks_1))
     296            2 :       CALL dbt_default_distvec(nblks_1, pdims_3d(1), size_1, dist3_1)
     297            2 :       ALLOCATE (dist3_2(nblks_2))
     298            2 :       CALL dbt_default_distvec(nblks_2, pdims_3d(2), size_2, dist3_2)
     299            2 :       ALLOCATE (dist3_3(nblks_4))
     300            2 :       CALL dbt_default_distvec(nblks_4, pdims_3d(3), size_4, dist3_3)
     301              : 
     302            2 :       ALLOCATE (dist4_1(nblks_1))
     303            2 :       CALL dbt_default_distvec(nblks_1, pdims_4d(1), size_1, dist4_1)
     304            2 :       ALLOCATE (dist4_2(nblks_2))
     305            2 :       CALL dbt_default_distvec(nblks_2, pdims_4d(2), size_2, dist4_2)
     306            2 :       ALLOCATE (dist4_3(nblks_4))
     307            2 :       CALL dbt_default_distvec(nblks_4, pdims_4d(3), size_4, dist4_3)
     308            2 :       ALLOCATE (dist4_4(nblks_5))
     309            2 :       CALL dbt_default_distvec(nblks_5, pdims_4d(4), size_5, dist4_4)
     310              : 
     311            2 :       ALLOCATE (dist5_1(nblks_3))
     312            2 :       CALL dbt_default_distvec(nblks_3, pdims_3d(1), size_3, dist5_1)
     313            2 :       ALLOCATE (dist5_2(nblks_4))
     314            2 :       CALL dbt_default_distvec(nblks_4, pdims_3d(2), size_4, dist5_2)
     315            2 :       ALLOCATE (dist5_3(nblks_5))
     316            2 :       CALL dbt_default_distvec(nblks_5, pdims_3d(3), size_5, dist5_3)
     317              : 
     318              : !--------------------------------------------------------------------------------------------------!
     319              : ! Test 4: Testing tensor contraction (12|3)x(3|4)=(12|4)                                           !
     320              : !--------------------------------------------------------------------------------------------------!
     321              : 
     322            2 :       ALLOCATE (map11(2), map12(1), map21(1), map22(1), map31(2), map32(1))
     323            6 :       map11(:) = [1, 2]
     324            4 :       map12(:) = [3]
     325            4 :       map21(:) = [1]
     326            4 :       map22(:) = [2]
     327            6 :       map31(:) = [1, 2]
     328            4 :       map32(:) = [3]
     329              : 
     330            2 :       CALL dbt_distribution_new(dist1, pgrid_3d, dist1_1, dist1_2, dist1_3)
     331            2 :       CALL dbt_distribution_new(dist2, pgrid_2d, dist2_1, dist2_2)
     332            2 :       CALL dbt_distribution_new(dist3, pgrid_3d, dist3_1, dist3_2, dist3_3)
     333              : 
     334            2 :       CALL dbt_create(tensor_A, "(12|3)", dist1, map11, map12, size_1, size_2, size_3)
     335            2 :       CALL dbt_create(tensor_B, "(3|4)", dist2, map21, map22, size_3, size_4)
     336            2 :       CALL dbt_create(tensor_C, "(12|4)", dist3, map31, map32, size_1, size_2, size_4)
     337              : 
     338            2 :       CALL dbt_setup_test_tensor(tensor_A, mp_comm, .FALSE., blk_ind_1_1, blk_ind_2_1, blk_ind_3_1)
     339            2 :       CALL dbt_setup_test_tensor(tensor_B, mp_comm, .FALSE., blk_ind_3_2, blk_ind_4_2)
     340              : 
     341            2 :       CALL dbt_setup_test_tensor(tensor_C, mp_comm, .FALSE., blk_ind_1_3, blk_ind_2_3, blk_ind_4_3)
     342              : 
     343              :       CALL dbt_contract_test(0.9_dp, tensor_A, tensor_B, 0.1_dp, tensor_C, &
     344              :                              [3], [2, 1], &
     345              :                              [1], [2], &
     346              :                              [2, 1], [3], &
     347              :                              io_unit, &
     348              :                              log_verbose=verbose, &
     349            2 :                              write_int=.TRUE.)
     350              : 
     351            2 :       DEALLOCATE (map11, map12, map21, map22, map31, map32)
     352              : 
     353            2 :       CALL dbt_destroy(tensor_A)
     354            2 :       CALL dbt_destroy(tensor_B)
     355            2 :       CALL dbt_destroy(tensor_C)
     356            2 :       CALL dbt_distribution_destroy(dist1)
     357            2 :       CALL dbt_distribution_destroy(dist2)
     358            2 :       CALL dbt_distribution_destroy(dist3)
     359              : 
     360              : !--------------------------------------------------------------------------------------------------!
     361              : ! Test 5: Testing tensor contraction (2|31)x(4|3)=(24|1)                                           !
     362              : !--------------------------------------------------------------------------------------------------!
     363              : 
     364            2 :       ALLOCATE (map11(1), map12(2), map21(1), map22(1), map31(2), map32(1))
     365            4 :       map11(:) = [2]
     366            6 :       map12(:) = [3, 1]
     367            4 :       map21(:) = [2]
     368            4 :       map22(:) = [1]
     369            6 :       map31(:) = [2, 3]
     370            4 :       map32(:) = [1]
     371              : 
     372            2 :       CALL dbt_distribution_new(dist1, pgrid_3d, dist1_1, dist1_2, dist1_3)
     373            2 :       CALL dbt_distribution_new(dist2, pgrid_2d, dist2_1, dist2_2)
     374            2 :       CALL dbt_distribution_new(dist3, pgrid_3d, dist3_1, dist3_2, dist3_3)
     375              : 
     376            2 :       CALL dbt_create(tensor_A, "(2|31)", dist1, map11, map12, size_1, size_2, size_3)
     377            2 :       CALL dbt_create(tensor_B, "(4|3)", dist2, map21, map22, size_3, size_4)
     378            2 :       CALL dbt_create(tensor_C, "(24|1)", dist3, map31, map32, size_1, size_2, size_4)
     379              : 
     380            2 :       CALL dbt_setup_test_tensor(tensor_A, mp_comm, .FALSE., blk_ind_1_1, blk_ind_2_1, blk_ind_3_1)
     381            2 :       CALL dbt_setup_test_tensor(tensor_B, mp_comm, .FALSE., blk_ind_3_2, blk_ind_4_2)
     382            2 :       CALL dbt_setup_test_tensor(tensor_C, mp_comm, .FALSE., blk_ind_1_3, blk_ind_2_3, blk_ind_4_3)
     383              : 
     384              :       CALL dbt_contract_test(0.9_dp, tensor_A, tensor_B, 0.1_dp, tensor_C, &
     385              :                              [3], [1, 2], &
     386              :                              [1], [2], &
     387              :                              [1, 2], [3], &
     388              :                              io_unit, &
     389              :                              log_verbose=verbose, &
     390            2 :                              write_int=.TRUE.)
     391              : 
     392            2 :       DEALLOCATE (map11, map12, map21, map22, map31, map32)
     393              : 
     394            2 :       CALL dbt_destroy(tensor_A)
     395            2 :       CALL dbt_destroy(tensor_B)
     396            2 :       CALL dbt_destroy(tensor_C)
     397            2 :       CALL dbt_distribution_destroy(dist1)
     398            2 :       CALL dbt_distribution_destroy(dist2)
     399            2 :       CALL dbt_distribution_destroy(dist3)
     400              : 
     401              : !-------------------------------------------------------------------------------------------------!
     402              : ! Test 6: Testing tensor contraction (4|3)x(1|32)=(24|1)                                           !
     403              : !-------------------------------------------------------------------------------------------------!
     404              : 
     405            2 :       ALLOCATE (map11(1), map12(2), map21(1), map22(1), map31(2), map32(1))
     406            4 :       map11(:) = [1]
     407            6 :       map12(:) = [3, 2]
     408            4 :       map21(:) = [2]
     409            4 :       map22(:) = [1]
     410            6 :       map31(:) = [2, 3]
     411            4 :       map32(:) = [1]
     412              : 
     413            2 :       CALL dbt_distribution_new(dist1, pgrid_3d, dist1_1, dist1_2, dist1_3)
     414            2 :       CALL dbt_distribution_new(dist2, pgrid_2d, dist2_1, dist2_2)
     415            2 :       CALL dbt_distribution_new(dist3, pgrid_3d, dist3_1, dist3_2, dist3_3)
     416              : 
     417            2 :       CALL dbt_create(tensor_A, "(1|32)", dist1, map11, map12, size_1, size_2, size_3)
     418            2 :       CALL dbt_create(tensor_B, "(4|3)", dist2, map21, map22, size_3, size_4)
     419            2 :       CALL dbt_create(tensor_C, "(24|1)", dist3, map31, map32, size_1, size_2, size_4)
     420              : 
     421            2 :       CALL dbt_setup_test_tensor(tensor_A, mp_comm, .FALSE., blk_ind_1_1, blk_ind_2_1, blk_ind_3_1)
     422            2 :       CALL dbt_setup_test_tensor(tensor_B, mp_comm, .FALSE., blk_ind_3_2, blk_ind_4_2)
     423            2 :       CALL dbt_setup_test_tensor(tensor_C, mp_comm, .FALSE., blk_ind_1_3, blk_ind_2_3, blk_ind_4_3)
     424              : 
     425            6 :       ALLOCATE (bounds_t(ndims_tensor(tensor_B)))
     426            2 :       CALL dbt_get_info(tensor_B, nfull_total=bounds_t)
     427              : 
     428            2 :       ALLOCATE (bounds(2, 1))
     429            2 :       bounds(1, 1) = 1
     430            2 :       bounds(2, 1) = bounds_t(1) - 21
     431              : 
     432              :       CALL dbt_contract_test(0.9_dp, tensor_B, tensor_A, 0.1_dp, tensor_C, &
     433              :                              [1], [2], &
     434              :                              [3], [1, 2], &
     435              :                              [3], [1, 2], &
     436              :                              io_unit, &
     437              :                              bounds_1=bounds, &
     438              :                              log_verbose=verbose, &
     439            2 :                              write_int=.TRUE.)
     440              : 
     441            2 :       DEALLOCATE (map11, map12, map21, map22, map31, map32, bounds_t, bounds)
     442              : 
     443            2 :       CALL dbt_destroy(tensor_A)
     444            2 :       CALL dbt_destroy(tensor_B)
     445            2 :       CALL dbt_destroy(tensor_C)
     446            2 :       CALL dbt_distribution_destroy(dist1)
     447            2 :       CALL dbt_distribution_destroy(dist2)
     448            2 :       CALL dbt_distribution_destroy(dist3)
     449              : 
     450              : !-------------------------------------------------------------------------------------------------!
     451              : ! Test 7: Testing tensor contraction (1|24)x(3|4)=(21|3)                                          !
     452              : !-------------------------------------------------------------------------------------------------!
     453              : 
     454            2 :       ALLOCATE (map11(2), map12(1), map21(1), map22(1), map31(1), map32(2))
     455            6 :       map11(:) = [2, 1]
     456            4 :       map12(:) = [3]
     457            4 :       map21(:) = [1]
     458            4 :       map22(:) = [2]
     459            4 :       map31(:) = [1]
     460            6 :       map32(:) = [2, 3]
     461              : 
     462            2 :       CALL dbt_distribution_new(dist1, pgrid_3d, dist1_1, dist1_2, dist1_3)
     463            2 :       CALL dbt_distribution_new(dist2, pgrid_2d, dist2_1, dist2_2)
     464            2 :       CALL dbt_distribution_new(dist3, pgrid_3d, dist3_1, dist3_2, dist3_3)
     465              : 
     466            2 :       CALL dbt_create(tensor_A, "(21|3)", dist1, map11, map12, size_1, size_2, size_3)
     467            2 :       CALL dbt_create(tensor_B, "(3|4)", dist2, map21, map22, size_3, size_4)
     468            2 :       CALL dbt_create(tensor_C, "(1|24)", dist3, map31, map32, size_1, size_2, size_4)
     469              : 
     470            2 :       CALL dbt_setup_test_tensor(tensor_A, mp_comm, .FALSE., blk_ind_1_1, blk_ind_2_1, blk_ind_3_1)
     471            2 :       CALL dbt_setup_test_tensor(tensor_B, mp_comm, .FALSE., blk_ind_3_2, blk_ind_4_2)
     472            2 :       CALL dbt_setup_test_tensor(tensor_C, mp_comm, .FALSE., blk_ind_1_3, blk_ind_2_3, blk_ind_4_3)
     473              : 
     474            6 :       ALLOCATE (bounds_t(ndims_tensor(tensor_C)))
     475            2 :       CALL dbt_get_info(tensor_C, nfull_total=bounds_t)
     476              : 
     477            2 :       ALLOCATE (bounds(2, 2))
     478            2 :       bounds(1, 1) = 4
     479            2 :       bounds(2, 1) = bounds_t(1)
     480            2 :       bounds(1, 2) = 13
     481            2 :       bounds(2, 2) = bounds_t(2) - 10
     482            2 :       DEALLOCATE (bounds_t)
     483              : 
     484              :       CALL dbt_contract_test(0.2_dp, tensor_C, tensor_B, 0.8_dp, tensor_A, &
     485              :                              [3], [1, 2], &
     486              :                              [2], [1], &
     487              :                              [1, 2], [3], &
     488              :                              io_unit, &
     489              :                              bounds_2=bounds, &
     490              :                              log_verbose=verbose, &
     491            2 :                              write_int=.TRUE.)
     492              : 
     493            2 :       DEALLOCATE (map11, map12, map21, map22, map31, map32, bounds)
     494              : 
     495            2 :       CALL dbt_destroy(tensor_A)
     496            2 :       CALL dbt_destroy(tensor_B)
     497            2 :       CALL dbt_destroy(tensor_C)
     498            2 :       CALL dbt_distribution_destroy(dist1)
     499            2 :       CALL dbt_distribution_destroy(dist2)
     500            2 :       CALL dbt_distribution_destroy(dist3)
     501              : 
     502              : !-------------------------------------------------------------------------------------------------!
     503              : ! Test 8: Testing tensor contraction (12|3)x(12|45)=(3|45)
     504              : !-------------------------------------------------------------------------------------------------!
     505              : 
     506            2 :       ALLOCATE (map11(2), map12(1), map21(2), map22(2), map31(1), map32(2))
     507            6 :       map11(:) = [1, 2]
     508            4 :       map12(:) = [3]
     509            6 :       map21(:) = [1, 2]
     510            6 :       map22(:) = [3, 4]
     511            4 :       map31(:) = [1]
     512            6 :       map32(:) = [2, 3]
     513              : 
     514            2 :       CALL dbt_distribution_new(dist1, pgrid_3d, dist1_1, dist1_2, dist1_3)
     515            2 :       CALL dbt_distribution_new(dist2, pgrid_4d, dist4_1, dist4_2, dist4_3, dist4_4)
     516            2 :       CALL dbt_distribution_new(dist3, pgrid_3d, dist5_1, dist5_2, dist5_3)
     517              : 
     518            2 :       CALL dbt_create(tensor_A, "(12|3)", dist1, map11, map12, size_1, size_2, size_3)
     519            2 :       CALL dbt_create(tensor_B, "(12|45)", dist2, map21, map22, size_1, size_2, size_4, size_5)
     520            2 :       CALL dbt_create(tensor_C, "(3|45)", dist3, map31, map32, size_3, size_4, size_5)
     521              : 
     522            2 :       CALL dbt_setup_test_tensor(tensor_A, mp_comm, .FALSE., blk_ind_1_1, blk_ind_2_1, blk_ind_3_1)
     523            2 :       CALL dbt_setup_test_tensor(tensor_B, mp_comm, .FALSE., blk_ind_1_4, blk_ind_2_4, blk_ind_4_4, blk_ind_5_4)
     524            2 :       CALL dbt_setup_test_tensor(tensor_C, mp_comm, .FALSE., blk_ind_3_5, blk_ind_4_5, blk_ind_5_5)
     525              : 
     526            6 :       ALLOCATE (bounds_t(ndims_tensor(tensor_A)))
     527            2 :       CALL dbt_get_info(tensor_A, nfull_total=bounds_t)
     528            2 :       ALLOCATE (bounds_1(2, 2))
     529            2 :       bounds_1(1, 1) = 7
     530            2 :       bounds_1(2, 1) = bounds_t(2) - 17
     531            2 :       bounds_1(1, 2) = 8
     532            2 :       bounds_1(2, 2) = bounds_t(1)
     533            2 :       DEALLOCATE (bounds_t)
     534              : 
     535            6 :       ALLOCATE (bounds_t(ndims_tensor(tensor_B)))
     536            2 :       CALL dbt_get_info(tensor_B, nfull_total=bounds_t)
     537            2 :       ALLOCATE (bounds_2(2, 2))
     538            2 :       bounds_2(1, 1) = 1
     539            2 :       bounds_2(2, 1) = bounds_t(3)
     540            2 :       bounds_2(1, 2) = 1
     541            2 :       bounds_2(2, 2) = bounds_t(4) - 18
     542            2 :       DEALLOCATE (bounds_t)
     543              : 
     544              :       CALL dbt_contract_test(0.2_dp, tensor_A, tensor_B, 0.8_dp, tensor_C, &
     545              :                              [2, 1], [3], &
     546              :                              [2, 1], [3, 4], &
     547              :                              [1], [2, 3], &
     548              :                              io_unit, &
     549              :                              bounds_1=bounds_1, &
     550              :                              bounds_3=bounds_2, &
     551              :                              log_verbose=verbose, &
     552            2 :                              write_int=.TRUE.)
     553              : 
     554            2 :       DEALLOCATE (map11, map12, map21, map22, map31, map32, bounds_1, bounds_2)
     555              : 
     556            2 :       CALL dbt_destroy(tensor_A)
     557            2 :       CALL dbt_destroy(tensor_B)
     558            2 :       CALL dbt_destroy(tensor_C)
     559            2 :       CALL dbt_distribution_destroy(dist1)
     560            2 :       CALL dbt_distribution_destroy(dist2)
     561            2 :       CALL dbt_distribution_destroy(dist3)
     562              : 
     563              : !-------------------------------------------------------------------------------------------------!
     564              : ! Test 9: Testing tensor contraction (3|21)x(12|45)=(3|45)
     565              : !-------------------------------------------------------------------------------------------------!
     566              : 
     567            2 :       ALLOCATE (map11(1), map12(2), map21(2), map22(2), map31(1), map32(2))
     568            4 :       map11(:) = [3]
     569            6 :       map12(:) = [2, 1]
     570            6 :       map21(:) = [1, 2]
     571            6 :       map22(:) = [3, 4]
     572            4 :       map31(:) = [1]
     573            6 :       map32(:) = [2, 3]
     574              : 
     575            2 :       CALL dbt_distribution_new(dist1, pgrid_3d, dist1_1, dist1_2, dist1_3)
     576            2 :       CALL dbt_distribution_new(dist2, pgrid_4d, dist4_1, dist4_2, dist4_3, dist4_4)
     577            2 :       CALL dbt_distribution_new(dist3, pgrid_3d, dist5_1, dist5_2, dist5_3)
     578              : 
     579            2 :       CALL dbt_create(tensor_A, "(3|21)", dist1, map11, map12, size_1, size_2, size_3)
     580            2 :       CALL dbt_create(tensor_B, "(12|45)", dist2, map21, map22, size_1, size_2, size_4, size_5)
     581            2 :       CALL dbt_create(tensor_C, "(3|45)", dist3, map31, map32, size_3, size_4, size_5)
     582              : 
     583            2 :       CALL dbt_setup_test_tensor(tensor_A, mp_comm, .FALSE., blk_ind_1_1, blk_ind_2_1, blk_ind_3_1)
     584            2 :       CALL dbt_setup_test_tensor(tensor_B, mp_comm, .FALSE., blk_ind_1_4, blk_ind_2_4, blk_ind_4_4, blk_ind_5_4)
     585            2 :       CALL dbt_setup_test_tensor(tensor_C, mp_comm, .FALSE., blk_ind_3_5, blk_ind_4_5, blk_ind_5_5)
     586              : 
     587              :       CALL dbt_contract_test(0.2_dp, tensor_A, tensor_B, 0.8_dp, tensor_C, &
     588              :                              [2, 1], [3], &
     589              :                              [2, 1], [3, 4], &
     590              :                              [1], [2, 3], &
     591              :                              io_unit, &
     592              :                              log_verbose=verbose, &
     593            2 :                              write_int=.TRUE.)
     594              : 
     595            2 :       DEALLOCATE (map11, map12, map21, map22, map31, map32)
     596              : 
     597            2 :       CALL dbt_destroy(tensor_A)
     598            2 :       CALL dbt_destroy(tensor_B)
     599            2 :       CALL dbt_destroy(tensor_C)
     600            2 :       CALL dbt_distribution_destroy(dist1)
     601            2 :       CALL dbt_distribution_destroy(dist2)
     602            2 :       CALL dbt_distribution_destroy(dist3)
     603              : 
     604              : !-------------------------------------------------------------------------------------------------!
     605              : ! Test 10: Testing tensor contraction (13|2)x(54|21)=(3|45)
     606              : !-------------------------------------------------------------------------------------------------!
     607              : 
     608            2 :       ALLOCATE (map11(2), map12(1), map21(2), map22(2), map31(1), map32(2))
     609            6 :       map11(:) = [1, 3]
     610            4 :       map12(:) = [2]
     611            6 :       map21(:) = [4, 3]
     612            6 :       map22(:) = [2, 1]
     613            4 :       map31(:) = [1]
     614            6 :       map32(:) = [2, 3]
     615              : 
     616            2 :       CALL dbt_distribution_new(dist1, pgrid_3d, dist1_1, dist1_2, dist1_3)
     617            2 :       CALL dbt_distribution_new(dist2, pgrid_4d, dist4_1, dist4_2, dist4_3, dist4_4)
     618            2 :       CALL dbt_distribution_new(dist3, pgrid_3d, dist5_1, dist5_2, dist5_3)
     619              : 
     620            2 :       CALL dbt_create(tensor_A, "(13|2)", dist1, map11, map12, size_1, size_2, size_3)
     621            2 :       CALL dbt_create(tensor_B, "(54|21)", dist2, map21, map22, size_1, size_2, size_4, size_5)
     622            2 :       CALL dbt_create(tensor_C, "(3|45)", dist3, map31, map32, size_3, size_4, size_5)
     623              : 
     624            2 :       CALL dbt_setup_test_tensor(tensor_A, mp_comm, .FALSE., blk_ind_1_1, blk_ind_2_1, blk_ind_3_1)
     625            2 :       CALL dbt_setup_test_tensor(tensor_B, mp_comm, .FALSE., blk_ind_1_4, blk_ind_2_4, blk_ind_4_4, blk_ind_5_4)
     626            2 :       CALL dbt_setup_test_tensor(tensor_C, mp_comm, .FALSE., blk_ind_3_5, blk_ind_4_5, blk_ind_5_5)
     627              : 
     628              :       CALL dbt_contract_test(0.2_dp, tensor_A, tensor_B, 0.8_dp, tensor_C, &
     629              :                              [1, 2], [3], &
     630              :                              [1, 2], [3, 4], &
     631              :                              [1], [2, 3], &
     632              :                              io_unit, &
     633              :                              log_verbose=verbose, &
     634            2 :                              write_int=.TRUE.)
     635              : 
     636            2 :       DEALLOCATE (map11, map12, map21, map22, map31, map32)
     637              : 
     638            2 :       CALL dbt_destroy(tensor_A)
     639            2 :       CALL dbt_destroy(tensor_B)
     640            2 :       CALL dbt_destroy(tensor_C)
     641            2 :       CALL dbt_distribution_destroy(dist1)
     642            2 :       CALL dbt_distribution_destroy(dist2)
     643            2 :       CALL dbt_distribution_destroy(dist3)
     644              : 
     645              : !-------------------------------------------------------------------------------------------------!
     646              : ! Test 10: Testing tensor contraction (54|21)x(2|31)=(43|5)
     647              : !-------------------------------------------------------------------------------------------------!
     648              : 
     649            2 :       ALLOCATE (map11(1), map12(2), map21(2), map22(2), map31(2), map32(1))
     650            4 :       map11(:) = [2]
     651            6 :       map12(:) = [3, 1]
     652            6 :       map21(:) = [4, 3]
     653            6 :       map22(:) = [2, 1]
     654            6 :       map31(:) = [2, 1]
     655            4 :       map32(:) = [3]
     656              : 
     657            2 :       CALL dbt_distribution_new(dist1, pgrid_3d, dist1_1, dist1_2, dist1_3)
     658            2 :       CALL dbt_distribution_new(dist2, pgrid_4d, dist4_1, dist4_2, dist4_3, dist4_4)
     659            2 :       CALL dbt_distribution_new(dist3, pgrid_3d, dist5_1, dist5_2, dist5_3)
     660              : 
     661            2 :       CALL dbt_create(tensor_A, "(2|31)", dist1, map11, map12, size_1, size_2, size_3)
     662            2 :       CALL dbt_create(tensor_B, "(54|21)", dist2, map21, map22, size_1, size_2, size_4, size_5)
     663            2 :       CALL dbt_create(tensor_C, "(43|5)", dist3, map31, map32, size_3, size_4, size_5)
     664              : 
     665            2 :       CALL dbt_setup_test_tensor(tensor_A, mp_comm, .FALSE., blk_ind_1_1, blk_ind_2_1, blk_ind_3_1)
     666            2 :       CALL dbt_setup_test_tensor(tensor_B, mp_comm, .FALSE., blk_ind_1_4, blk_ind_2_4, blk_ind_4_4, blk_ind_5_4)
     667            2 :       CALL dbt_setup_test_tensor(tensor_C, mp_comm, .FALSE., blk_ind_3_5, blk_ind_4_5, blk_ind_5_5)
     668              : 
     669              :       CALL dbt_contract_test(0.2_dp, tensor_B, tensor_A, 0.8_dp, tensor_C, &
     670              :                              [2, 1], [4, 3], &
     671              :                              [2, 1], [3], &
     672              :                              [3, 2], [1], &
     673              :                              io_unit, &
     674              :                              log_verbose=verbose, &
     675            2 :                              write_int=.TRUE.)
     676              : 
     677            2 :       DEALLOCATE (map11, map12, map21, map22, map31, map32)
     678              : 
     679            2 :       CALL dbt_destroy(tensor_A)
     680            2 :       CALL dbt_destroy(tensor_B)
     681            2 :       CALL dbt_destroy(tensor_C)
     682            2 :       CALL dbt_distribution_destroy(dist1)
     683            2 :       CALL dbt_distribution_destroy(dist2)
     684            2 :       CALL dbt_distribution_destroy(dist3)
     685              : 
     686              : !-------------------------------------------------------------------------------------------------!
     687              : ! Test 11: Testing tensor contraction (241|5)x(31|2)=(5|43)
     688              : !-------------------------------------------------------------------------------------------------!
     689              : 
     690            2 :       ALLOCATE (map11(2), map12(1), map21(3), map22(1), map31(1), map32(2))
     691            6 :       map11(:) = [3, 1]
     692            4 :       map12(:) = [2]
     693            8 :       map21(:) = [2, 3, 1]
     694            4 :       map22(:) = [4]
     695            4 :       map31(:) = [3]
     696            6 :       map32(:) = [2, 1]
     697              : 
     698            2 :       CALL dbt_distribution_new(dist1, pgrid_3d, dist1_1, dist1_2, dist1_3)
     699            2 :       CALL dbt_distribution_new(dist2, pgrid_4d, dist4_1, dist4_2, dist4_3, dist4_4)
     700            2 :       CALL dbt_distribution_new(dist3, pgrid_3d, dist5_1, dist5_2, dist5_3)
     701              : 
     702            2 :       CALL dbt_create(tensor_A, "(31|2)", dist1, map11, map12, size_1, size_2, size_3)
     703            2 :       CALL dbt_create(tensor_B, "(241|5)", dist2, map21, map22, size_1, size_2, size_4, size_5)
     704            2 :       CALL dbt_create(tensor_C, "(5|43)", dist3, map31, map32, size_3, size_4, size_5)
     705              : 
     706            2 :       CALL dbt_setup_test_tensor(tensor_A, mp_comm, .FALSE., blk_ind_1_1, blk_ind_2_1, blk_ind_3_1)
     707            2 :       CALL dbt_setup_test_tensor(tensor_B, mp_comm, .FALSE., blk_ind_1_4, blk_ind_2_4, blk_ind_4_4, blk_ind_5_4)
     708            2 :       CALL dbt_setup_test_tensor(tensor_C, mp_comm, .FALSE., blk_ind_3_5, blk_ind_4_5, blk_ind_5_5)
     709              : 
     710              :       CALL dbt_contract_test(0.6_dp, tensor_B, tensor_A, 0.4_dp, tensor_C, &
     711              :                              [2, 1], [3, 4], &
     712              :                              [2, 1], [3], &
     713              :                              [2, 3], [1], &
     714              :                              io_unit, &
     715              :                              log_verbose=verbose, &
     716            2 :                              write_int=.TRUE.)
     717              : 
     718            2 :       DEALLOCATE (map11, map12, map21, map22, map31, map32)
     719              : 
     720            2 :       CALL dbt_destroy(tensor_A)
     721            2 :       CALL dbt_destroy(tensor_B)
     722            2 :       CALL dbt_destroy(tensor_C)
     723            2 :       CALL dbt_distribution_destroy(dist1)
     724            2 :       CALL dbt_distribution_destroy(dist2)
     725            2 :       CALL dbt_distribution_destroy(dist3)
     726              : 
     727              : !-------------------------------------------------------------------------------------------------!
     728              : ! Test 12: Testing tensor contraction (34|5)x(12|3)=(14|25)
     729              : !-------------------------------------------------------------------------------------------------!
     730              : 
     731            2 :       ALLOCATE (map11(2), map12(1), map21(2), map22(2), map31(2), map32(1))
     732            6 :       map11(:) = [1, 2]
     733            4 :       map12(:) = [3]
     734            6 :       map21(:) = [1, 3]
     735            6 :       map22(:) = [2, 4]
     736            6 :       map31(:) = [1, 2]
     737            4 :       map32(:) = [3]
     738              : 
     739            2 :       CALL dbt_distribution_new(dist1, pgrid_3d, dist1_1, dist1_2, dist1_3)
     740            2 :       CALL dbt_distribution_new(dist2, pgrid_4d, dist4_1, dist4_2, dist4_3, dist4_4)
     741            2 :       CALL dbt_distribution_new(dist3, pgrid_3d, dist5_1, dist5_2, dist5_3)
     742              : 
     743            2 :       CALL dbt_create(tensor_A, "(12|3)", dist1, map11, map12, size_1, size_2, size_3)
     744            2 :       CALL dbt_create(tensor_B, "(14|25)", dist2, map21, map22, size_1, size_2, size_4, size_5)
     745            2 :       CALL dbt_create(tensor_C, "(34|5)", dist3, map31, map32, size_3, size_4, size_5)
     746              : 
     747            2 :       CALL dbt_setup_test_tensor(tensor_A, mp_comm, .FALSE., blk_ind_1_1, blk_ind_2_1, blk_ind_3_1)
     748            2 :       CALL dbt_setup_test_tensor(tensor_B, mp_comm, .FALSE., blk_ind_1_4, blk_ind_2_4, blk_ind_4_4, blk_ind_5_4)
     749            2 :       CALL dbt_setup_test_tensor(tensor_C, mp_comm, .FALSE., blk_ind_3_5, blk_ind_4_5, blk_ind_5_5)
     750              : 
     751              :       CALL dbt_contract_test(0.2_dp, tensor_C, tensor_A, 0.8_dp, tensor_B, &
     752              :                              [1], [2, 3], &
     753              :                              [3], [1, 2], &
     754              :                              [3, 4], [1, 2], &
     755              :                              io_unit, &
     756              :                              log_verbose=verbose, &
     757            2 :                              write_int=.TRUE.)
     758              : 
     759            2 :       DEALLOCATE (map11, map12, map21, map22, map31, map32)
     760              : 
     761            2 :       CALL dbt_destroy(tensor_A)
     762            2 :       CALL dbt_destroy(tensor_B)
     763            2 :       CALL dbt_destroy(tensor_C)
     764            2 :       CALL dbt_distribution_destroy(dist1)
     765            2 :       CALL dbt_distribution_destroy(dist2)
     766            2 :       CALL dbt_distribution_destroy(dist3)
     767              : 
     768              : !--------------------------------------------------------------------------------------------------!
     769              : ! Cleanup for tensor contraction tests                                                             !
     770              : !--------------------------------------------------------------------------------------------------!
     771              : 
     772            2 :       DEALLOCATE (blk_ind_1_1, blk_ind_2_1, blk_ind_3_1)
     773            2 :       DEALLOCATE (blk_ind_3_2, blk_ind_4_2)
     774            2 :       DEALLOCATE (blk_ind_1_3, blk_ind_2_3, blk_ind_4_3)
     775            2 :       DEALLOCATE (blk_ind_1_4, blk_ind_2_4, blk_ind_4_4, blk_ind_5_4)
     776            2 :       DEALLOCATE (blk_ind_3_5, blk_ind_4_5, blk_ind_5_5)
     777            0 :       DEALLOCATE (size_1, size_2, size_3, size_4, size_5, dist1_1, dist1_2, dist1_3, &
     778            0 :                   dist2_1, dist2_2, dist3_1, dist3_2, dist3_3, dist4_1, dist4_2, &
     779            2 :                   dist4_3, dist4_4, dist5_1, dist5_2, dist5_3)
     780            2 :       CALL dbt_pgrid_destroy(pgrid_3d)
     781            2 :       CALL dbt_pgrid_destroy(pgrid_2d)
     782            2 :       CALL dbt_pgrid_destroy(pgrid_4d)
     783              : 
     784              :    END IF
     785              : 
     786              : !--------------------------------------------------------------------------------------------------!
     787              : ! End tests                                                                                        !
     788              : !--------------------------------------------------------------------------------------------------!
     789              : 
     790            2 :    CALL dbm_library_print_stats(mp_comm, io_unit)
     791            2 :    CALL dbt_library_print_stats(mp_comm, io_unit)
     792            2 :    CALL dbt_library_finalize()
     793            2 :    CALL dbm_library_finalize()
     794            2 :    CALL dbcsr_finalize_lib() ! Needed for DBM_VALIDATE_AGAINST_DBCSR.
     795              : 
     796              :    ! finalize mpi
     797            2 :    CALL mp_world_finalize()
     798              : 
     799            2 : END PROGRAM dbt_unittest
        

Generated by: LCOV version 2.0-1