LCOV - code coverage report
Current view: top level - src - task_list_types.F (source / functions) Hit Total Coverage
Test: CP2K Regtests (git:2fce0f8) Lines: 87 88 98.9 %
Date: 2024-12-21 06:28:57 Functions: 5 8 62.5 %

          Line data    Source code
       1             : !--------------------------------------------------------------------------------------------------!
       2             : !   CP2K: A general program to perform molecular dynamics simulations                              !
       3             : !   Copyright 2000-2024 CP2K developers group <https://cp2k.org>                                   !
       4             : !                                                                                                  !
       5             : !   SPDX-License-Identifier: GPL-2.0-or-later                                                      !
       6             : !--------------------------------------------------------------------------------------------------!
       7             : 
       8             : ! **************************************************************************************************
       9             : !> \brief types for task lists
      10             : !> \par History
      11             : !>      01.2008 [Joost VandeVondele] refactered out of qs_collocate / qs_integrate
      12             : !> \author Joost VandeVondele
      13             : ! **************************************************************************************************
      14             : MODULE task_list_types
      15             :    USE grid_api,                        ONLY: grid_basis_set_type,&
      16             :                                               grid_free_basis_set,&
      17             :                                               grid_free_task_list,&
      18             :                                               grid_task_list_type
      19             :    USE kinds,                           ONLY: dp,&
      20             :                                               int_8
      21             :    USE offload_api,                     ONLY: offload_buffer_type,&
      22             :                                               offload_free_buffer
      23             : #include "./base/base_uses.f90"
      24             : 
      25             :    IMPLICIT NONE
      26             : 
      27             :    PRIVATE
      28             : 
      29             :    CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'task_list_types'
      30             : 
      31             :    TYPE task_type
      32             :       INTEGER                                       :: destination = 0
      33             :       INTEGER                                       :: source = 0
      34             :       INTEGER                                       :: dist_type = 0
      35             :       INTEGER                                       :: cost = 0
      36             :       INTEGER                                       :: subpatch_pattern = 0
      37             :       INTEGER                                       :: grid_level = 0
      38             :       INTEGER                                       :: image = 0
      39             :       INTEGER                                       :: iatom = 0
      40             :       INTEGER                                       :: jatom = 0
      41             :       INTEGER                                       :: iset = 0
      42             :       INTEGER                                       :: jset = 0
      43             :       INTEGER                                       :: ipgf = 0
      44             :       INTEGER                                       :: jpgf = 0
      45             :       INTEGER                                       :: pair_index = 0
      46             : 
      47             :       REAL(KIND=dp), DIMENSION(3)                   :: rab = 0.0_dp
      48             :       REAL(KIND=dp)                                 :: radius = 0.0_dp
      49             :    END TYPE task_type
      50             : 
      51             :    TYPE atom_pair_type
      52             :       INTEGER                                       :: rank = 0
      53             :       INTEGER                                       :: row = 0
      54             :       INTEGER                                       :: col = 0
      55             :       INTEGER                                       :: image = 0
      56             :    END TYPE atom_pair_type
      57             : 
      58             :    TYPE task_list_type
      59             :       TYPE(task_type), DIMENSION(:), POINTER        :: tasks => Null()
      60             :       INTEGER                                       :: ntasks = 0
      61             :       INTEGER, DIMENSION(:, :), POINTER             :: taskstart => Null(), taskstop => Null()
      62             :       INTEGER, DIMENSION(:), POINTER                :: npairs => Null()
      63             : 
      64             :       TYPE(atom_pair_type), DIMENSION(:), POINTER   :: atom_pair_send => Null()
      65             :       INTEGER, DIMENSION(:), POINTER                :: pair_offsets_send => Null()
      66             :       INTEGER, DIMENSION(:), POINTER                :: rank_offsets_send => Null()
      67             :       INTEGER, DIMENSION(:), POINTER                :: rank_sizes_send => Null()
      68             :       INTEGER                                       :: buffer_size_send = 0
      69             : 
      70             :       TYPE(atom_pair_type), DIMENSION(:), POINTER   :: atom_pair_recv => Null()
      71             :       INTEGER, DIMENSION(:), POINTER                :: pair_offsets_recv => Null()
      72             :       INTEGER, DIMENSION(:), POINTER                :: rank_offsets_recv => Null()
      73             :       INTEGER, DIMENSION(:), POINTER                :: rank_sizes_recv => Null()
      74             :       INTEGER                                       :: buffer_size_recv = 0
      75             : 
      76             :       TYPE(grid_basis_set_type), DIMENSION(:), POINTER :: grid_basis_sets => Null()
      77             :       TYPE(grid_task_list_type)                     :: grid_task_list = grid_task_list_type()
      78             :       TYPE(offload_buffer_type)                     :: pab_buffer = offload_buffer_type()
      79             :       TYPE(offload_buffer_type)                     :: hab_buffer = offload_buffer_type()
      80             :    END TYPE task_list_type
      81             : 
      82             :    INTEGER, PARAMETER                               :: task_size_in_int8 = 17
      83             : 
      84             :    PUBLIC :: task_type, atom_pair_type, task_list_type
      85             :    PUBLIC :: task_size_in_int8, serialize_task, deserialize_task
      86             :    PUBLIC :: allocate_task_list, deallocate_task_list, reallocate_tasks
      87             : 
      88             : CONTAINS
      89             : 
      90             : ! **************************************************************************************************
      91             : !> \brief allocates and initialised the components of the task_list_type
      92             : !> \param task_list ...
      93             : !> \par History
      94             : !>      01.2008 created [Joost VandeVondele]
      95             : ! **************************************************************************************************
      96        8038 :    SUBROUTINE allocate_task_list(task_list)
      97             :       TYPE(task_list_type), POINTER                      :: task_list
      98             : 
      99        8038 :       ALLOCATE (task_list)
     100             : 
     101             :       NULLIFY (task_list%tasks)
     102             :       NULLIFY (task_list%atom_pair_send)
     103             :       NULLIFY (task_list%atom_pair_recv)
     104             :       NULLIFY (task_list%taskstart)
     105             :       NULLIFY (task_list%taskstop)
     106             :       NULLIFY (task_list%npairs)
     107             :       task_list%ntasks = 0
     108        8038 :    END SUBROUTINE allocate_task_list
     109             : 
     110             : ! **************************************************************************************************
     111             : !> \brief Grow an array of tasks while preserving the existing entries.
     112             : !> \param tasks ...
     113             : !> \param new_size ...
     114             : !> \author Ole Schuett
     115             : ! **************************************************************************************************
     116       11415 :    SUBROUTINE reallocate_tasks(tasks, new_size)
     117             :       TYPE(task_type), DIMENSION(:), INTENT(inout), &
     118             :          POINTER                                         :: tasks
     119             :       INTEGER, INTENT(in)                                :: new_size
     120             : 
     121       11415 :       TYPE(task_type), DIMENSION(:), POINTER             :: old_tasks
     122             : 
     123       11415 :       IF (.NOT. ASSOCIATED(tasks)) THEN
     124    20926592 :          ALLOCATE (tasks(new_size))
     125       10432 :          RETURN
     126             :       END IF
     127             : 
     128         983 :       IF (new_size <= SIZE(tasks)) RETURN
     129             : 
     130         983 :       old_tasks => tasks
     131         983 :       NULLIFY (tasks)
     132             : 
     133     9505842 :       ALLOCATE (tasks(new_size))
     134     7534927 :       tasks(1:SIZE(old_tasks)) = old_tasks(:)
     135         983 :       DEALLOCATE (old_tasks)
     136       11415 :    END SUBROUTINE reallocate_tasks
     137             : 
     138             : ! **************************************************************************************************
     139             : !> \brief deallocates the components and the object itself
     140             : !> \param task_list ...
     141             : !> \par History
     142             : !>      01.2008 created [Joost VandeVondele]
     143             : ! **************************************************************************************************
     144        8038 :    SUBROUTINE deallocate_task_list(task_list)
     145             :       TYPE(task_list_type), POINTER                      :: task_list
     146             : 
     147             :       INTEGER                                            :: i
     148             : 
     149        8038 :       IF (ASSOCIATED(task_list%tasks)) THEN
     150        8038 :          DEALLOCATE (task_list%tasks)
     151             :       END IF
     152        8038 :       IF (ASSOCIATED(task_list%taskstart)) THEN
     153        8038 :          DEALLOCATE (task_list%taskstart)
     154             :       END IF
     155        8038 :       IF (ASSOCIATED(task_list%taskstop)) THEN
     156        8038 :          DEALLOCATE (task_list%taskstop)
     157             :       END IF
     158        8038 :       IF (ASSOCIATED(task_list%npairs)) THEN
     159        8038 :          DEALLOCATE (task_list%npairs)
     160             :       END IF
     161             : 
     162        8038 :       IF (ASSOCIATED(task_list%atom_pair_send)) THEN
     163          20 :          DEALLOCATE (task_list%atom_pair_send)
     164             :       END IF
     165        8038 :       IF (ASSOCIATED(task_list%pair_offsets_send)) THEN
     166          20 :          DEALLOCATE (task_list%pair_offsets_send)
     167             :       END IF
     168        8038 :       IF (ASSOCIATED(task_list%rank_offsets_send)) THEN
     169          20 :          DEALLOCATE (task_list%rank_offsets_send)
     170             :       END IF
     171        8038 :       IF (ASSOCIATED(task_list%rank_sizes_send)) THEN
     172          20 :          DEALLOCATE (task_list%rank_sizes_send)
     173             :       END IF
     174             : 
     175        8038 :       IF (ASSOCIATED(task_list%atom_pair_recv)) THEN
     176        8038 :          DEALLOCATE (task_list%atom_pair_recv)
     177             :       END IF
     178        8038 :       IF (ASSOCIATED(task_list%pair_offsets_recv)) THEN
     179        8038 :          DEALLOCATE (task_list%pair_offsets_recv)
     180             :       END IF
     181        8038 :       IF (ASSOCIATED(task_list%rank_offsets_recv)) THEN
     182        8038 :          DEALLOCATE (task_list%rank_offsets_recv)
     183             :       END IF
     184        8038 :       IF (ASSOCIATED(task_list%rank_sizes_recv)) THEN
     185        8038 :          DEALLOCATE (task_list%rank_sizes_recv)
     186             :       END IF
     187        8038 :       CALL grid_free_task_list(task_list%grid_task_list)
     188        8038 :       CALL offload_free_buffer(task_list%pab_buffer)
     189        8038 :       CALL offload_free_buffer(task_list%hab_buffer)
     190        8038 :       IF (ASSOCIATED(task_list%grid_basis_sets)) THEN
     191       22411 :          DO i = 1, SIZE(task_list%grid_basis_sets)
     192       22411 :             CALL grid_free_basis_set(task_list%grid_basis_sets(i))
     193             :          END DO
     194        8038 :          DEALLOCATE (task_list%grid_basis_sets)
     195             :       END IF
     196             : 
     197        8038 :       DEALLOCATE (task_list)
     198        8038 :    END SUBROUTINE deallocate_task_list
     199             : 
     200             : ! **************************************************************************************************
     201             : !> \brief Serialize a task into an integer array. Used for MPI communication.
     202             : !> \param task ...
     203             : !> \param serialized_task ...
     204             : !> \author Ole Schuett
     205             : ! **************************************************************************************************
     206        3618 :    SUBROUTINE serialize_task(task, serialized_task)
     207             :       TYPE(task_type), INTENT(IN)                        :: task
     208             :       INTEGER(KIND=int_8), &
     209             :          DIMENSION(task_size_in_int8), INTENT(OUT)       :: serialized_task
     210             : 
     211        3618 :       serialized_task(1) = task%destination
     212        3618 :       serialized_task(2) = task%source
     213        3618 :       serialized_task(3) = task%dist_type
     214        3618 :       serialized_task(4) = task%cost
     215        3618 :       serialized_task(5) = task%subpatch_pattern
     216             : 
     217        3618 :       serialized_task(6) = task%grid_level
     218        3618 :       serialized_task(7) = task%image
     219        3618 :       serialized_task(8) = task%iatom
     220        3618 :       serialized_task(9) = task%jatom
     221        3618 :       serialized_task(10) = task%iset
     222        3618 :       serialized_task(11) = task%jset
     223        3618 :       serialized_task(12) = task%ipgf
     224        3618 :       serialized_task(13) = task%jpgf
     225             : 
     226        3618 :       serialized_task(14) = TRANSFER(task%rab(1), mold=1_int_8)
     227        3618 :       serialized_task(15) = TRANSFER(task%rab(2), mold=1_int_8)
     228        3618 :       serialized_task(16) = TRANSFER(task%rab(3), mold=1_int_8)
     229        3618 :       serialized_task(17) = TRANSFER(task%radius, mold=1_int_8)
     230        3618 :    END SUBROUTINE serialize_task
     231             : 
     232             : ! **************************************************************************************************
     233             : !> \brief De-serialize a task from an integer array. Used for MPI communication.
     234             : !> \param task ...
     235             : !> \param serialized_task ...
     236             : !> \author Ole Schuett
     237             : ! **************************************************************************************************
     238       14472 :    SUBROUTINE deserialize_task(task, serialized_task)
     239             :       TYPE(task_type), INTENT(OUT)                       :: task
     240             :       INTEGER(KIND=int_8), &
     241             :          DIMENSION(task_size_in_int8), INTENT(IN)        :: serialized_task
     242             : 
     243        3618 :       task%destination = INT(serialized_task(1))
     244        3618 :       task%source = INT(serialized_task(2))
     245        3618 :       task%dist_type = INT(serialized_task(3))
     246        3618 :       task%cost = INT(serialized_task(4))
     247        3618 :       task%subpatch_pattern = INT(serialized_task(5))
     248             : 
     249        3618 :       task%grid_level = INT(serialized_task(6))
     250        3618 :       task%image = INT(serialized_task(7))
     251        3618 :       task%iatom = INT(serialized_task(8))
     252        3618 :       task%jatom = INT(serialized_task(9))
     253        3618 :       task%iset = INT(serialized_task(10))
     254        3618 :       task%jset = INT(serialized_task(11))
     255        3618 :       task%ipgf = INT(serialized_task(12))
     256        3618 :       task%jpgf = INT(serialized_task(13))
     257             : 
     258        3618 :       task%rab(1) = TRANSFER(serialized_task(14), mold=1.0_dp)
     259        3618 :       task%rab(2) = TRANSFER(serialized_task(15), mold=1.0_dp)
     260        3618 :       task%rab(3) = TRANSFER(serialized_task(16), mold=1.0_dp)
     261        3618 :       task%radius = TRANSFER(serialized_task(17), mold=1.0_dp)
     262        3618 :    END SUBROUTINE deserialize_task
     263             : 
     264           0 : END MODULE task_list_types

Generated by: LCOV version 1.15