15 USE iso_c_binding,
ONLY: c_char, &
54 #include "./base/base_uses.f90"
60 CHARACTER(len=*),
PARAMETER,
PRIVATE :: moduleN =
'ipi_driver'
76 TYPE(force_env_type),
POINTER :: force_env
77 TYPE(global_environment_type),
POINTER :: globenv
79 CHARACTER(len=*),
PARAMETER :: routinen =
'run_driver'
83 CALL timeset(routinen, handle)
84 cpabort(
"CP2K was compiled with the __NO_SOCKETS option!")
88 INTEGER,
PARAMETER :: msglen = 12
90 CHARACTER(len=default_path_length) :: c_hostname, drv_hostname
91 CHARACTER(LEN=default_string_length) ::
header
92 INTEGER :: drv_port, handle, i_drv_unix, &
93 idir, ii, inet, ip, iwait, &
94 nat, output_unit, socket
95 TYPE(mp_request_type),
DIMENSION(2) :: wait_req
96 INTEGER(KIND=int_4),
POINTER :: wait_msg(:)
97 LOGICAL :: drv_unix, fwait, hasdata, &
99 REAL(kind=
dp) :: cellh(3, 3), cellih(3, 3), &
100 mxmat(9), pot, vir(3, 3)
101 REAL(kind=
dp),
ALLOCATABLE :: combuf(:)
102 TYPE(cell_type),
POINTER :: cpcell
103 TYPE(mp_para_env_type),
POINTER :: para_env
104 TYPE(cp_subsys_type),
POINTER :: subsys
105 TYPE(section_vals_type),
POINTER :: drv_section, motion_section
106 TYPE(virial_type),
POINTER :: virial
107 REAL(kind=
dp) :: sleeptime
109 CALL timeset(routinen, handle)
118 cpassert(
ASSOCIATED(force_env))
122 ionode = para_env%is_source()
134 cpassert(sleeptime >= 0)
140 IF (drv_unix) i_drv_unix = 0
141 IF (output_unit > 0)
THEN
142 WRITE (output_unit, *)
"@ i-PI DRIVER BEING LOADED"
143 WRITE (output_unit, *)
"@ INPUT DATA: ", trim(drv_hostname), drv_port, drv_unix
146 c_hostname = trim(drv_hostname)//c_null_char
150 ALLOCATE (wait_msg(1))
164 DO iwait = 0, para_env%num_pe - 1
165 IF (iwait /= para_env%source)
THEN
166 CALL para_env%send(msg=wait_msg, dest=iwait, tag=666)
170 CALL para_env%irecv(msgout=wait_msg, source=para_env%source, &
171 tag=666, request=wait_req(2))
172 CALL mp_testany(wait_req(2:), flag=fwait)
173 DO WHILE (.NOT. fwait)
174 CALL mp_testany(wait_req(2:), flag=fwait)
175 CALL uwait(sleeptime)
181 CALL para_env%bcast(
header)
183 IF (output_unit > 0)
WRITE (output_unit, *)
" @ DRIVER MODE: Message from server: ", trim(
header)
184 IF (trim(
header) ==
"STATUS")
THEN
195 ELSE IF (trim(
header) ==
"POSDATA")
THEN
198 cellh = reshape(mxmat, (/3, 3/))
200 cellih = reshape(mxmat, (/3, 3/))
202 cellh = transpose(cellh)
203 cellih = transpose(cellih)
205 CALL para_env%bcast(cellh)
206 CALL para_env%bcast(cellih)
207 CALL para_env%bcast(nat)
208 IF (.NOT.
ALLOCATED(combuf))
ALLOCATE (combuf(3*nat))
209 IF (ionode)
CALL readbuffer(socket, combuf, nat*3)
210 CALL para_env%bcast(combuf)
213 IF (nat /= subsys%particles%n_els) &
214 cpabort(
"@DRIVER MODE: Uh-oh! Particle number mismatch between i-PI and cp2k input!")
216 DO ip = 1, subsys%particles%n_els
219 subsys%particles%els(ip)%r(idir) = combuf(ii)
227 IF (output_unit > 0)
WRITE (output_unit, *)
" @ DRIVER MODE: Received positions "
231 DO ip = 1, subsys%particles%n_els
234 combuf(ii) = subsys%particles%els(ip)%f(idir)
240 vir = transpose(virial%pv_virial)
243 IF (should_stop)
EXIT
246 ELSE IF (trim(
header) ==
"GETFORCE")
THEN
247 IF (output_unit > 0)
WRITE (output_unit, *)
" @ DRIVER MODE: Returning v,forces,stress "
264 IF (output_unit > 0)
WRITE (output_unit, *)
" @DRIVER MODE: Socket disconnected, time to exit. "
271 DEALLOCATE (wait_msg)
274 CALL timestop(handle)
collects all references to literature in CP2K as new algorithms / method are included from literature...
integer, save, public kapil2016
integer, save, public ceriotti2014
Handles all functions related to the CELL.
subroutine, public init_cell(cell, hmat, periodic)
Initialise/readjust a simulation cell after hmat has been changed.
subroutine, public cell_create(cell, hmat, periodic, tag)
allocates and initializes a cell
Handles all functions related to the CELL.
subroutine, public cell_release(cell)
releases the given cell (see doc/ReferenceCounting.html)
Routines to handle the external control of CP2K.
subroutine, public external_control(should_stop, flag, globenv, target_time, start_time, force_check)
External manipulations during a run : when the <PROJECT_NAME>.EXIT_$runtype command is sent the progr...
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...
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 for the force calculations.
recursive subroutine, public force_env_calc_energy_force(force_env, calc_force, consistent_energies, skip_external_control, eval_energy_forces, require_consistent_energy_force, linres, calc_stress_tensor)
Interface routine for force and energy calculations.
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)
returns various attributes about the force environment
Define type storing the global information of a run. Keep the amount of stored data small....
Driver mode - To communicate with i-PI Python wrapper.
subroutine, public run_driver(force_env, globenv)
...
Defines the basic variable types.
integer, parameter, public dp
integer, parameter, public default_string_length
integer, parameter, public default_path_length
integer, parameter, public int_4
Interface to the message passing library MPI.
Implements UNIX and INET sockets.
void writebuffer(int *psockfd, char *data, int *plen)
Writes to a socket.
void uwait(double *dsec)
Mini-wrapper to nanosleep.
void readbuffer(int *psockfd, char *data, int *plen)
Reads from a socket.