61#include "./base/base_uses.f90"
66 LOGICAL,
PRIVATE,
PARAMETER :: debug_this_module = .true.
67 CHARACTER(len=*),
PARAMETER,
PRIVATE :: moduleN =
'replica_methods'
68 INTEGER,
SAVE,
PRIVATE :: last_rep_env_id = 0
89 SUBROUTINE rep_env_create(rep_env, para_env, input, input_declaration, nrep, prep, &
90 sync_v, keep_wf_history, row_force)
96 LOGICAL,
INTENT(in),
OPTIONAL :: sync_v, keep_wf_history, row_force
98 CHARACTER(len=default_path_length) :: input_file_path, output_file_path
99 INTEGER :: forcedim, i, i0, ierr, ip, ir, irep, lp, &
100 my_prep, new_env_id, nparticle, &
102 INTEGER,
ALLOCATABLE,
DIMENSION(:, :) :: gridinfo
103 INTEGER,
DIMENSION(2) :: dims, pos
109 cpassert(.NOT.
ASSOCIATED(rep_env))
110 cpassert(
ASSOCIATED(input_declaration))
112 NULLIFY (cart, para_env_f, para_env_inter_rep)
117 IF (
PRESENT(row_force))
THEN
118 IF (row_force) forcedim = 2
120 my_prep = min(prep, para_env%num_pe)
121 dims(3 - forcedim) = min(para_env%num_pe/my_prep, nrep)
122 dims(forcedim) = my_prep
123 IF ((dims(1)*dims(2) /= para_env%num_pe) .AND. (unit_nr > 0))
THEN
124 WRITE (unit_nr, fmt=
"(T2,A)")
"REPLICA| WARNING: number of processors is not divisible by the number of replicas"
125 WRITE (unit_nr, fmt=
"(T2,A,I0,A)")
"REPLICA| ", para_env%num_pe - dims(1)*dims(2),
" MPI process(es) will be idle"
128 CALL cart%create(comm_old=para_env, ndims=2, dims=dims)
130 pos = cart%mepos_cart
131 ALLOCATE (para_env_full)
133 ALLOCATE (para_env_f)
134 CALL para_env_f%from_split(cart, pos(3 - forcedim))
135 ALLOCATE (para_env_inter_rep)
136 CALL para_env_inter_rep%from_split(cart, pos(forcedim))
142 ALLOCATE (gridinfo(2, 0:para_env%num_pe - 1))
144 gridinfo(:, para_env%mepos) = pos
145 CALL para_env%sum(gridinfo)
146 IF (unit_nr > 0)
THEN
147 WRITE (unit_nr, fmt=
"(T2,A,T71,I10)")
"REPLICA| layout of the replica grid, number of groups ", para_env_inter_rep%num_pe
148 WRITE (unit_nr, fmt=
"(T2,A,T71,I10)")
"REPLICA| layout of the replica grid, size of each group", para_env_f%num_pe
149 WRITE (unit_nr, fmt=
"(T2,A)", advance=
"NO")
"REPLICA| MPI process to grid (group,rank) correspondence:"
150 DO i = 0, para_env%num_pe - 1
151 IF (
modulo(i, 4) == 0)
WRITE (unit_nr, *)
152 WRITE (unit_nr, fmt=
'(A3,I4,A3,I4,A1,I4,A1)', advance=
"NO") &
153 " (", i,
" : ", gridinfo(3 - forcedim, i),
",", &
154 gridinfo(forcedim, i),
")"
158 DEALLOCATE (gridinfo)
159 IF (
ASSOCIATED(rep_env))
THEN
160 last_rep_env_id = last_rep_env_id + 1
161 rep_env%id_nr = last_rep_env_id
162 rep_env%ref_count = 1
164 rep_env%sync_v = .false.
165 IF (
PRESENT(sync_v)) rep_env%sync_v = sync_v
166 rep_env%keep_wf_history = .true.
167 IF (
PRESENT(keep_wf_history)) rep_env%keep_wf_history = keep_wf_history
168 NULLIFY (rep_env%wf_history)
169 NULLIFY (rep_env%results)
171 rep_env%force_dim = forcedim
172 rep_env%my_rep_group = cart%mepos_cart(3 - forcedim)
173 ALLOCATE (rep_env%inter_rep_rank(0:para_env_inter_rep%num_pe - 1), &
174 rep_env%force_rank(0:para_env_f%num_pe - 1))
175 rep_env%inter_rep_rank = 0
176 rep_env%inter_rep_rank(rep_env%my_rep_group) = para_env_inter_rep%mepos
177 CALL para_env_inter_rep%sum(rep_env%inter_rep_rank)
178 rep_env%force_rank = 0
179 rep_env%force_rank(cart%mepos_cart(forcedim)) = para_env_f%mepos
180 CALL para_env_f%sum(rep_env%force_rank)
183 c_val=input_file_path)
184 rep_env%original_project_name = input_file_path
188 lp = len_trim(input_file_path)
189 input_file_path(lp + 1:len(input_file_path)) =
"-r-"// &
191 lp = len_trim(input_file_path)
194 c_val=input_file_path)
196 output_file_path = input_file_path(1:lp)//
".out"
198 c_val=trim(output_file_path))
202 input_file_path(lp + 1:len(input_file_path)) =
".inp"
203 IF (para_env_f%is_source())
THEN
204 CALL open_file(file_name=trim(input_file_path), file_status=
"UNKNOWN", &
205 file_form=
"FORMATTED", file_action=
"WRITE", &
211 output_file_path, para_env_f, ierr=ierr)
215 IF (para_env_f%is_source())
THEN
216 CALL open_file(file_name=trim(input_file_path), file_status=
"OLD", &
217 file_form=
"FORMATTED", file_action=
"READ", unit_number=unit_nr)
218 CALL close_file(unit_number=unit_nr, file_status=
"DELETE")
221 rep_env%f_env_id = new_env_id
224 rep_env%nparticle = nparticle
225 rep_env%ndim = 3*nparticle
226 ALLOCATE (rep_env%replica_owner(nrep))
228 i0 = nrep/para_env_inter_rep%num_pe
229 ir =
modulo(nrep, para_env_inter_rep%num_pe)
230 DO ip = 0, para_env_inter_rep%num_pe - 1
231 DO i = i0*ip + min(ip, ir) + 1, i0*(ip + 1) + min(ip + 1, ir)
232 rep_env%replica_owner(i) = ip
237 IF (rep_env%my_rep_group < ir) nrep_local = nrep_local + 1
238 ALLOCATE (rep_env%local_rep_indices(nrep_local), &
239 rep_env%rep_is_local(nrep))
241 rep_env%rep_is_local = .false.
243 IF (rep_env%replica_owner(irep) == rep_env%my_rep_group)
THEN
244 nrep_local = nrep_local + 1
245 rep_env%local_rep_indices(nrep_local) = irep
246 rep_env%rep_is_local(irep) = .true.
249 cpassert(nrep_local ==
SIZE(rep_env%local_rep_indices))
252 rep_env%para_env => para_env_full
253 rep_env%para_env_f => para_env_f
254 rep_env%para_env_inter_rep => para_env_inter_rep
256 ALLOCATE (rep_env%r(rep_env%ndim, nrep), rep_env%v(rep_env%ndim, nrep), &
257 rep_env%f(rep_env%ndim + 1, nrep))
262 CALL set_vel(rep_env%f_env_id, rep_env%v(:, 1), rep_env%ndim, ierr)
265 IF (rep_env%rep_is_local(i))
THEN
266 CALL get_pos(rep_env%f_env_id, rep_env%r(:, i), rep_env%ndim, ierr)
271 IF (
ASSOCIATED(rep_env))
THEN
273 CALL rep_env_init_low(rep_env%id_nr, ierr)
284 SUBROUTINE rep_env_init_low(rep_env_id, ierr)
285 INTEGER,
INTENT(in) :: rep_env_id
286 INTEGER,
INTENT(out) :: ierr
288 INTEGER :: i, in_use, stat
289 LOGICAL :: do_kpoints, has_unit_metric
298 IF (.NOT.
ASSOCIATED(rep_env)) &
299 cpabort(
"could not find rep_env with id_nr"//
cp_to_string(rep_env_id))
300 NULLIFY (qs_env, dft_control, subsys)
303 logger%iter_info%iteration(1) = rep_env%my_rep_group
305 level_name=
"REPLICA_EVAL")
307 IF (rep_env%keep_wf_history)
THEN
311 CALL get_qs_env(qs_env, dft_control=dft_control)
312 ALLOCATE (rep_env%wf_history(
SIZE(rep_env%local_rep_indices)))
313 DO i = 1,
SIZE(rep_env%wf_history)
314 NULLIFY (rep_env%wf_history(i)%wf_history)
317 wf_history=rep_env%wf_history(i)%wf_history)
318 CALL wfi_retain(rep_env%wf_history(i)%wf_history)
320 CALL get_qs_env(qs_env, has_unit_metric=has_unit_metric, &
321 do_kpoints=do_kpoints)
322 CALL wfi_create(rep_env%wf_history(i)%wf_history, &
323 interpolation_method_nr= &
324 dft_control%qs_control%wf_interpolation_method_nr, &
325 extrapolation_order=dft_control%qs_control%wf_extrapolation_order, &
326 has_unit_metric=has_unit_metric)
333 rep_env%keep_wf_history = .false.
336 ALLOCATE (rep_env%results(rep_env%nrep))
337 DO i = 1, rep_env%nrep
338 NULLIFY (rep_env%results(i)%results)
341 CALL cp_subsys_get(subsys, results=rep_env%results(i)%results)
353 END SUBROUTINE rep_env_init_low
367 LOGICAL,
OPTIONAL :: calc_f
369 CHARACTER(len=*),
PARAMETER :: routinen =
'rep_env_calc_e_f'
371 INTEGER :: handle, ierr, my_calc_f
373 CALL timeset(routinen, handle)
374 cpassert(
ASSOCIATED(rep_env))
375 cpassert(rep_env%ref_count > 0)
377 IF (
PRESENT(calc_f))
THEN
378 IF (calc_f) my_calc_f = 1
380 CALL rep_env_calc_e_f_low(rep_env%id_nr, my_calc_f, ierr)
382 CALL timestop(handle)
397 RECURSIVE SUBROUTINE rep_env_calc_e_f_low(rep_env_id, calc_f, ierr)
398 INTEGER,
INTENT(in) :: rep_env_id, calc_f
399 INTEGER,
INTENT(out) :: ierr
405 IF (
ASSOCIATED(rep_env))
THEN
407 CALL rep_env_calc_e_f_int(rep_env, calc_f /= 0)
412 END SUBROUTINE rep_env_calc_e_f_low
422 SUBROUTINE rep_env_calc_e_f_int(rep_env, calc_f)
424 LOGICAL,
OPTIONAL :: calc_f
426 INTEGER :: i, ierr, irep, md_iter, my_calc_f, ndim
432 NULLIFY (f_env, qs_env, subsys)
433 cpassert(
ASSOCIATED(rep_env))
434 cpassert(rep_env%ref_count > 0)
435 my_calc_f = 3*rep_env%nparticle
436 IF (
PRESENT(calc_f))
THEN
437 IF (.NOT. calc_f) my_calc_f = 0
443 md_iter = logger%iter_info%iteration(2)
446 DO i = 1,
SIZE(rep_env%local_rep_indices)
447 irep = rep_env%local_rep_indices(i)
448 ndim = 3*rep_env%nparticle
449 IF (rep_env%sync_v)
THEN
450 CALL set_vel(rep_env%f_env_id, rep_env%v(:, irep), ndim, ierr)
454 logger%iter_info%iteration(1) = irep
455 logger%iter_info%iteration(2) = md_iter
457 IF (rep_env%keep_wf_history)
THEN
461 wf_history=rep_env%wf_history(i)%wf_history)
468 CALL cp_subsys_set(subsys, results=rep_env%results(irep)%results)
471 CALL calc_force(rep_env%f_env_id, rep_env%r(:, irep), ndim, &
472 rep_env%f(ndim + 1, irep), rep_env%f(:ndim, irep), &
479 END SUBROUTINE rep_env_calc_e_f_int
static GRID_HOST_DEVICE int modulo(int a, int m)
Equivalent of Fortran's MODULO, which always return a positive number. https://gcc....
Defines control structures, which contain the parameters and the settings for the DFT-based calculati...
Utility routines to open and close files. Tracking of preconnections.
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.
subroutine, public close_file(unit_number, file_status, keep_preconnection)
Close an open file given by its logical unit number. Optionally, keep the file and unit preconnected.
various routines to log and control the output. The idea is that decisions about where to log should ...
integer function, public cp_logger_get_default_io_unit(logger)
returns the unit nr for the ionode (-1 on all other processors) skips as well checks if the procs cal...
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...
subroutine, public cp_add_iter_level(iteration_info, level_name, n_rlevel_new)
Adds an iteration level.
set of type/routines to handle the storage of results in force_envs
subroutine, public cp_result_retain(results)
Retains cp_result type.
subroutine, public cp_result_create(results)
Allocates and intitializes the cp_result.
types that represent a subsys, i.e. a part of the system
subroutine, public cp_subsys_set(subsys, atomic_kinds, particles, local_particles, molecules, molecule_kinds, local_molecules, para_env, colvar_p, shell_particles, core_particles, gci, multipoles, results, cell)
sets various propreties of the subsys
subroutine, public cp_subsys_get(subsys, ref_count, atomic_kinds, atomic_kind_set, particles, particle_set, local_particles, molecules, molecule_set, molecule_kinds, molecule_kind_set, local_molecules, para_env, colvar_p, shell_particles, core_particles, gci, multipoles, natom, nparticle, ncore, nshell, nkind, atprop, virial, results, cell)
returns information about various attributes of the given subsys
interface to use cp2k as library
subroutine, public set_vel(env_id, new_vel, n_el, ierr)
sets the velocities of the particles
subroutine, public get_nparticle(env_id, n_particle, ierr)
returns the number of particles in the given force env
subroutine, public f_env_add_defaults(f_env_id, f_env, handle)
adds the default environments of the f_env to the stack of the defaults, and returns a new error and ...
subroutine, public get_pos(env_id, pos, n_el, ierr)
gets the positions of the particles
recursive subroutine, public create_force_env(new_env_id, input_declaration, input_path, output_path, mpi_comm, output_unit, owns_out_unit, input, ierr, work_dir, initial_variables)
creates a new force environment using the given input, and writing the output to the given output uni...
subroutine, public f_env_rm_defaults(f_env, ierr, handle)
removes the default environments of the f_env to the stack of the defaults, and sets ierr accordingly...
recursive subroutine, public calc_force(env_id, pos, n_el_pos, e_pot, force, n_el_force, ierr)
returns the energy of the configuration given by the positions passed as argument
Interface for the force calculations.
recursive subroutine, public force_env_get(force_env, in_use, fist_env, qs_env, meta_env, fp_env, subsys, para_env, potential_energy, additional_potential, kinetic_energy, harmonic_shell, kinetic_shell, cell, sub_force_env, qmmm_env, qmmmx_env, eip_env, pwdft_env, globenv, input, force_env_section, method_name_id, root_section, mixed_env, nnp_env, embed_env, ipi_env)
returns various attributes about the force environment
integer, parameter, public use_qs_force
Defines the basic variable types.
integer, parameter, public dp
integer, parameter, public default_path_length
Interface to the message passing library MPI.
type(mp_comm_type), parameter, public mp_comm_null
subroutine, public get_qs_env(qs_env, atomic_kind_set, qs_kind_set, cell, super_cell, cell_ref, use_ref_cell, kpoints, dft_control, mos, sab_orb, sab_all, qmmm, qmmm_periodic, sac_ae, sac_ppl, sac_lri, sap_ppnl, sab_vdw, sab_scp, sap_oce, sab_lrc, sab_se, sab_xtbe, sab_tbe, sab_core, sab_xb, sab_xtb_pp, sab_xtb_nonbond, sab_almo, sab_kp, sab_kp_nosym, particle_set, energy, force, matrix_h, matrix_h_im, matrix_ks, matrix_ks_im, matrix_vxc, run_rtp, rtp, matrix_h_kp, matrix_h_im_kp, matrix_ks_kp, matrix_ks_im_kp, matrix_vxc_kp, kinetic_kp, matrix_s_kp, matrix_w_kp, matrix_s_ri_aux_kp, matrix_s, matrix_s_ri_aux, matrix_w, matrix_p_mp2, matrix_p_mp2_admm, rho, rho_xc, pw_env, ewald_env, ewald_pw, active_space, mpools, input, para_env, blacs_env, scf_control, rel_control, kinetic, qs_charges, vppl, rho_core, rho_nlcc, rho_nlcc_g, ks_env, ks_qmmm_env, wf_history, scf_env, local_particles, local_molecules, distribution_2d, dbcsr_dist, molecule_kind_set, molecule_set, subsys, cp_subsys, oce, local_rho_set, rho_atom_set, task_list, task_list_soft, rho0_atom_set, rho0_mpole, rhoz_set, ecoul_1c, rho0_s_rs, rho0_s_gs, do_kpoints, has_unit_metric, requires_mo_derivs, mo_derivs, mo_loc_history, nkind, natom, nelectron_total, nelectron_spin, efield, neighbor_list_id, linres_control, xas_env, virial, cp_ddapc_env, cp_ddapc_ewald, outer_scf_history, outer_scf_ihistory, x_data, et_coupling, dftb_potential, results, se_taper, se_store_int_env, se_nddo_mpole, se_nonbond_env, admm_env, lri_env, lri_density, exstate_env, ec_env, harris_env, dispersion_env, gcp_env, vee, rho_external, external_vxc, mask, mp2_env, bs_env, kg_env, wanniercentres, atprop, ls_scf_env, do_transport, transport_env, v_hartree_rspace, s_mstruct_changed, rho_changed, potential_changed, forces_up_to_date, mscfg_env, almo_scf_env, gradient_history, variable_history, embed_pot, spin_embed_pot, polar_env, mos_last_converged, eeq, rhs)
Get the QUICKSTEP environment.
subroutine, public set_qs_env(qs_env, super_cell, mos, qmmm, qmmm_periodic, ewald_env, ewald_pw, mpools, rho_external, external_vxc, mask, scf_control, rel_control, qs_charges, ks_env, ks_qmmm_env, wf_history, scf_env, active_space, input, oce, rho_atom_set, rho0_atom_set, rho0_mpole, run_rtp, rtp, rhoz_set, rhoz_tot, ecoul_1c, has_unit_metric, requires_mo_derivs, mo_derivs, mo_loc_history, efield, linres_control, xas_env, cp_ddapc_env, cp_ddapc_ewald, outer_scf_history, outer_scf_ihistory, x_data, et_coupling, dftb_potential, se_taper, se_store_int_env, se_nddo_mpole, se_nonbond_env, admm_env, ls_scf_env, do_transport, transport_env, lri_env, lri_density, exstate_env, ec_env, dispersion_env, harris_env, gcp_env, mp2_env, bs_env, kg_env, force, kpoints, wanniercentres, almo_scf_env, gradient_history, variable_history, embed_pot, spin_embed_pot, polar_env, mos_last_converged, eeq, rhs)
Set the QUICKSTEP environment.
Storage of past states of the qs_env. Methods to interpolate (or actually normally extrapolate) the n...
subroutine, public wfi_create_for_kp(wf_history)
...
subroutine, public wfi_create(wf_history, interpolation_method_nr, extrapolation_order, has_unit_metric)
...
interpolate the wavefunctions to speed up the convergence when doing MD
subroutine, public wfi_retain(wf_history)
retains a wf history (see doc/ReferenceCounting.html)
methods to setup replicas of the same system differing only by atom positions and velocities (as used...
subroutine, public rep_env_create(rep_env, para_env, input, input_declaration, nrep, prep, sync_v, keep_wf_history, row_force)
creates a replica environment together with its force environment
subroutine, public rep_env_calc_e_f(rep_env, calc_f)
evaluates the forces
types used to handle many replica of the same system that differ only in atom positions,...
subroutine, public rep_envs_add_rep_env(rep_env)
adds the given rep_env to the list of controlled rep_envs.
type(replica_env_type) function, pointer, public rep_envs_get_rep_env(id_nr, ierr)
returns the replica environment with the given id_nr
subroutine, public rep_env_sync(rep_env, vals)
sends the data from each replica to all the other on replica j/=i data from replica i overwrites val(...
subroutine, public rep_env_sync_results(rep_env, results)
sends the data from each replica to all the other in this case the result type is passed
type of a logger, at the moment it contains just a print level starting at which level it should be l...
represents a system: atoms, molecules, their pos,vel,...
represent a multidimensional parallel environment
stores all the informations relevant to an mpi environment
keeps replicated information about the replicas