(git:15c1bfc)
Loading...
Searching...
No Matches
embed_main.F
Go to the documentation of this file.
1!--------------------------------------------------------------------------------------------------!
2! CP2K: A general program to perform molecular dynamics simulations !
3! Copyright 2000-2025 CP2K developers group <https://cp2k.org> !
4! !
5! SPDX-License-Identifier: GPL-2.0-or-later !
6!--------------------------------------------------------------------------------------------------!
7
8! **************************************************************************************************
9!> \brief Main force create for embedding
10!> \author Vladimir Rybkin 02.2018
11! **************************************************************************************************
13 USE cp_files, ONLY: open_file
21 USE embed_types, ONLY: embed_env_create,&
25 USE kinds, ONLY: default_path_length,&
28#include "./base/base_uses.f90"
29
30 IMPLICIT NONE
31
32 PRIVATE
33
34 ! Global parameters
35 CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'embed_main'
36
38
39CONTAINS
40! **************************************************************************************************
41!> \brief Controls program flow for embedded calculations
42!> \param embed_env ...
43!> \param root_section ...
44!> \param para_env ...
45!> \param force_env_section ...
46!> \param n_subforce_eval ...
47!> \param use_motion_section ...
48!> \author Vladimir Rybkin
49! **************************************************************************************************
50 SUBROUTINE embed_create_force_env(embed_env, root_section, para_env, &
51 force_env_section, n_subforce_eval, use_motion_section)
52
53 TYPE(embed_env_type), INTENT(OUT) :: embed_env
54 TYPE(section_vals_type), POINTER :: root_section
55 TYPE(mp_para_env_type), POINTER :: para_env
56 TYPE(section_vals_type), POINTER :: force_env_section
57 INTEGER, INTENT(IN) :: n_subforce_eval
58 LOGICAL, INTENT(IN) :: use_motion_section
59
60 CHARACTER(LEN=*), PARAMETER :: routinen = 'embed_create_force_env'
61
62 CHARACTER(len=default_path_length) :: c_val, input_file_path, output_file_path
63 INTEGER :: group_size_wish, handle, i, lp, &
64 n_rep_val, ngroup_wish, output_unit, &
65 unit_nr
66 INTEGER, DIMENSION(:), POINTER :: group_partition, i_vals
67 TYPE(cp_logger_type), POINTER :: logger
68 TYPE(mp_para_env_type), POINTER :: sub_para_env
69
70 CALL timeset(routinen, handle)
71 logger => cp_get_default_logger()
72 output_unit = cp_print_key_unit_nr(logger, force_env_section, "EMBED%PRINT%PROGRAM_RUN_INFO", &
73 extension=".log")
74
75 CALL embed_env_create(embed_env, para_env=para_env)
76 ! Setup the new parallel env
77 NULLIFY (group_partition)
78 CALL section_vals_val_get(force_env_section, "EMBED%GROUP_PARTITION", n_rep_val=n_rep_val)
79
80 ! Split the current communicator
81 ALLOCATE (embed_env%group_distribution(0:para_env%num_pe - 1))
82 ALLOCATE (sub_para_env)
83 IF (n_rep_val > 0) THEN
84 CALL section_vals_val_get(force_env_section, "EMBED%GROUP_PARTITION", i_vals=i_vals)
85 ALLOCATE (group_partition(0:SIZE(i_vals) - 1))
86 group_partition(:) = i_vals
87 ngroup_wish = SIZE(i_vals)
88
89 CALL sub_para_env%from_split(para_env, embed_env%ngroups, embed_env%group_distribution, &
90 n_subgroups=ngroup_wish, &
91 group_partition=group_partition)
92 ELSE
93 CALL section_vals_val_get(force_env_section, "EMBED%NGROUPS", n_rep_val=n_rep_val)
94 IF (n_rep_val > 0) THEN
95 CALL section_vals_val_get(force_env_section, "EMBED%NGROUPS", i_val=ngroup_wish)
96 IF (ngroup_wish .NE. 1) cpabort("Embedding runs with NGROUP=1 and no group partitioning")
97 ELSE
98 ngroup_wish = n_subforce_eval
99 END IF
100 group_size_wish = max(1, para_env%num_pe/ngroup_wish)
101
102 CALL sub_para_env%from_split(para_env, embed_env%ngroups, embed_env%group_distribution, &
103 subgroup_min_size=group_size_wish)
104 END IF
105
106 IF (output_unit > 0) THEN
107 WRITE (output_unit, fmt="(T2,A,T71,I10)") "EMBED_ENV| Number of created MPI groups:", embed_env%ngroups
108 WRITE (output_unit, fmt="(T2,A)", advance="NO") "EMBED_ENV| Task to group correspondence:"
109 DO i = 0, para_env%num_pe - 1
110 IF (modulo(i, 4) == 0) WRITE (output_unit, *)
111 WRITE (output_unit, fmt='(A3,I4,A3,I4,A1)', advance="NO") &
112 " (", i, " : ", embed_env%group_distribution(i), ")"
113 END DO
114 WRITE (output_unit, *)
115 END IF
116 IF (ASSOCIATED(group_partition)) THEN
117 DEALLOCATE (group_partition)
118 END IF
119 ! Allocate para_env and handle the several loggers
120 ALLOCATE (embed_env%sub_para_env(embed_env%ngroups))
121 ALLOCATE (embed_env%sub_logger(embed_env%ngroups))
122 ALLOCATE (embed_env%energies(n_subforce_eval))
123 !
124 NULLIFY (logger)
125 i = embed_env%group_distribution(para_env%mepos) + 1
126 ! Create sub_para_env
127 embed_env%sub_para_env(i)%para_env => sub_para_env
128 ! Create sub_logger
129 IF (embed_env%sub_para_env(i)%para_env%is_source()) THEN
130 ! Redirecting output of subforce_eval to file..
131 CALL section_vals_val_get(root_section, "GLOBAL%PROJECT_NAME", &
132 c_val=input_file_path)
133 lp = len_trim(input_file_path)
134 input_file_path(lp + 1:len(input_file_path)) = "-r-"// &
135 adjustl(cp_to_string(i))
136 lp = len_trim(input_file_path)
137 output_file_path = input_file_path(1:lp)//".out"
138 CALL open_file(file_name=output_file_path, file_status="UNKNOWN", &
139 file_action="WRITE", file_position="APPEND", &
140 unit_number=unit_nr)
141 ELSE
142 unit_nr = -1
143 END IF
144 CALL cp_logger_create(embed_env%sub_logger(i)%p, &
145 para_env=embed_env%sub_para_env(i)%para_env, &
146 default_global_unit_nr=unit_nr, &
147 close_global_unit_on_dealloc=.false.)
148 ! Try to use better names for the local log if it is not too late
149 CALL section_vals_val_get(root_section, "GLOBAL%OUTPUT_FILE_NAME", &
150 c_val=c_val)
151 IF (c_val /= "") THEN
152 CALL cp_logger_set(embed_env%sub_logger(i)%p, &
153 local_filename=trim(c_val)//"_localLog")
154 END IF
155 CALL section_vals_val_get(root_section, "GLOBAL%PROJECT", c_val=c_val)
156 IF (c_val /= "") THEN
157 CALL cp_logger_set(embed_env%sub_logger(i)%p, &
158 local_filename=trim(c_val)//"_localLog")
159 END IF
160 IF (len_trim(c_val) > default_string_length) THEN
161 cpwarn("The project name will be truncated.")
162 END IF
163 embed_env%sub_logger(i)%p%iter_info%project_name = trim(c_val)
164 CALL section_vals_val_get(root_section, "GLOBAL%PRINT_LEVEL", &
165 i_val=embed_env%sub_logger(i)%p%iter_info%print_level)
166
167 ! *** initializations for the setup of the EMBED environment ***
168 CALL embed_init(embed_env, root_section, para_env, force_env_section, &
169 use_motion_section)
170 CALL timestop(handle)
171
172 END SUBROUTINE embed_create_force_env
173
174END MODULE embed_main
static GRID_HOST_DEVICE int modulo(int a, int m)
Equivalent of Fortran's MODULO, which always return a positive number. https://gcc....
Utility routines to open and close files. Tracking of preconnections.
Definition cp_files.F:16
subroutine, public open_file(file_name, file_status, file_form, file_action, file_position, file_pad, unit_number, debug, skip_get_unit_number, file_access)
Opens the requested file using a free unit number.
Definition cp_files.F:308
various routines to log and control the output. The idea is that decisions about where to log should ...
subroutine, public cp_logger_set(logger, local_filename, global_filename)
sets various attributes of the given logger
subroutine, public cp_logger_create(logger, para_env, print_level, default_global_unit_nr, default_local_unit_nr, global_filename, local_filename, close_global_unit_on_dealloc, iter_info, close_local_unit_on_dealloc, suffix, template_logger)
initializes a logger
type(cp_logger_type) function, pointer, public cp_get_default_logger()
returns the default logger
routines to handle the output, The idea is to remove the decision of wheter to output and what to out...
integer function, public cp_print_key_unit_nr(logger, basis_section, print_key_path, extension, middle_name, local, log_filename, ignore_should_output, file_form, file_position, file_action, file_status, do_backup, on_file, is_new_file, mpi_io, fout)
...
initialize embed environment: clone of the mixed environment
subroutine, public embed_init(embed_env, root_section, para_env, force_env_section, use_motion_section)
reads the input and database file for embedding
Main force create for embedding.
Definition embed_main.F:12
subroutine, public embed_create_force_env(embed_env, root_section, para_env, force_env_section, n_subforce_eval, use_motion_section)
Controls program flow for embedded calculations.
Definition embed_main.F:52
subroutine, public embed_env_create(embed_env, para_env)
...
objects that represent the structure of input sections and the data contained in an input section
subroutine, public section_vals_val_get(section_vals, keyword_name, i_rep_section, i_rep_val, n_rep_val, val, l_val, i_val, r_val, c_val, l_vals, i_vals, r_vals, c_vals, explicit)
returns the requested value
Defines the basic variable types.
Definition kinds.F:23
integer, parameter, public default_string_length
Definition kinds.F:57
integer, parameter, public default_path_length
Definition kinds.F:58
Interface to the message passing library MPI.
type of a logger, at the moment it contains just a print level starting at which level it should be l...
Embedding environment type.
stores all the informations relevant to an mpi environment