(git:27c966b)
Loading...
Searching...
No Matches
pw_copy_all.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!> \note
10!> Copy of pw types using an optimal match strategy
11!> \par History
12!> JGH (06-May-2021) : pw_copy routine for complex match
13!> \author JGH
14! **************************************************************************************************
16 USE kinds, ONLY: dp
17 USE mathconstants, ONLY: z_zero
20 USE pw_types, ONLY: pw_c1d_gs_type
21#include "../base/base_uses.f90"
22
23 IMPLICIT NONE
24
25 PRIVATE
26
27 PUBLIC :: pw_copy_match
28
29 CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'pw_copy_all'
30 LOGICAL, PARAMETER, PRIVATE :: debug_this_module = .false.
31
32! **************************************************************************************************
33
34CONTAINS
35
36! **************************************************************************************************
37!> \brief copy a pw type variable
38!> \param pw1 ...
39!> \param pw2 ...
40!> \author JGH
41! **************************************************************************************************
42 SUBROUTINE pw_copy_match(pw1, pw2)
43 TYPE(pw_c1d_gs_type), INTENT(IN) :: pw1
44 TYPE(pw_c1d_gs_type), INTENT(INOUT) :: pw2
45
46 COMPLEX(KIND=dp), ALLOCATABLE, DIMENSION(:) :: cc
47 INTEGER :: group_size, ig1, ig2, ip, jg2, me, ng1, &
48 ng2, ngm, penow, same_order
49 INTEGER, ALLOCATABLE, DIMENSION(:) :: ngr
50 INTEGER, ALLOCATABLE, DIMENSION(:, :) :: g_hat
51 INTEGER, DIMENSION(3) :: k1, k2
52 TYPE(mp_comm_type) :: group
53 TYPE(pw_grid_type), POINTER :: pg1, pg2
54
55 ng1 = SIZE(pw1%array)
56 ng2 = SIZE(pw2%array)
57
58 pg1 => pw1%pw_grid
59 pg2 => pw2%pw_grid
60
61 group = pg1%para%group
62 group_size = pg1%para%group%num_pe
63 me = pg1%para%group%mepos
64 ! Independently constructed grids can still have identical local ordering.
65 ! All ranks must agree before bypassing the collective ring exchange.
66 same_order = 0
67 IF (ng1 == ng2) THEN
68 IF (all(pg1%g_hat(1:3, 1:ng1) == pg2%g_hat(1:3, 1:ng2))) same_order = 1
69 END IF
70 CALL group%min(same_order)
71 IF (same_order == 1) THEN
72 pw2%array(:) = pw1%array(:)
73 RETURN
74 END IF
75 ALLOCATE (ngr(group_size))
76 ngr = 0
77 ngr(me + 1) = pg1%ngpts_cut_local
78 CALL group%sum(ngr)
79 ngm = maxval(ngr)
80 ALLOCATE (cc(ngm))
81 cc(1:ng1) = pw1%array(1:ng1)
82 cc(ng1 + 1:ngm) = z_zero
83
84 ALLOCATE (g_hat(3, ngm))
85 g_hat = 0
86 g_hat(1:3, 1:ng1) = pg1%g_hat(1:3, 1:ng1)
87
88 DO ip = 1, group_size
89 penow = me - ip + 1
90 IF (penow < 0) penow = penow + group_size
91
92 DO ig1 = 1, ngr(penow + 1)
93 k1(1:3) = g_hat(1:3, ig1)
94 jg2 = 0
95 DO ig2 = 1, ng2
96 k2(1:3) = pg2%g_hat(1:3, ig2)
97 IF (sum(abs(k1 - k2)) == 0) THEN
98 jg2 = ig2
99 EXIT
100 END IF
101 END DO
102 IF (jg2 /= 0) pw2%array(jg2) = cc(ig1)
103 END DO
104 IF (ip /= group_size) THEN
105 CALL group%shift(cc)
106 CALL group%shift(g_hat)
107 END IF
108
109 END DO
110
111 DEALLOCATE (ngr, cc, g_hat)
112
113 END SUBROUTINE pw_copy_match
114
115END MODULE pw_copy_all
Defines the basic variable types.
Definition kinds.F:23
integer, parameter, public dp
Definition kinds.F:34
Definition of mathematical constants and functions.
complex(kind=dp), parameter, public z_zero
Interface to the message passing library MPI.
subroutine, public pw_copy_match(pw1, pw2)
copy a pw type variable
Definition pw_copy_all.F:43