LCOV - code coverage report
Current view: top level - src - semi_empirical_store_int_types.F (source / functions) Hit Total Coverage
Test: CP2K Regtests (git:ccc2433) Lines: 75 78 96.2 %
Date: 2024-04-25 07:09:54 Functions: 4 5 80.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 Type to store integrals for semi-empirical calculations
      10             : !> \author Teodoro Laino [tlaino] - University of Zurich
      11             : !> \date   05.2008
      12             : ! **************************************************************************************************
      13             : MODULE semi_empirical_store_int_types
      14             : 
      15             :    USE hfx_compression_methods,         ONLY: hfx_decompress_first_cache,&
      16             :                                               hfx_flush_last_cache,&
      17             :                                               hfx_reset_cache_and_container
      18             :    USE hfx_types,                       ONLY: hfx_cache_type,&
      19             :                                               hfx_container_type,&
      20             :                                               hfx_init_container,&
      21             :                                               hfx_memory_type,&
      22             :                                               parse_memory_section
      23             :    USE input_section_types,             ONLY: section_vals_get_subs_vals,&
      24             :                                               section_vals_type,&
      25             :                                               section_vals_val_get
      26             :    USE kinds,                           ONLY: dp
      27             :    USE memory_utilities,                ONLY: reallocate
      28             : #include "./base/base_uses.f90"
      29             : 
      30             :    IMPLICIT NONE
      31             : 
      32             :    PRIVATE
      33             : 
      34             : ! *** Global parameters ***
      35             : 
      36             :    CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'semi_empirical_store_int_types'
      37             : 
      38             : ! **************************************************************************************************
      39             : !> \brief Semi-empirical store integrals type
      40             : !> \author Teodoro Laino [tlaino] - University of Zurich
      41             : !> \date   05.2008
      42             : ! **************************************************************************************************
      43             :    TYPE semi_empirical_si_type
      44             :       LOGICAL                                     :: filling_containers, compress
      45             :       INTEGER                                     :: nbuffer
      46             :       REAL(KIND=dp), POINTER, DIMENSION(:)        :: max_val_buffer, uncompressed_container
      47             :       TYPE(hfx_memory_type)                       :: memory_parameter
      48             :       TYPE(hfx_cache_type), DIMENSION(:), &
      49             :          POINTER                                :: integral_caches
      50             :       TYPE(hfx_container_type), DIMENSION(:), &
      51             :          POINTER                                :: integral_containers
      52             :    END TYPE semi_empirical_si_type
      53             : 
      54             :    PUBLIC :: semi_empirical_si_type, &
      55             :              semi_empirical_si_create, &
      56             :              semi_empirical_si_release, &
      57             :              semi_empirical_si_finalize, &
      58             :              semi_empirical_si_initialize
      59             : 
      60             : CONTAINS
      61             : 
      62             : ! **************************************************************************************************
      63             : !> \brief Allocate semi-empirical store integrals type
      64             : !> \param store_int_env ...
      65             : !> \param se_section ...
      66             : !> \param compression ...
      67             : !> \date   05.2008
      68             : !> \author Teodoro Laino [tlaino] - University of Zurich
      69             : ! **************************************************************************************************
      70         998 :    SUBROUTINE semi_empirical_si_create(store_int_env, se_section, compression)
      71             :       TYPE(semi_empirical_si_type), POINTER              :: store_int_env
      72             :       TYPE(section_vals_type), POINTER                   :: se_section
      73             :       LOGICAL, INTENT(in), OPTIONAL                      :: compression
      74             : 
      75             :       INTEGER                                            :: i
      76             :       TYPE(section_vals_type), POINTER                   :: se_mem_section
      77             : 
      78         998 :       CPASSERT(.NOT. ASSOCIATED(store_int_env))
      79         998 :       ALLOCATE (store_int_env)
      80         998 :       store_int_env%filling_containers = .TRUE.
      81         998 :       store_int_env%nbuffer = 0
      82         998 :       NULLIFY (store_int_env%max_val_buffer, store_int_env%uncompressed_container)
      83             : 
      84             :       ! Memory section
      85         998 :       se_mem_section => section_vals_get_subs_vals(se_section, "MEMORY")
      86         998 :       IF (PRESENT(compression)) THEN
      87           0 :          store_int_env%compress = compression
      88             :       ELSE
      89         998 :          CALL section_vals_val_get(se_mem_section, "COMPRESS", l_val=store_int_env%compress)
      90             :       END IF
      91             :       CALL parse_memory_section(store_int_env%memory_parameter, se_mem_section, skip_disk=.TRUE., &
      92         998 :                                 skip_in_core_forces=.TRUE.)
      93         998 :       store_int_env%memory_parameter%ram_counter = 0
      94             :       ! If we don't compress there's no cache
      95         998 :       IF (.NOT. store_int_env%compress) THEN
      96         994 :          store_int_env%memory_parameter%cache_size = 1
      97             :       END IF
      98             : 
      99             :       ! Disk Storage disabled for semi-empirical methods
     100         998 :       IF (store_int_env%memory_parameter%do_disk_storage) &
     101           0 :          CPABORT("Disk storage for SEMIEMPIRICAL methods disabled! ")
     102             : 
     103             :       ! Allocate containers/caches for integral storage if requested
     104         998 :       IF (.NOT. store_int_env%memory_parameter%do_all_on_the_fly .AND. store_int_env%compress) THEN
     105         260 :          ALLOCATE (store_int_env%integral_containers(64))
     106        4356 :          ALLOCATE (store_int_env%integral_caches(64))
     107         260 :          DO i = 1, 64
     108         256 :             store_int_env%integral_caches(i)%element_counter = 1
     109      262400 :             store_int_env%integral_caches(i)%data = 0
     110      262656 :             ALLOCATE (store_int_env%integral_containers(i)%first)
     111         256 :             store_int_env%integral_containers(i)%first%prev => NULL()
     112         256 :             store_int_env%integral_containers(i)%first%next => NULL()
     113         256 :             store_int_env%integral_containers(i)%current => store_int_env%integral_containers(i)%first
     114      262400 :             store_int_env%integral_containers(i)%current%data = 0
     115         260 :             store_int_env%integral_containers(i)%element_counter = 1
     116             :          END DO
     117             :       END IF
     118         998 :    END SUBROUTINE semi_empirical_si_create
     119             : 
     120             : ! **************************************************************************************************
     121             : !> \brief Deallocate the semi-empirical store integrals type
     122             : !> \param store_int_env ...
     123             : !> \date   05.2008
     124             : !> \author Teodoro Laino [tlaino] - University of Zurich
     125             : ! **************************************************************************************************
     126        1996 :    SUBROUTINE semi_empirical_si_release(store_int_env)
     127             :       TYPE(semi_empirical_si_type), POINTER              :: store_int_env
     128             : 
     129             :       INTEGER                                            :: i
     130             : 
     131        1996 :       IF (ASSOCIATED(store_int_env)) THEN
     132             :          ! Deallocate containers/caches
     133         998 :          IF (.NOT. store_int_env%memory_parameter%do_all_on_the_fly) THEN
     134         998 :             IF (store_int_env%compress) THEN
     135             :                ! Deallocate containers/caches
     136         260 :                DO i = 1, 64
     137             :                   CALL hfx_init_container(store_int_env%integral_containers(i), &
     138             :                                           store_int_env%memory_parameter%actual_memory_usage, &
     139         256 :                                           .FALSE.)
     140         260 :                   DEALLOCATE (store_int_env%integral_containers(i)%first)
     141             :                END DO
     142           4 :                IF (ASSOCIATED(store_int_env%max_val_buffer)) THEN
     143           4 :                   DEALLOCATE (store_int_env%max_val_buffer)
     144             :                END IF
     145           4 :                DEALLOCATE (store_int_env%integral_containers)
     146           4 :                DEALLOCATE (store_int_env%integral_caches)
     147             :             ELSE
     148         994 :                IF (ASSOCIATED(store_int_env%uncompressed_container)) THEN
     149         346 :                   DEALLOCATE (store_int_env%uncompressed_container)
     150             :                END IF
     151             :             END IF
     152             :          END IF
     153             :          ! Deallocate the full store_int_env
     154         998 :          DEALLOCATE (store_int_env)
     155             :       END IF
     156             : 
     157        1996 :    END SUBROUTINE semi_empirical_si_release
     158             : 
     159             : ! **************************************************************************************************
     160             : !> \brief Deallocate the semi-empirical store integrals type
     161             : !> \param store_int_env ...
     162             : !> \param geometry_did_change ...
     163             : !> \date   05.2008
     164             : !> \author Teodoro Laino [tlaino] - University of Zurich
     165             : ! **************************************************************************************************
     166       41070 :    SUBROUTINE semi_empirical_si_initialize(store_int_env, geometry_did_change)
     167             :       TYPE(semi_empirical_si_type), POINTER              :: store_int_env
     168             :       LOGICAL, INTENT(IN)                                :: geometry_did_change
     169             : 
     170             :       INTEGER                                            :: i
     171             : 
     172       41070 :       IF (ASSOCIATED(store_int_env)) THEN
     173       41070 :          IF (.NOT. store_int_env%memory_parameter%do_all_on_the_fly) THEN
     174       41070 :             IF (geometry_did_change) THEN
     175        3766 :                store_int_env%filling_containers = .TRUE.
     176        3766 :                store_int_env%nbuffer = 0
     177        3766 :                store_int_env%memory_parameter%ram_counter = HUGE(store_int_env%memory_parameter%ram_counter)
     178        3766 :                IF (store_int_env%compress) THEN
     179             :                   ! Compress integrals
     180           6 :                   CALL reallocate(store_int_env%max_val_buffer, 1, store_int_env%nbuffer)
     181             :                   ! Clean containers
     182         390 :                   DO i = 1, 64
     183             :                      CALL hfx_init_container(store_int_env%integral_containers(i), &
     184             :                                              store_int_env%memory_parameter%actual_memory_usage, &
     185         390 :                                              .FALSE.)
     186             :                   END DO
     187             :                ELSE
     188             :                   ! Skip compression
     189        3760 :                   CALL reallocate(store_int_env%uncompressed_container, 1, 0)
     190        3760 :                   store_int_env%memory_parameter%actual_memory_usage = 1
     191             :                END IF
     192             :             ELSE
     193       37304 :                store_int_env%filling_containers = .FALSE.
     194       37304 :                store_int_env%nbuffer = 0
     195       37304 :                IF (store_int_env%compress) THEN
     196             :                   ! Retrieve data into the cache
     197        8710 :                   DO i = 1, 64
     198             :                      CALL hfx_decompress_first_cache(i, store_int_env%integral_caches(i), &
     199             :                                                      store_int_env%integral_containers(i), &
     200        8710 :                                                      store_int_env%memory_parameter%actual_memory_usage, .FALSE.)
     201             :                   END DO
     202             :                ELSE
     203       37170 :                   store_int_env%memory_parameter%actual_memory_usage = 1
     204             :                END IF
     205             :             END IF
     206             :          END IF
     207             :       END IF
     208             : 
     209       41070 :    END SUBROUTINE semi_empirical_si_initialize
     210             : 
     211             : ! **************************************************************************************************
     212             : !> \brief Deallocate the semi-empirical store integrals type
     213             : !> \param store_int_env ...
     214             : !> \param geometry_did_change ...
     215             : !> \date   05.2008
     216             : !> \author Teodoro Laino [tlaino] - University of Zurich
     217             : ! **************************************************************************************************
     218       41070 :    SUBROUTINE semi_empirical_si_finalize(store_int_env, geometry_did_change)
     219             :       TYPE(semi_empirical_si_type), POINTER              :: store_int_env
     220             :       LOGICAL, INTENT(IN)                                :: geometry_did_change
     221             : 
     222             :       INTEGER                                            :: i
     223             : 
     224       41070 :       IF (ASSOCIATED(store_int_env)) THEN
     225       41070 :          IF (.NOT. store_int_env%memory_parameter%do_all_on_the_fly) THEN
     226       41070 :             IF (geometry_did_change) THEN
     227        3766 :                IF (store_int_env%compress) THEN
     228             :                   ! Flush last cache
     229         390 :                   DO i = 1, 64
     230             :                      CALL hfx_flush_last_cache(i, store_int_env%integral_caches(i), &
     231             :                                                store_int_env%integral_containers(i), &
     232         390 :                                                store_int_env%memory_parameter%actual_memory_usage, .FALSE.)
     233             :                   END DO
     234             :                   ! Reallocate this array with the proper size
     235           6 :                   CALL reallocate(store_int_env%max_val_buffer, 1, store_int_env%nbuffer)
     236             :                ELSE
     237             :                   ! Skip compression
     238             :                   CALL reallocate(store_int_env%uncompressed_container, 1, &
     239        3760 :                                   store_int_env%memory_parameter%actual_memory_usage - 1)
     240             :                END IF
     241             :             END IF
     242       41070 :             IF (store_int_env%compress) THEN
     243             :                ! Reset caches and containers
     244        9100 :                DO i = 1, 64
     245             :                   CALL hfx_reset_cache_and_container( &
     246             :                      store_int_env%integral_caches(i), &
     247             :                      store_int_env%integral_containers(i), store_int_env%memory_parameter%actual_memory_usage, &
     248        9100 :                      .FALSE.)
     249             :                END DO
     250             :             END IF
     251             :          END IF
     252             :       END IF
     253             : 
     254       41070 :    END SUBROUTINE semi_empirical_si_finalize
     255             : 
     256           0 : END MODULE semi_empirical_store_int_types

Generated by: LCOV version 1.15