(git:5a3db73)
Loading...
Searching...
No Matches
mimic_communicator.F
Go to the documentation of this file.
1!--------------------------------------------------------------------------------------------------!
2! CP2K: A general program to perform molecular dynamics simulations !
3! Copyright 2000-2026 CP2K developers group <https://cp2k.org> !
4! !
5! SPDX-License-Identifier: GPL-2.0-or-later !
6!--------------------------------------------------------------------------------------------------!
7
8! **************************************************************************************************
9!> \brief Module containing a MiMiC communicator class
10!> \par History
11!> 05.2025 Created [AA]
12!> \author Andrej Antalik
13! **************************************************************************************************
14
16
27 USE kinds, ONLY: default_string_length,&
28 dp
29 USE mcl_api, ONLY: mcl_finalize,&
35 USE mcl_requests, ONLY: mcl_data,&
41 USE pw_env_types, ONLY: pw_env_get,&
44 USE pw_types, ONLY: pw_r3d_rs_type
49 USE qs_kind_types, ONLY: get_qs_kind,&
51 USE qs_ks_types, ONLY: qs_ks_env_type,&
53 USE qs_rho_types, ONLY: qs_rho_get,&
55#include "../base/base_uses.f90"
56
57 IMPLICIT NONE
58
59 PRIVATE
60
61 CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'mimic_communicator'
62
63! **************************************************************************************************
64!> \brief MiMiC communicator class that facilitates MiMiC client-server data exchange
65!> \par History
66!> 05.2025 Created [AA]
67! **************************************************************************************************
69 PRIVATE
70 !> communication
71 TYPE(mp_para_env_type), POINTER :: para_env => null()
72 LOGICAL :: is_ionode = .false.
73 INTEGER :: mcl_server = 0, &
74 client_id = -1
75 !> CP2K data
76 TYPE(force_env_type), POINTER :: force_env => null()
77 TYPE(pw_pool_type), POINTER :: pw_info => null()
78 TYPE(particle_list_type), POINTER :: atoms => null()
79 TYPE(atomic_kind_list_type), POINTER :: kinds => null()
80 TYPE(qs_energy_type), POINTER :: energy => null()
81 TYPE(pw_r3d_rs_type), POINTER :: potential => null()
82 TYPE(qs_rho_type), POINTER :: density => null()
83 INTEGER :: n_atoms = -1, &
84 n_kinds = -1, &
85 n_spins = -1
86 INTEGER, DIMENSION(:, :), ALLOCATABLE :: npts_pproc
87 !> beginning index of the local buffer in the global buffer diminished by 1
88 INTEGER, DIMENSION(:), ALLOCATABLE :: lb_pproc
89
90 CONTAINS
91
92 PROCEDURE :: initialize
93 PROCEDURE :: finalize
94 PROCEDURE :: receive_request
95 PROCEDURE :: send_value
96 PROCEDURE :: send_client_info
97 PROCEDURE :: send_atom_info
98 PROCEDURE :: send_kind_info
99 PROCEDURE :: send_box_info
100 PROCEDURE :: send_result
101 PROCEDURE :: send_grid_coordinates
102 PROCEDURE :: send_density
103 PROCEDURE :: send_forces
104 PROCEDURE :: send_positions
105 PROCEDURE :: receive_positions
106 PROCEDURE :: receive_potential
107
109
110CONTAINS
111
112! **************************************************************************************************
113!> \brief Initialize the communicator by loading data and saving pointers to relevant data
114!> \param this ...
115!> \param force_env ...
116!> \par History
117!> 05.2025 Created [AA]
118! **************************************************************************************************
119 SUBROUTINE initialize(this, force_env)
120 CLASS(mimic_communicator_type), INTENT(INOUT) :: this
121 TYPE(force_env_type), TARGET :: force_env
122
123 CHARACTER(LEN=*), PARAMETER :: routineN = modulen//':initialize'
124
125 TYPE(cp_subsys_type), POINTER :: subsys
126 TYPE(dft_control_type), POINTER :: dft_control
127 TYPE(pw_env_type), POINTER :: pw_env
128 TYPE(qs_environment_type), POINTER :: qs_env
129 TYPE(qs_ks_env_type), POINTER :: ks_env
130 INTEGER :: handle
131 LOGICAL :: mcl_initialized
132
133 CALL timeset(routinen, handle)
134
135 CALL mcl_is_initialized(mcl_initialized)
136 IF (.NOT. mcl_initialized) THEN
137 CALL cp_abort(__location__, "MiMiC run requested, but MCL is not initialized. "// &
138 "Launch CP2K as a client in an MPMD run or set MCL_COMM_MODE.")
139 END IF
140
141 CALL mcl_get_program_id(this%client_id)
142
143 NULLIFY (subsys, qs_env, ks_env, pw_env)
144 this%force_env => force_env
145 CALL force_env_get(this%force_env, subsys=subsys, para_env=this%para_env, qs_env=qs_env)
146 CALL cp_subsys_get(subsys, natom=this%n_atoms, particles=this%atoms, &
147 nkind=this%n_kinds, atomic_kinds=this%kinds)
148 CALL get_qs_env(qs_env, energy=this%energy, vee=this%potential, rho=this%density, &
149 dft_control=dft_control, ks_env=ks_env, pw_env=pw_env)
150 CALL pw_env_get(pw_env, auxbas_pw_pool=this%pw_info)
151
152 this%is_ionode = this%para_env%is_source()
153
154 ALLOCATE (this%npts_pproc(3, 0:this%para_env%num_pe - 1), source=0)
155 this%npts_pproc(:, this%para_env%mepos) = this%pw_info%pw_grid%npts_local
156 CALL this%para_env%sum(this%npts_pproc)
157
158 ALLOCATE (this%lb_pproc(0:this%para_env%num_pe - 1), source=0)
159 this%lb_pproc(this%para_env%mepos) = this%pw_info%pw_grid%bounds_local(1, 1) &
160 - this%pw_info%pw_grid%bounds(1, 1)
161 CALL this%para_env%sum(this%lb_pproc)
162
163 this%n_spins = dft_control%nspins
164
165 CALL set_qs_env(qs_env, mimic=.true.)
166 dft_control%apply_external_potential = .true.
167 dft_control%eval_external_potential = .false.
168
169 ! allocate external electrostatic potential
170 IF (ASSOCIATED(this%potential)) THEN
171 CALL this%potential%release()
172 DEALLOCATE (this%potential)
173 END IF
174 ALLOCATE (this%potential)
175 CALL this%pw_info%create_pw(this%potential)
176 CALL set_ks_env(ks_env, vee=this%potential)
177
178 CALL timestop(handle)
179
180 END SUBROUTINE initialize
181
182! **************************************************************************************************
183!> \brief Finalize the simulation by deallocating memory
184!> \param this ...
185! **************************************************************************************************
186 SUBROUTINE finalize(this)
187 CLASS(mimic_communicator_type), INTENT(INOUT) :: this
188
189 CHARACTER(LEN=*), PARAMETER :: routineN = modulen//':finalize'
190
191 INTEGER :: handle
192
193 CALL timeset(routinen, handle)
194
195 CALL this%para_env%sync()
196
197 CALL mcl_finalize()
198
199 CALL timestop(handle)
200
201 END SUBROUTINE finalize
202
203! **************************************************************************************************
204!> \brief Receive a request from the server
205!> \param this ...
206!> \return ...
207! **************************************************************************************************
208 FUNCTION receive_request(this) RESULT(request)
209 CLASS(mimic_communicator_type), INTENT(INOUT) :: this
210 INTEGER :: request
211
212 CHARACTER(LEN=*), PARAMETER :: routineN = modulen//':receive_request'
213
214 INTEGER :: handle
215
216 CALL timeset(routinen, handle)
217
218 request = -1
219 CALL mcl_receive(request, 1, mcl_request, this%mcl_server)
220 CALL this%para_env%bcast(request)
221
222 CALL timestop(handle)
223
224 END FUNCTION receive_request
225
226! **************************************************************************************************
227!> \brief Send the specified single value data to the server
228!> \param this ...
229!> \param option word corresponding to available options
230!> \note Several values hardcoded for now
231! **************************************************************************************************
232 SUBROUTINE send_value(this, option)
233 CLASS(mimic_communicator_type), INTENT(INOUT) :: this
234 CHARACTER(LEN=*) :: option
235
236 CHARACTER(LEN=*), PARAMETER :: routineN = modulen//':send_value'
237
238 REAL(dp) :: energy
239 INTEGER :: handle
240
241 CALL timeset(routinen, handle)
242
243 SELECT CASE (option)
244 CASE ("num_atoms", "num_atoms_in_fragments")
245 CALL mcl_send(this%n_atoms, 1, mcl_data, this%mcl_server)
246 CASE ("num_kinds")
247 CALL mcl_send(this%n_kinds, 1, mcl_data, this%mcl_server)
248 CASE ("num_fragments")
249 CALL mcl_send(1, 1, mcl_data, this%mcl_server)
250 CASE ("num_bonds") ! later use to communicate constraints
251 CALL mcl_send(0, 1, mcl_data, this%mcl_server)
252 CASE ("num_angles") ! later use to communicate constraints
253 CALL mcl_send(0, 1, mcl_data, this%mcl_server)
254 CASE ("energy")
255 energy = this%energy%total - this%energy%ee
256 CALL mcl_send(energy, 1, mcl_data, this%mcl_server)
257 CASE DEFAULT
258 cpabort("The value chosen in "//routinen//" is not implemented.")
259 END SELECT
260
261 CALL timestop(handle)
262
263 END SUBROUTINE send_value
264
265! **************************************************************************************************
266!> \brief Send the specified information about the client to the server
267!> \param this ...
268!> \param option word corresponding to available options
269! **************************************************************************************************
270 SUBROUTINE send_client_info(this, option)
271 CLASS(mimic_communicator_type), INTENT(INOUT) :: this
272 CHARACTER(LEN=*) :: option
273
274 CHARACTER(LEN=*), PARAMETER :: routineN = modulen//':send_client_info'
275
276 CHARACTER(LEN=*), PARAMETER :: client_name = "CP2K"
277 INTEGER, DIMENSION(3) :: api_version
278 INTEGER :: handle, length
279
280 CALL timeset(routinen, handle)
281
282 SELECT CASE (option)
283 CASE ("id")
284 CALL mcl_send(this%client_id, 1, mcl_data, this%mcl_server)
285 CASE ("name")
286 length = len(client_name)
287 CALL mcl_send(length, 1, mcl_length, this%mcl_server)
288 CALL mcl_send(client_name, length, mcl_data, this%mcl_server)
289 CASE ("run_type")
290 CALL mcl_send(mcl_runtype_qm_rs_grid, 1, mcl_data, this%mcl_server)
291 CASE ("api_version")
292 CALL mcl_get_api_version(api_version)
293 CALL mcl_send(api_version, 3, mcl_data, this%mcl_server)
294 CASE DEFAULT
295 cpabort("The value chosen in "//routinen//" is not implemented.")
296 END SELECT
297
298 CALL timestop(handle)
299
300 END SUBROUTINE send_client_info
301
302! **************************************************************************************************
303!> \brief Send the specified data for each atom to the server
304!> \param this ...
305!> \param option word corresponding to available options
306! **************************************************************************************************
307 SUBROUTINE send_atom_info(this, option)
308 CLASS(mimic_communicator_type), INTENT(INOUT) :: this
309 CHARACTER(LEN=*) :: option
310
311 CHARACTER(LEN=*), PARAMETER :: routineN = modulen//':send_atom_info'
312
313 INTEGER, DIMENSION(:), ALLOCATABLE :: buffer
314 INTEGER :: handle, i
315
316 CALL timeset(routinen, handle)
317
318 ALLOCATE (buffer(this%n_atoms))
319 SELECT CASE (option)
320 CASE ("kinds")
321 DO i = 1, this%n_atoms
322 buffer(i) = this%atoms%els(i)%atomic_kind%kind_number
323 END DO
324 CASE ("ids")
325 DO i = 1, this%n_atoms
326 buffer(i) = this%atoms%els(i)%atom_index
327 END DO
328 CASE DEFAULT
329 cpabort("The value chosen in "//routinen//" is not implemented.")
330 END SELECT
331 CALL mcl_send(buffer, SIZE(buffer), mcl_data, this%mcl_server)
332
333 CALL timestop(handle)
334
335 END SUBROUTINE send_atom_info
336
337! **************************************************************************************************
338!> \brief Send the specified data for each kind to the server
339!> \param this ...
340!> \param option word corresponding to available options
341! **************************************************************************************************
342 SUBROUTINE send_kind_info(this, option)
343 CLASS(mimic_communicator_type), INTENT(INOUT) :: this
344 CHARACTER(LEN=*) :: option
345
346 CHARACTER(LEN=*), PARAMETER :: routineN = modulen//':send_kind_info'
347
348 TYPE(qs_environment_type), POINTER :: qs_env
349 TYPE(qs_kind_type), DIMENSION(:), POINTER :: qs_kinds
350 REAL(dp), DIMENSION(:), ALLOCATABLE :: buffer_dp
351 INTEGER, DIMENSION(:), ALLOCATABLE :: buffer_i
352 CHARACTER(LEN=:), ALLOCATABLE :: labels
353 CHARACTER(LEN=default_string_length) :: label
354 INTEGER :: handle, length, i
355
356 CALL timeset(routinen, handle)
357
358 SELECT CASE (option)
359 CASE ("labels")
360 ALLOCATE (CHARACTER(30*this%n_kinds) :: labels)
361 labels = ""
362 DO i = 1, this%n_kinds
363 CALL get_atomic_kind(this%kinds%els(i), name=label)
364 labels = trim(labels)//trim(label)//","
365 END DO
366 length = len(trim(labels)) - 1
367 CALL mcl_send(length, 1, mcl_length, this%mcl_server)
368 CALL mcl_send(labels, length, mcl_data, this%mcl_server)
369 CASE ("elements")
370 ALLOCATE (buffer_i(this%n_kinds))
371 DO i = 1, this%n_kinds
372 CALL get_atomic_kind(this%kinds%els(i), z=buffer_i(i))
373 END DO
374 CALL mcl_send(buffer_i, SIZE(buffer_i), mcl_data, this%mcl_server)
375 CASE ("masses")
376 ALLOCATE (buffer_dp(this%n_kinds))
377 DO i = 1, this%n_kinds
378 buffer_dp(i) = cp_unit_from_cp2k(this%kinds%els(i)%mass, "AMU")
379 END DO
380 CALL mcl_send(buffer_dp, SIZE(buffer_dp), mcl_data, this%mcl_server)
381 CASE ("nuclear_charges")
382 NULLIFY (qs_env, qs_kinds)
383 CALL force_env_get(this%force_env, qs_env=qs_env)
384 CALL get_qs_env(qs_env, qs_kind_set=qs_kinds)
385 ALLOCATE (buffer_dp(this%n_kinds))
386 DO i = 1, this%n_kinds
387 CALL get_qs_kind(qs_kinds(i), zeff=buffer_dp(i))
388 END DO
389 CALL mcl_send(buffer_dp, SIZE(buffer_dp), mcl_data, this%mcl_server)
390 CASE DEFAULT
391 cpabort("The value chosen in "//routinen//" is not implemented.")
392 END SELECT
393
394 CALL timestop(handle)
395
396 END SUBROUTINE send_kind_info
397
398! **************************************************************************************************
399!> \brief Send the specified box information to the server
400!> \param this ...
401!> \param option word corresponding to available options
402! **************************************************************************************************
403 SUBROUTINE send_box_info(this, option)
404 CLASS(mimic_communicator_type), INTENT(INOUT) :: this
405 CHARACTER(LEN=*) :: option
406
407 CHARACTER(LEN=*), PARAMETER :: routineN = modulen//':send_box_info'
408
409 INTEGER, DIMENSION(3) :: npts_glob
410 REAL(dp), DIMENSION(3) :: origin
411 REAL(dp), DIMENSION(9) :: box_vectors
412 INTEGER :: handle, i
413
414 CALL timeset(routinen, handle)
415
416 npts_glob = this%pw_info%pw_grid%npts
417
418 SELECT CASE (option)
419 CASE ("num_gridpoints")
420 CALL mcl_send(npts_glob, 3, mcl_data, this%mcl_server)
421 CASE ("origin")
422 origin = 0.0_dp
423 CALL mcl_send(origin, 3, mcl_data, this%mcl_server)
424 CASE ("box_vectors")
425 box_vectors = [(this%pw_info%pw_grid%dh(:, i)*real(npts_glob(i), dp), i=1, 3)]
426 CALL mcl_send(box_vectors, 9, mcl_data, this%mcl_server)
427 CASE DEFAULT
428 cpabort("The value chosen in "//routinen//" is not implemented.")
429 END SELECT
430
431 CALL timestop(handle)
432
433 END SUBROUTINE send_box_info
434
435! **************************************************************************************************
436!> \brief Send the specified result to the server
437!> \param this ...
438!> \param option word corresponding to available options
439! **************************************************************************************************
440 SUBROUTINE send_result(this, option)
441 CLASS(mimic_communicator_type), INTENT(INOUT) :: this
442 CHARACTER(LEN=*) :: option
443
444 CHARACTER(LEN=*), PARAMETER :: routineN = modulen//':send_result'
445
446 TYPE(qs_environment_type), POINTER :: qs_env
447 TYPE(cp_result_type), POINTER :: results
448 CHARACTER(LEN=default_string_length) :: description
449 REAL(KIND=dp), DIMENSION(:), ALLOCATABLE :: buffer
450 INTEGER :: handle
451
452 CALL timeset(routinen, handle)
453
454 NULLIFY (qs_env, results)
455 CALL force_env_get(this%force_env, qs_env=qs_env)
456 CALL get_qs_env(qs_env, results=results)
457
458 SELECT CASE (option)
459 CASE ("hirshfeld_charges")
460 description = "[HIRSHFELD-CHARGES]"
461 ALLOCATE (buffer(this%n_atoms), source=0.0_dp)
462 CALL get_results(results, description, buffer)
463 CALL mcl_send(buffer, SIZE(buffer), mcl_data, this%mcl_server)
464 CASE DEFAULT
465 cpabort("The value chosen in "//routinen//" is not implemented.")
466 END SELECT
467
468 CALL timestop(handle)
469
470 END SUBROUTINE send_result
471
472! **************************************************************************************************
473!> \brief Send grid point coordinates to the server
474!> \param this ...
475! **************************************************************************************************
476 SUBROUTINE send_grid_coordinates(this)
477 CLASS(mimic_communicator_type), INTENT(INOUT) :: this
478
479 CHARACTER(LEN=*), PARAMETER :: routineN = modulen//':send_grid_coordinates'
480
481 INTEGER, DIMENSION(3) :: npts_glob, npts, lb_glob, lb, ub
482 REAL(dp), DIMENSION(3) :: origin
483 REAL(dp), DIMENSION(3, 3) :: box_vectors
484 REAL(dp), DIMENSION(:, :), ALLOCATABLE :: coords
485 INTEGER :: handle, i, j, k, offset
486
487 CALL timeset(routinen, handle)
488
489 origin = 0.0_dp
490 box_vectors = this%pw_info%pw_grid%dh
491 ! number of grid points
492 npts_glob = this%pw_info%pw_grid%npts
493 npts = this%pw_info%pw_grid%npts_local
494 ! bounds
495 lb_glob = this%pw_info%pw_grid%bounds(1, :)
496 lb = this%pw_info%pw_grid%bounds_local(1, :)
497 ub = this%pw_info%pw_grid%bounds_local(2, :)
498
499 ALLOCATE (coords(3, product(npts_glob)), source=0.0_dp)
500 offset = (lb(1) - lb_glob(1))*product(npts(2:))
501 DO k = lb(3), ub(3)
502 DO j = lb(2), ub(2)
503 DO i = lb(1), ub(1)
504 offset = offset + 1
505 coords(:, offset) = origin + box_vectors(:, 1)*real(i - lb_glob(1), dp) &
506 + box_vectors(:, 2)*real(j - lb_glob(2), dp) &
507 + box_vectors(:, 3)*real(k - lb_glob(3), dp)
508 END DO
509 END DO
510 END DO
511 CALL this%para_env%sum(coords)
512
513 CALL mcl_send(coords, SIZE(coords), mcl_data, this%mcl_server)
514
515 CALL timestop(handle)
516
517 END SUBROUTINE send_grid_coordinates
518
519! **************************************************************************************************
520!> \brief Receive external potential from the server
521!> \param this ...
522! **************************************************************************************************
523 SUBROUTINE receive_potential(this)
524 CLASS(mimic_communicator_type), INTENT(INOUT) :: this
525
526 CHARACTER(LEN=*), PARAMETER :: routineN = modulen//':receive_potential'
527
528 INTEGER, DIMENSION(3) :: npts, lb, ub
529 REAL(dp), DIMENSION(:), ALLOCATABLE, TARGET :: buffer
530 REAL(dp), DIMENSION(:), ALLOCATABLE :: buffer_loc
531 REAL(dp), DIMENSION(:), POINTER :: buffer_p
532 INTEGER :: i, j, k, i_proc, offset
533 INTEGER :: handle, length, tag
534
535 CALL timeset(routinen, handle)
536
537 NULLIFY (buffer_p)
538 npts = this%pw_info%pw_grid%npts_local
539 lb = this%pw_info%pw_grid%bounds_local(1, :)
540 ub = this%pw_info%pw_grid%bounds_local(2, :)
541 ALLOCATE (buffer_loc(product(npts)))
542
543 tag = 1
544
545 IF (this%is_ionode) THEN
546 ALLOCATE (buffer(product(this%pw_info%pw_grid%npts)))
547 ! receive potential at the IO process
548 CALL mcl_receive(buffer, SIZE(buffer), mcl_data, this%mcl_server)
549 ! distribute across processes
550 DO i_proc = 0, this%para_env%num_pe - 1
551 length = product(this%npts_pproc(:, i_proc))
552 offset = this%lb_pproc(i_proc)*product(npts(2:)) + 1
553 buffer_p => buffer(offset:offset + length - 1)
554 IF (i_proc /= this%para_env%source) THEN
555 i = i_proc
556 CALL this%para_env%send(buffer_p, i, tag)
557 ELSE
558 buffer_loc(:) = buffer_p
559 END IF
560 END DO
561 ELSE
562 CALL this%para_env%recv(buffer_loc, this%para_env%source, tag)
563 END IF
564
565 ! set the potential
566 offset = 0
567 DO k = lb(3), ub(3)
568 DO j = lb(2), ub(2)
569 DO i = lb(1), ub(1)
570 offset = offset + 1
571 this%potential%array(i, j, k) = -buffer_loc(offset)
572 END DO
573 END DO
574 END DO
575
576 CALL timestop(handle)
577
578 END SUBROUTINE receive_potential
579
580! **************************************************************************************************
581!> \brief Send electron density to the server
582!> \param this ...
583! **************************************************************************************************
584 SUBROUTINE send_density(this)
585 CLASS(mimic_communicator_type), INTENT(INOUT) :: this
586
587 CHARACTER(LEN=*), PARAMETER :: routineN = modulen//':send_density'
588
589 INTEGER, DIMENSION(3) :: npts, lb, ub
590 TYPE(pw_r3d_rs_type), DIMENSION(:), POINTER :: rho
591 REAL(dp), DIMENSION(:), ALLOCATABLE, TARGET :: buffer
592 REAL(dp), DIMENSION(:), ALLOCATABLE :: buffer_loc
593 REAL(dp), DIMENSION(:), POINTER :: buffer_p
594 INTEGER :: i_spin, i_proc, i, j, k, offset
595 INTEGER :: handle, length, tag
596
597 CALL timeset(routinen, handle)
598
599 NULLIFY (rho, buffer_p)
600 CALL qs_rho_get(this%density, rho_r=rho)
601 npts = this%pw_info%pw_grid%npts_local
602 lb = this%pw_info%pw_grid%bounds_local(1, :)
603 ub = this%pw_info%pw_grid%bounds_local(2, :)
604 ALLOCATE (buffer_loc(product(npts)))
605
606 ! gather density values
607 buffer_loc = 0.0_dp
608 DO i_spin = 1, this%n_spins
609 offset = 0
610 DO k = lb(3), ub(3)
611 DO j = lb(2), ub(2)
612 DO i = lb(1), ub(1)
613 offset = offset + 1
614 buffer_loc(offset) = buffer_loc(offset) + rho(i_spin)%array(i, j, k)
615 END DO
616 END DO
617 END DO
618 END DO
619
620 tag = 1
621
622 IF (.NOT. this%is_ionode) THEN
623 CALL this%para_env%send(buffer_loc, this%para_env%source, tag)
624 ELSE
625 ALLOCATE (buffer(product(this%pw_info%pw_grid%npts)))
626 ! collect from the processes at the IO process
627 DO i_proc = 0, this%para_env%num_pe - 1
628 length = product(this%npts_pproc(:, i_proc))
629 offset = this%lb_pproc(i_proc)*product(npts(2:)) + 1
630 buffer_p => buffer(offset:offset + length - 1)
631 IF (i_proc /= this%para_env%source) THEN
632 i = i_proc
633 CALL this%para_env%recv(buffer_p, i, tag)
634 ELSE
635 buffer_p = buffer_loc
636 END IF
637 END DO
638 ! send the density
639 CALL mcl_send(buffer, SIZE(buffer), mcl_data, this%mcl_server)
640 END IF
641
642 CALL timestop(handle)
643
644 END SUBROUTINE send_density
645
646! **************************************************************************************************
647!> \brief Send positions of all atoms to the server
648!> \param this ...
649! **************************************************************************************************
650 SUBROUTINE send_positions(this)
651 CLASS(mimic_communicator_type), INTENT(INOUT) :: this
652
653 CHARACTER(LEN=*), PARAMETER :: routineN = modulen//':send_positions'
654
655 REAL(dp), DIMENSION(:, :), ALLOCATABLE :: buffer
656 INTEGER :: handle, i_atom
657
658 CALL timeset(routinen, handle)
659
660 ALLOCATE (buffer(3, this%n_atoms))
661 DO i_atom = 1, this%n_atoms
662 buffer(:, i_atom) = this%atoms%els(i_atom)%r
663 END DO
664 CALL mcl_send(buffer, SIZE(buffer), mcl_data, this%mcl_server)
665
666 CALL timestop(handle)
667
668 END SUBROUTINE send_positions
669
670! **************************************************************************************************
671!> \brief Receive positions of all atoms from the server
672!> \param this ...
673! **************************************************************************************************
674 SUBROUTINE receive_positions(this)
675 CLASS(mimic_communicator_type), INTENT(INOUT) :: this
676
677 CHARACTER(LEN=*), PARAMETER :: routineN = modulen//':receive_positions'
678
679 REAL(dp), DIMENSION(:, :), ALLOCATABLE :: buffer
680 INTEGER :: handle, i_atom
681
682 CALL timeset(routinen, handle)
683
684 ALLOCATE (buffer(3, this%n_atoms))
685 CALL mcl_receive(buffer, SIZE(buffer), mcl_data, this%mcl_server)
686 CALL this%para_env%bcast(buffer)
687 DO i_atom = 1, this%n_atoms
688 this%atoms%els(i_atom)%r = buffer(:, i_atom)
689 END DO
690
691 CALL timestop(handle)
692
693 END SUBROUTINE receive_positions
694
695! **************************************************************************************************
696!> \brief Send QM forces of all atoms to the server
697!> \param this ...
698! **************************************************************************************************
699 SUBROUTINE send_forces(this)
700 CLASS(mimic_communicator_type), INTENT(INOUT) :: this
701
702 CHARACTER(LEN=*), PARAMETER :: routineN = modulen//':send_forces'
703
704 REAL(dp), DIMENSION(:, :), ALLOCATABLE :: buffer
705 INTEGER :: handle, i_atom
706
707 CALL timeset(routinen, handle)
708
709 ALLOCATE (buffer(3, this%n_atoms))
710 DO i_atom = 1, this%n_atoms
711 buffer(:, i_atom) = this%atoms%els(i_atom)%f
712 END DO
713 CALL mcl_send(buffer, SIZE(buffer), mcl_data, this%mcl_server)
714
715 CALL timestop(handle)
716
717 END SUBROUTINE send_forces
718
719END MODULE mimic_communicator
represent a simple array based list of the given type
Define the atomic kind types and their sub types.
subroutine, public get_atomic_kind(atomic_kind, fist_potential, element_symbol, name, mass, kind_number, natom, atom_list, rcov, rvdw, z, qeff, apol, cpol, mm_radius, shell, shell_active, damping)
Get attributes of an atomic kind.
Defines control structures, which contain the parameters and the settings for the DFT-based calculati...
set of type/routines to handle the storage of results in force_envs
set of type/routines to handle the storage of results in force_envs
types that represent a subsys, i.e. a part of the system
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, cell_ref, use_ref_cell)
returns information about various attributes of the given subsys
unit conversion facility
Definition cp_units.F:30
real(kind=dp) function, public cp_unit_from_cp2k(value, unit_str, defaults, power)
converts from the internal cp2k units to the given unit
Definition cp_units.F:1311
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
Defines the basic variable types.
Definition kinds.F:23
integer, parameter, public dp
Definition kinds.F:34
integer, parameter, public default_string_length
Definition kinds.F:57
Wrapper module for MiMiC Communication Library (MCL) routines.
Definition mcl_api.F:15
subroutine, public mcl_is_initialized(is_initialized)
Definition mcl_api.F:94
subroutine, public mcl_finalize()
Definition mcl_api.F:78
subroutine, public mcl_get_program_id(id)
Definition mcl_api.F:88
subroutine, public mcl_get_api_version(version)
Definition mcl_api.F:82
Wrapper module for MiMiC Communication Library (MCL) request labels.
integer, parameter, public mcl_request
integer, parameter, public mcl_data
integer, parameter, public mcl_runtype_qm_rs_grid
integer, parameter, public mcl_length
Interface to the message passing library MPI.
Module containing a MiMiC communicator class.
subroutine initialize(this, force_env)
Initialize the communicator by loading data and saving pointers to relevant data.
represent a simple array based list of the given type
container for various plainwaves related things
subroutine, public pw_env_get(pw_env, pw_pools, cube_info, gridlevel_info, auxbas_pw_pool, auxbas_grid, auxbas_rs_desc, auxbas_rs_grid, rs_descs, rs_grids, xc_pw_pool, vdw_pw_pool, poisson_env, interp_section)
returns the various attributes of the pw env
Manages a pool of grids (to be used for example as tmp objects), but can also be used to instantiate ...
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, mimic, 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, sab_cneo, 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, matrix_vhxc, 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, xcint_weights, 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, rhoz_cneo_set, ecoul_1c, rho0_s_rs, rho0_s_gs, rhoz_cneo_s_rs, rhoz_cneo_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, do_rixs, tb_tblite, matrix_metric, matrix_metric_kp)
Get the QUICKSTEP environment.
subroutine, public set_qs_env(qs_env, super_cell, mos, qmmm, qmmm_periodic, mimic, 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, rhoz_cneo_set, 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, do_rixs, tb_tblite)
Set the QUICKSTEP environment.
Define the quickstep kind type and their sub types.
subroutine, public get_qs_kind(qs_kind, basis_set, basis_type, ncgf, nsgf, all_potential, tnadd_potential, gth_potential, sgp_potential, upf_potential, cneo_potential, se_parameter, dftb_parameter, xtb_parameter, dftb3_param, zatom, zeff, elec_conf, mao, lmax_dftb, alpha_core_charge, ccore_charge, core_charge, core_charge_radius, paw_proj_set, paw_atom, hard_radius, hard0_radius, max_rad_local, covalent_radius, vdw_radius, gpw_type_forced, harmonics, max_iso_not0, max_s_harm, grid_atom, ngrid_ang, ngrid_rad, lmax_rho0, dft_plus_u_atom, l_of_dft_plus_u, n_of_dft_plus_u, u_minus_j, hund_j, u_of_dft_plus_u, j_of_dft_plus_u, alpha_of_dft_plus_u, beta_of_dft_plus_u, j0_of_dft_plus_u, occupation_of_dft_plus_u, dispersion, bs_occupation, magnetization, no_optimize, addel, laddel, naddel, orbitals, max_scf, eps_scf, smear, u_ramping, u_minus_j_target, eps_u_ramping, proj_shell_charge, lr_atom, do_mtlr, u_j_loop, ao_coef, init_u_ramping_each_scf, reltmat, ghost, monovalent, floating, name, element_symbol, pao_basis_size, pao_model_file, pao_potentials, pao_descriptors, nelec)
Get attributes of an atomic kind.
subroutine, public set_ks_env(ks_env, v_hartree_rspace, s_mstruct_changed, rho_changed, exc_accint, potential_changed, forces_up_to_date, complex_ks, matrix_h, matrix_h_im, matrix_ks, matrix_ks_im, matrix_vxc, kinetic, matrix_s, matrix_s_ri_aux, matrix_w, matrix_p_mp2, matrix_p_mp2_admm, matrix_vhxc, matrix_h_kp, matrix_h_im_kp, matrix_ks_kp, matrix_vxc_kp, kinetic_kp, matrix_s_kp, matrix_w_kp, matrix_s_ri_aux_kp, matrix_ks_im_kp, vppl, xcint_weights, rho_core, rho_nlcc, rho_nlcc_g, vee, neighbor_list_id, kpoints, sab_orb, sab_all, sac_ae, sac_ppl, sac_lri, sap_ppnl, sap_oce, sab_lrc, sab_se, sab_xtbe, sab_tbe, sab_core, sab_xb, sab_xtb_pp, sab_xtb_nonbond, sab_vdw, sab_scp, sab_almo, sab_kp, sab_kp_nosym, sab_cneo, task_list, task_list_soft, subsys, dft_control, dbcsr_dist, distribution_2d, pw_env, para_env, blacs_env, uspp, upf_inverse)
...
superstucture that hold various representations of the density and keeps track of which ones are vali...
subroutine, public qs_rho_get(rho_struct, rho_ao, rho_ao_im, rho_ao_kp, rho_ao_im_kp, rho_r, drho_r, rho_g, drho_g, tau_r, tau_g, rho_r_valid, drho_r_valid, rho_g_valid, drho_g_valid, tau_r_valid, tau_g_valid, tot_rho_r, tot_rho_g, rho_r_sccs, soft_valid, complex_rho_ao)
returns info about the density described by this object. If some representation is not available an e...
contains arbitrary information which need to be stored
represents a system: atoms, molecules, their pos,vel,...
wrapper to abstract the force evaluation of the various methods
stores all the informations relevant to an mpi environment
MiMiC communicator class that facilitates MiMiC client-server data exchange.
contained for different pw related things
Manages a pool of grids (to be used for example as tmp objects), but can also be used to instantiate ...
Provides all information about a quickstep kind.
calculation environment to calculate the ks matrix, holds all the needed vars. assumes that the core ...
keeps the density in various representations, keeping track of which ones are valid.