LCOV - code coverage report
Current view: top level - src - farming_types.F (source / functions) Hit Total Coverage
Test: CP2K Regtests (git:262480d) Lines: 34 35 97.1 %
Date: 2024-11-22 07:00:40 Functions: 4 6 66.7 %

          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             : MODULE farming_types
      10             : 
      11             :    USE kinds,                           ONLY: default_path_length,&
      12             :                                               dp
      13             : #include "./base/base_uses.f90"
      14             : 
      15             :    IMPLICIT NONE
      16             :    PRIVATE
      17             : 
      18             :    PUBLIC :: farming_env_type, deallocate_farming_env, init_farming_env, init_job_type
      19             : 
      20             :    INTEGER, PUBLIC, PARAMETER :: job_pending = 1, job_running = 2, job_finished = 3
      21             : 
      22             : ! **************************************************************************************************
      23             :    TYPE job_type
      24             :       CHARACTER(LEN=default_path_length) :: cwd = "" ! the directory to go to
      25             :       CHARACTER(LEN=default_path_length) :: input = "" ! the input file to use
      26             :       CHARACTER(LEN=default_path_length) :: output = "" ! the output file to use
      27             :       INTEGER                            :: ID = -1 ! the ID of this job
      28             :       INTEGER, POINTER, DIMENSION(:)     :: dependencies => NULL() ! the dependencies of this job
      29             :       INTEGER                            :: status = -1 ! pending,running,finished
      30             :    END TYPE job_type
      31             : 
      32             : ! **************************************************************************************************
      33             :    TYPE farming_env_type
      34             :       INTEGER :: group_size_wish = -1
      35             :       LOGICAL :: group_size_wish_set = .FALSE.
      36             :       INTEGER :: ngroup_wish = -1
      37             :       LOGICAL :: ngroup_wish_set = .FALSE.
      38             :       LOGICAL :: restart = .FALSE.
      39             :       LOGICAL :: CYCLE = .FALSE.
      40             :       LOGICAL :: captain_minion = .FALSE.
      41             :       INTEGER, DIMENSION(:), POINTER                              :: group_partition => NULL() ! user preference for partitioning the cpus
      42             :       CHARACTER(LEN=default_path_length)                          :: restart_file_name = "" ! restart file for farming
      43             :       CHARACTER(LEN=default_path_length)                          :: cwd = "" ! directory we started from
      44             :       INTEGER                                                     :: Njobs = -1 ! how many jobs to run
      45             :       INTEGER                                                     :: restart_n = -1 ! where to start
      46             :       INTEGER                                                     :: max_steps = -1 ! max number of steps,
      47             :       ! results in max_steps*Ngroup jobs being run
      48             :       INTEGER                                                     :: stride = -1 ! for creating minion groups.
      49             :       TYPE(job_type), DIMENSION(:), POINTER                       :: job => NULL() ! a list of jobs
      50             :       REAL(KIND=dp) :: wait_time = 0.0_dp
      51             :    END TYPE farming_env_type
      52             : 
      53             : CONTAINS
      54             : 
      55             : ! **************************************************************************************************
      56             : !> \brief help poor compilers do their job
      57             : !>       i.e. provide a default initialization
      58             : !> \param farming_env an associated farming env pointer
      59             : !> \par History
      60             : !>      03.2004 created [Joost VandeVondele ]
      61             : ! **************************************************************************************************
      62          24 :    SUBROUTINE init_farming_env(farming_env)
      63             :       TYPE(farming_env_type), POINTER                    :: farming_env
      64             : 
      65          24 :       IF (ASSOCIATED(farming_env)) THEN
      66          24 :          farming_env%group_size_wish = 0
      67          24 :          farming_env%group_size_wish_set = .FALSE.
      68          24 :          farming_env%ngroup_wish = 0
      69          24 :          farming_env%ngroup_wish_set = .FALSE.
      70          24 :          farming_env%restart = .FALSE.
      71          24 :          farming_env%restart_n = 1
      72          24 :          farming_env%cycle = .FALSE.
      73          24 :          farming_env%captain_minion = .FALSE.
      74          24 :          NULLIFY (farming_env%group_partition)
      75          24 :          farming_env%cwd = "."
      76          24 :          farming_env%Njobs = 0
      77             :          ! so that maxsteps*ngroup is (likely) not overflowing
      78          24 :          farming_env%max_steps = 65535
      79          24 :          NULLIFY (farming_env%Job)
      80             :       END IF
      81          24 :    END SUBROUTINE
      82             : 
      83             : ! **************************************************************************************************
      84             : !> \brief provide a default initialization
      85             : !> \param job ...
      86             : !> \par History
      87             : !>      09.2007 created [Joost VandeVondele ]
      88             : ! **************************************************************************************************
      89         160 :    ELEMENTAL SUBROUTINE init_job_type(job)
      90             :       TYPE(job_type), INTENT(OUT)                        :: job
      91             : 
      92         160 :       job%cwd = ""
      93         160 :       job%input = ""
      94         160 :       job%output = ""
      95             :       job%ID = -1
      96         160 :       job%status = job_pending
      97             :       NULLIFY (job%dependencies)
      98             : 
      99         160 :    END SUBROUTINE init_job_type
     100             : 
     101             : ! **************************************************************************************************
     102             : !> \brief deallocates all memory associated with this job
     103             : !> \param job ...
     104             : !> \par History
     105             : !>      09.2007 created [Joost VandeVondele ]
     106             : ! **************************************************************************************************
     107         160 :    SUBROUTINE deallocate_job_type(job)
     108             :       TYPE(job_type)                                     :: job
     109             : 
     110         160 :       IF (ASSOCIATED(job%dependencies)) DEALLOCATE (job%dependencies)
     111             : 
     112         160 :    END SUBROUTINE deallocate_job_type
     113             : 
     114             : ! **************************************************************************************************
     115             : !> \brief deallocates all associated fields of the farming_env type
     116             : !>      and the type itself
     117             : !> \param farming_env ...
     118             : !> \par History
     119             : !>      03.2004 created [Joost VandeVondele]
     120             : ! **************************************************************************************************
     121          24 :    SUBROUTINE deallocate_farming_env(farming_env)
     122             :       TYPE(farming_env_type), POINTER                    :: farming_env
     123             : 
     124             :       INTEGER                                            :: I
     125             : 
     126          24 :       IF (ASSOCIATED(farming_env)) THEN
     127          24 :          IF (ASSOCIATED(farming_env%job)) THEN
     128         184 :             DO I = 1, SIZE(farming_env%job, 1)
     129         184 :                CALL deallocate_job_type(farming_env%job(I))
     130             :             END DO
     131          24 :             DEALLOCATE (farming_env%job)
     132             :          END IF
     133          24 :          IF (ASSOCIATED(farming_env%group_partition)) DEALLOCATE (farming_env%group_partition)
     134          24 :          DEALLOCATE (farming_env) ! and the type itself
     135             :       END IF
     136          24 :    END SUBROUTINE deallocate_farming_env
     137           0 : END MODULE farming_types

Generated by: LCOV version 1.15