LCOV - code coverage report
Current view: top level - src - mixed_main.F (source / functions) Hit Total Coverage
Test: CP2K Regtests (git:4dc10b3) Lines: 56 57 98.2 %
Date: 2024-11-21 06:45:46 Functions: 1 1 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 perform biased molecular dynamics (H= k H1 + (1-k) H2 [linear or general mixing)
      10             : !> \author fschiff 11.06
      11             : ! **************************************************************************************************
      12             : MODULE mixed_main
      13             :    USE cp_files,                        ONLY: open_file
      14             :    USE cp_log_handling,                 ONLY: cp_get_default_logger,&
      15             :                                               cp_logger_create,&
      16             :                                               cp_logger_set,&
      17             :                                               cp_logger_type,&
      18             :                                               cp_to_string
      19             :    USE cp_output_handling,              ONLY: cp_print_key_unit_nr
      20             :    USE input_section_types,             ONLY: section_vals_type,&
      21             :                                               section_vals_val_get
      22             :    USE kinds,                           ONLY: default_path_length
      23             :    USE message_passing,                 ONLY: mp_para_env_type
      24             :    USE mixed_environment,               ONLY: mixed_init
      25             :    USE mixed_environment_types,         ONLY: mixed_env_create,&
      26             :                                               mixed_environment_type
      27             : #include "./base/base_uses.f90"
      28             : 
      29             :    IMPLICIT NONE
      30             : 
      31             :    PRIVATE
      32             : 
      33             : ! *** Global parameters ***
      34             :    CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'mixed_main'
      35             : 
      36             :    PUBLIC :: mixed_create_force_env
      37             : 
      38             : CONTAINS
      39             : ! **************************************************************************************************
      40             : !> \brief Controls program flow for mixed calculations
      41             : !> \param mixed_env ...
      42             : !> \param root_section ...
      43             : !> \param para_env ...
      44             : !> \param force_env_section ...
      45             : !> \param n_subforce_eval ...
      46             : !> \param use_motion_section ...
      47             : !> \author fschiff
      48             : ! **************************************************************************************************
      49           0 :    SUBROUTINE mixed_create_force_env(mixed_env, root_section, para_env, &
      50             :                                      force_env_section, n_subforce_eval, use_motion_section)
      51             : 
      52             :       TYPE(mixed_environment_type), INTENT(OUT)          :: mixed_env
      53             :       TYPE(section_vals_type), POINTER                   :: root_section
      54             :       TYPE(mp_para_env_type), POINTER                    :: para_env
      55             :       TYPE(section_vals_type), POINTER                   :: force_env_section
      56             :       INTEGER, INTENT(IN)                                :: n_subforce_eval
      57             :       LOGICAL, INTENT(IN)                                :: use_motion_section
      58             : 
      59             :       CHARACTER(LEN=*), PARAMETER :: routineN = 'mixed_create_force_env'
      60             : 
      61             :       CHARACTER(len=default_path_length)                 :: c_val, input_file_path, output_file_path
      62             :       INTEGER                                            :: group_size_wish, handle, i, lp, &
      63             :                                                             n_rep_val, ngroup_wish, output_unit, &
      64             :                                                             unit_nr
      65         130 :       INTEGER, DIMENSION(:), POINTER                     :: group_partition, i_vals
      66             :       TYPE(cp_logger_type), POINTER                      :: logger
      67             :       TYPE(mp_para_env_type), POINTER                    :: sub_para_env
      68             : 
      69         130 :       CALL timeset(routineN, handle)
      70         130 :       logger => cp_get_default_logger()
      71             :       output_unit = cp_print_key_unit_nr(logger, force_env_section, "MIXED%PRINT%PROGRAM_RUN_INFO", &
      72         130 :                                          extension=".log")
      73             : 
      74         130 :       CALL mixed_env_create(mixed_env, para_env=para_env)
      75             :       ! Setup the new parallel env
      76         130 :       NULLIFY (group_partition)
      77         130 :       CALL section_vals_val_get(force_env_section, "MIXED%GROUP_PARTITION", n_rep_val=n_rep_val)
      78             : 
      79             :       ! Split the current communicator
      80         390 :       ALLOCATE (mixed_env%group_distribution(0:para_env%num_pe - 1))
      81         130 :       ALLOCATE (sub_para_env)
      82         130 :       IF (n_rep_val > 0) THEN
      83          26 :          CALL section_vals_val_get(force_env_section, "MIXED%GROUP_PARTITION", i_vals=i_vals)
      84          78 :          ALLOCATE (group_partition(0:SIZE(i_vals) - 1))
      85         130 :          group_partition(:) = i_vals
      86          26 :          ngroup_wish = SIZE(i_vals)
      87             : 
      88             :          CALL sub_para_env%from_split(para_env, mixed_env%ngroups, mixed_env%group_distribution, &
      89             :                                       n_subgroups=ngroup_wish, &
      90          26 :                                       group_partition=group_partition)
      91             :       ELSE
      92         104 :          CALL section_vals_val_get(force_env_section, "MIXED%NGROUPS", n_rep_val=n_rep_val)
      93         104 :          IF (n_rep_val > 0) THEN
      94          76 :             CALL section_vals_val_get(force_env_section, "MIXED%NGROUPS", i_val=ngroup_wish)
      95             :          ELSE
      96          28 :             ngroup_wish = n_subforce_eval
      97             :          END IF
      98         104 :          group_size_wish = MAX(1, para_env%num_pe/ngroup_wish)
      99             : 
     100             :          CALL sub_para_env%from_split(para_env, mixed_env%ngroups, mixed_env%group_distribution, &
     101         104 :                                       subgroup_min_size=group_size_wish)
     102             :       END IF
     103             : 
     104         130 :       IF (output_unit > 0) THEN
     105          65 :          WRITE (output_unit, FMT="(T2,A,T71,I10)") "MIXED_ENV| Number of created MPI groups:", mixed_env%ngroups
     106          65 :          WRITE (output_unit, FMT="(T2,A)", ADVANCE="NO") "MIXED_ENV| Task to group correspondence:"
     107         195 :          DO i = 0, para_env%num_pe - 1
     108         130 :             IF (MODULO(i, 4) == 0) WRITE (output_unit, *)
     109             :             WRITE (output_unit, FMT='(A3,I4,A3,I4,A1)', ADVANCE="NO") &
     110         195 :                "  (", i, " : ", mixed_env%group_distribution(i), ")"
     111             :          END DO
     112          65 :          WRITE (output_unit, *)
     113             :       END IF
     114         130 :       IF (ASSOCIATED(group_partition)) THEN
     115          26 :          DEALLOCATE (group_partition)
     116             :       END IF
     117             :       ! Allocate para_env and handle the several loggers
     118         600 :       ALLOCATE (mixed_env%sub_para_env(mixed_env%ngroups))
     119         600 :       ALLOCATE (mixed_env%sub_logger(mixed_env%ngroups))
     120         390 :       ALLOCATE (mixed_env%energies(n_subforce_eval))
     121             :       !
     122         130 :       NULLIFY (logger)
     123         130 :       i = mixed_env%group_distribution(para_env%mepos) + 1
     124             :       ! Create sub_para_env
     125         130 :       mixed_env%sub_para_env(i)%para_env => sub_para_env
     126             :       ! Create sub_logger
     127         130 :       IF (mixed_env%sub_para_env(i)%para_env%is_source()) THEN
     128             :          ! Redirecting output of subforce_eval to file..
     129             :          CALL section_vals_val_get(root_section, "GLOBAL%PROJECT_NAME", &
     130         105 :                                    c_val=input_file_path)
     131         105 :          lp = LEN_TRIM(input_file_path)
     132             :          input_file_path(lp + 1:LEN(input_file_path)) = "-r-"// &
     133         105 :                                                         ADJUSTL(cp_to_string(i))
     134         105 :          lp = LEN_TRIM(input_file_path)
     135         105 :          output_file_path = input_file_path(1:lp)//".out"
     136             :          CALL open_file(file_name=output_file_path, file_status="UNKNOWN", &
     137             :                         file_action="WRITE", file_position="APPEND", &
     138         105 :                         unit_number=unit_nr)
     139             :       ELSE
     140          25 :          unit_nr = -1
     141             :       END IF
     142             :       CALL cp_logger_create(mixed_env%sub_logger(i)%p, &
     143             :                             para_env=mixed_env%sub_para_env(i)%para_env, &
     144             :                             default_global_unit_nr=unit_nr, &
     145         130 :                             close_global_unit_on_dealloc=.FALSE.)
     146             :       ! Try to use better names for the local log if it is not too late
     147             :       CALL section_vals_val_get(root_section, "GLOBAL%OUTPUT_FILE_NAME", &
     148         130 :                                 c_val=c_val)
     149         130 :       IF (c_val /= "") THEN
     150             :          CALL cp_logger_set(mixed_env%sub_logger(i)%p, &
     151           6 :                             local_filename=TRIM(c_val)//"_localLog")
     152             :       END IF
     153         130 :       CALL section_vals_val_get(root_section, "GLOBAL%PROJECT", c_val=c_val)
     154         130 :       IF (c_val /= "") THEN
     155             :          CALL cp_logger_set(mixed_env%sub_logger(i)%p, &
     156         130 :                             local_filename=TRIM(c_val)//"_localLog")
     157             :       END IF
     158         130 :       mixed_env%sub_logger(i)%p%iter_info%project_name = c_val
     159             :       CALL section_vals_val_get(root_section, "GLOBAL%PRINT_LEVEL", &
     160         130 :                                 i_val=mixed_env%sub_logger(i)%p%iter_info%print_level)
     161             : 
     162             :       ! *** initializations for the setup of the MIXED environment ***
     163             :       CALL mixed_init(mixed_env, root_section, para_env, force_env_section, &
     164         130 :                       use_motion_section)
     165         130 :       CALL timestop(handle)
     166             : 
     167         260 :    END SUBROUTINE mixed_create_force_env
     168             : 
     169             : END MODULE mixed_main

Generated by: LCOV version 1.15