LCOV - code coverage report
Current view: top level - src/input - cp_parser_buffer_types.F (source / functions) Hit Total Coverage
Test: CP2K Regtests (git:b1c14e6) Lines: 49 52 94.2 %
Date: 2022-07-02 11:36:49 Functions: 5 7 71.4 %

          Line data    Source code
       1             : !--------------------------------------------------------------------------------------------------!
       2             : !   CP2K: A general program to perform molecular dynamics simulations                              !
       3             : !   Copyright 2000-2022 CP2K developers group <https://cp2k.org>                                   !
       4             : !                                                                                                  !
       5             : !   SPDX-License-Identifier: GPL-2.0-or-later                                                      !
       6             : !--------------------------------------------------------------------------------------------------!
       7             : 
       8             : ! **************************************************************************************************
       9             : !> \brief a module to allow simple buffering of read lines of a parser
      10             : !> \author Teodoro Laino [tlaino] - University of Zurich
      11             : !> \date 08.2008
      12             : ! **************************************************************************************************
      13             : MODULE cp_parser_buffer_types
      14             : 
      15             :    USE kinds,                           ONLY: max_line_length
      16             : #include "../base/base_uses.f90"
      17             : 
      18             :    IMPLICIT NONE
      19             :    PRIVATE
      20             : 
      21             : ! ****************************************************************************
      22             : !> \brief  Buffer type for speeding-up the parsing in parallel
      23             : !> \author Teodoro Laino [tlaino] - University of Zurich
      24             : !> \date   08.2008
      25             : ! **************************************************************************************************
      26             :    TYPE buffer_type
      27             :       INTEGER                              :: size, buffer_id
      28             :       INTEGER                              :: present_line_number, &
      29             :                                               last_line_number, &
      30             :                                               istat
      31             :       INTEGER, DIMENSION(:), POINTER       :: input_line_numbers
      32             :       CHARACTER(LEN=max_line_length), &
      33             :          DIMENSION(:), POINTER           :: input_lines
      34             :       TYPE(buffer_type), POINTER           :: sub_buffer
      35             :    END TYPE buffer_type
      36             : 
      37             :    PUBLIC :: buffer_type, create_buffer_type, release_buffer_type, copy_buffer_type, &
      38             :              initialize_sub_buffer, finalize_sub_buffer
      39             :    CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'cp_parser_buffer_types'
      40             :    INTEGER, PARAMETER, PRIVATE          :: buffer_size = 1000
      41             : 
      42             : CONTAINS
      43             : 
      44             : ! ****************************************************************************
      45             : !> \brief  Creates the parser buffer type
      46             : !> \param buffer ...
      47             : !> \date   08.2008
      48             : !> \author Teodoro Laino [tlaino] - University of Zurich
      49             : ! **************************************************************************************************
      50       94212 :    SUBROUTINE create_buffer_type(buffer)
      51             :       TYPE(buffer_type), POINTER                         :: buffer
      52             : 
      53       94212 :       CPASSERT(.NOT. ASSOCIATED(buffer))
      54       94212 :       ALLOCATE (buffer)
      55       94212 :       buffer%size = buffer_size
      56       94212 :       ALLOCATE (buffer%input_lines(buffer%size))
      57       94212 :       ALLOCATE (buffer%input_line_numbers(buffer%size))
      58       94212 :       buffer%buffer_id = 0
      59    94306212 :       buffer%input_line_numbers = 0
      60       94212 :       buffer%istat = 0
      61       94212 :       buffer%present_line_number = buffer%size
      62       94212 :       buffer%last_line_number = buffer%size
      63       94212 :       NULLIFY (buffer%sub_buffer)
      64       94212 :    END SUBROUTINE create_buffer_type
      65             : 
      66             : ! ****************************************************************************
      67             : !> \brief  Releases the parser buffer type
      68             : !> \param buffer ...
      69             : !> \date   08.2008
      70             : !> \author Teodoro Laino [tlaino] - University of Zurich
      71             : ! **************************************************************************************************
      72       94212 :    RECURSIVE SUBROUTINE release_buffer_type(buffer)
      73             :       TYPE(buffer_type), POINTER                         :: buffer
      74             : 
      75       94212 :       CPASSERT(ASSOCIATED(buffer))
      76       94212 :       DEALLOCATE (buffer%input_lines)
      77       94212 :       DEALLOCATE (buffer%input_line_numbers)
      78       94212 :       IF (ASSOCIATED(buffer%sub_buffer)) THEN
      79           0 :          CALL release_buffer_type(buffer%sub_buffer)
      80             :       END IF
      81       94212 :       DEALLOCATE (buffer)
      82       94212 :    END SUBROUTINE release_buffer_type
      83             : 
      84             : ! ****************************************************************************
      85             : !> \brief  Copies  buffer types
      86             : !> \param buffer_in ...
      87             : !> \param buffer_out ...
      88             : !> \param force ...
      89             : !> \date   08.2008
      90             : !> \author Teodoro Laino [tlaino] - University of Zurich
      91             : ! **************************************************************************************************
      92    20537668 :    RECURSIVE SUBROUTINE copy_buffer_type(buffer_in, buffer_out, force)
      93             :       TYPE(buffer_type), POINTER                         :: buffer_in, buffer_out
      94             :       LOGICAL, INTENT(IN), OPTIONAL                      :: force
      95             : 
      96             :       INTEGER                                            :: i
      97             :       LOGICAL                                            :: my_force
      98             : 
      99    20537668 :       CPASSERT(ASSOCIATED(buffer_in))
     100    20537668 :       CPASSERT(ASSOCIATED(buffer_out))
     101    20537668 :       CPASSERT(buffer_in%size == buffer_out%size)
     102    20537668 :       my_force = .FALSE.
     103    20537668 :       IF (PRESENT(force)) my_force = force
     104             :       ! Copy buffer structure
     105    20537668 :       buffer_out%present_line_number = buffer_in%present_line_number
     106    20537668 :       buffer_out%last_line_number = buffer_in%last_line_number
     107    20537668 :       buffer_out%istat = buffer_in%istat
     108             :       ! This part can be quite expensive.. we do it only when strictly necessary..
     109    20537668 :       IF ((buffer_out%buffer_id /= buffer_in%buffer_id) .OR. (my_force)) THEN
     110       31048 :          buffer_out%buffer_id = buffer_in%buffer_id
     111    62158096 :          buffer_out%input_line_numbers = buffer_in%input_line_numbers
     112             :          ! Explicit loop: bypass a NAG bug..
     113    31079048 :          DO i = 1, SIZE(buffer_in%input_lines)
     114    51585668 :             buffer_out%input_lines(i) = buffer_in%input_lines(i)
     115             :          END DO
     116             :       END IF
     117    20537668 :       IF (ASSOCIATED(buffer_in%sub_buffer) .AND. ASSOCIATED(buffer_out%sub_buffer)) THEN
     118           0 :          CALL copy_buffer_type(buffer_in%sub_buffer, buffer_out%sub_buffer, force)
     119             :       END IF
     120    20537668 :    END SUBROUTINE copy_buffer_type
     121             : 
     122             : ! ****************************************************************************
     123             : !> \brief  Initializes sub buffer structure
     124             : !> \param sub_buffer ...
     125             : !> \param buffer ...
     126             : !> \date   08.2008
     127             : !> \author Teodoro Laino [tlaino] - University of Zurich
     128             : ! **************************************************************************************************
     129        1238 :    SUBROUTINE initialize_sub_buffer(sub_buffer, buffer)
     130             :       TYPE(buffer_type), POINTER                         :: sub_buffer, buffer
     131             : 
     132        1238 :       CPASSERT(ASSOCIATED(buffer))
     133        1238 :       CPASSERT(.NOT. ASSOCIATED(sub_buffer))
     134        1238 :       CALL create_buffer_type(sub_buffer)
     135        1238 :       CALL copy_buffer_type(buffer, sub_buffer)
     136        1238 :       sub_buffer%present_line_number = 0
     137        1238 :    END SUBROUTINE initialize_sub_buffer
     138             : 
     139             : ! ****************************************************************************
     140             : !> \brief  Finalizes sub buffer structure
     141             : !> \param sub_buffer ...
     142             : !> \param buffer ...
     143             : !> \date   08.2008
     144             : !> \author Teodoro Laino [tlaino] - University of Zurich
     145             : ! **************************************************************************************************
     146        1238 :    SUBROUTINE finalize_sub_buffer(sub_buffer, buffer)
     147             :       TYPE(buffer_type), POINTER                         :: sub_buffer, buffer
     148             : 
     149        1238 :       CPASSERT(ASSOCIATED(buffer))
     150        1238 :       CPASSERT(ASSOCIATED(sub_buffer))
     151        1238 :       CALL copy_buffer_type(sub_buffer, buffer)
     152        1238 :       CALL release_buffer_type(sub_buffer)
     153        1238 :    END SUBROUTINE finalize_sub_buffer
     154             : 
     155           0 : END MODULE cp_parser_buffer_types

Generated by: LCOV version 1.15