LCOV - code coverage report
Current view: top level - src/tmc - tmc_cancelation.F (source / functions) Hit Total Coverage
Test: CP2K Regtests (git:262480d) Lines: 25 30 83.3 %
Date: 2024-11-22 07:00:40 Functions: 2 2 100.0 %

          Line data    Source code
       1             : !--------------------------------------------------------------------------------------------------!
       2             : !   CP2K: A general program to perform molecular dynamics simulations                              !
       3             : !   Copyright 2000-2024 CP2K developers group <https://cp2k.org>                                   !
       4             : !                                                                                                  !
       5             : !   SPDX-License-Identifier: GPL-2.0-or-later                                                      !
       6             : !--------------------------------------------------------------------------------------------------!
       7             : 
       8             : ! **************************************************************************************************
       9             : !> \brief - to decrease the used memory size, just actual needed tree elements
      10             : !>        should be stored in memory, other ones should be written out in file
      11             : !>        - sub tree elements can be canceled and further deallocated when no
      12             : !>          global tree element refers to it anymore
      13             : !>        - then also the ongoing calculation of these elements is not needed
      14             : !>          anymore => can be canceled
      15             : !>        - MODULE: creates and handles a list of tree nodes
      16             : !>                    which can be canceled
      17             : !>                  these elements are collected and canceled all in one
      18             : !>                    from the master routine
      19             : !>        - the actual cancelation routine is implemented in master module and
      20             : !>          communication is done using the message module
      21             : !> \par History
      22             : !>      11.2012 created [Mandes Schoenherr]
      23             : !> \author Mandes
      24             : ! **************************************************************************************************
      25             : 
      26             : MODULE tmc_cancelation
      27             :    USE cp_log_handling,                 ONLY: cp_to_string
      28             :    USE tmc_dot_tree,                    ONLY: create_dot_color
      29             :    USE tmc_tree_types,                  ONLY: &
      30             :         add_to_list, elem_list_type, status_accepted, status_accepted_result, &
      31             :         status_calc_approx_ener, status_calculate_MD, status_calculate_NMC_steps, &
      32             :         status_calculate_energy, status_calculated, status_cancel_ener, status_cancel_nmc, &
      33             :         status_canceled_ener, status_canceled_nmc, status_created, status_deleted, &
      34             :         status_deleted_result, status_rejected, status_rejected_result, tree_type
      35             :    USE tmc_types,                       ONLY: tmc_env_type
      36             : #include "../base/base_uses.f90"
      37             : 
      38             :    IMPLICIT NONE
      39             : 
      40             :    PRIVATE
      41             : 
      42             :    CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'tmc_cancelation'
      43             : 
      44             :    PUBLIC :: add_to_canceling_list, free_cancelation_list
      45             : 
      46             : CONTAINS
      47             : 
      48             : ! **************************************************************************************************
      49             : !> \brief add a certain element to the cancelation list
      50             : !> \param elem the sub tree element, to be added
      51             : !> \param tmc_env tmc environment
      52             : !> \author Mandes 11.2012
      53             : ! **************************************************************************************************
      54        9046 :    SUBROUTINE add_to_canceling_list(elem, tmc_env)
      55             :       TYPE(tree_type), POINTER                           :: elem
      56             :       TYPE(tmc_env_type), POINTER                        :: tmc_env
      57             : 
      58             :       CHARACTER(LEN=*), PARAMETER :: routineN = 'add_to_canceling_list'
      59             : 
      60             :       INTEGER                                            :: handle
      61             :       LOGICAL                                            :: need_to_cancel
      62             : 
      63        4523 :       CPASSERT(ASSOCIATED(elem))
      64        4523 :       CPASSERT(ASSOCIATED(tmc_env))
      65        4523 :       CPASSERT(ASSOCIATED(tmc_env%m_env))
      66        4523 :       CPASSERT(ASSOCIATED(tmc_env%params))
      67             : 
      68             :       ! start the timing
      69        4523 :       CALL timeset(routineN, handle)
      70             : 
      71        4523 :       IF (tmc_env%params%SPECULATIVE_CANCELING) THEN
      72        4523 :          need_to_cancel = .FALSE.
      73             :          ! update status
      74        4524 :          SELECT CASE (elem%stat)
      75             :          CASE (status_calculate_energy)
      76           1 :             elem%stat = status_cancel_ener
      77           1 :             need_to_cancel = .TRUE.
      78           1 :             tmc_env%m_env%count_cancel_ener = tmc_env%m_env%count_cancel_ener + 1
      79             :          CASE (status_calc_approx_ener) !TODO maybe elem status for approx ener cancel
      80             :             !elem%stat = status_cancel_ener
      81             :             !need_to_cancel = .TRUE.
      82             :          CASE (status_calculate_NMC_steps, status_calculate_MD)
      83           0 :             elem%stat = status_cancel_nmc
      84           0 :             need_to_cancel = .TRUE.
      85           0 :             tmc_env%m_env%count_cancel_NMC = tmc_env%m_env%count_cancel_NMC + 1
      86             :          CASE (status_accepted, status_accepted_result, status_rejected, &
      87             :                status_rejected_result, status_calculated, status_created, &
      88             :                status_cancel_nmc, status_cancel_ener, status_canceled_nmc, &
      89             :                status_canceled_ener)
      90             :          CASE (status_deleted_result, status_deleted)
      91             :             ! if deallocation is deactivated, should not be
      92           0 :             CPWARN("try to add deleted element cancelation list ")
      93           0 :             WRITE (*, *) "WARNING: try to cancel subtree, element ", elem%sub_tree_nr, elem%nr, ", with status ", elem%stat
      94             :          CASE DEFAULT
      95             :             CALL cp_abort(__LOCATION__, &
      96             :                           "try to add element with unknown status to cancelation list (stat=" &
      97        4523 :                           //cp_to_string(elem%stat))
      98             :          END SELECT
      99             :          ! set dot color
     100        4523 :          IF (tmc_env%params%DRAW_TREE) &
     101          46 :             CALL create_dot_color(tree_element=elem, tmc_params=tmc_env%params)
     102             : 
     103             :          ! add to list
     104        4523 :          IF (need_to_cancel) THEN
     105           1 :             CALL add_to_list(elem=elem, list=tmc_env%m_env%cancelation_list)
     106             :          END IF
     107             :       END IF
     108             :       ! end the timing
     109        4523 :       CALL timestop(handle)
     110        4523 :    END SUBROUTINE add_to_canceling_list
     111             : 
     112             : ! **************************************************************************************************
     113             : !> \brief for correct finalizing deallocate the cancelation list
     114             : !> \param cancel_list ...
     115             : !> \param
     116             : !> \author Mandes 12.2012
     117             : ! **************************************************************************************************
     118          14 :    SUBROUTINE free_cancelation_list(cancel_list)
     119             :       TYPE(elem_list_type), POINTER                      :: cancel_list
     120             : 
     121             :       TYPE(elem_list_type), POINTER                      :: tmp_element
     122             : 
     123          15 :       cancel_elem_loop: DO WHILE (ASSOCIATED(cancel_list))
     124           1 :          tmp_element => cancel_list%next
     125           1 :          DEALLOCATE (cancel_list)
     126           1 :          cancel_list => tmp_element
     127             :       END DO cancel_elem_loop
     128          14 :    END SUBROUTINE free_cancelation_list
     129             : 
     130             : END MODULE tmc_cancelation

Generated by: LCOV version 1.15