forked from lgcrego/Dynemol
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MPI_topologies.f
359 lines (298 loc) · 11.3 KB
/
MPI_topologies.f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
module MPI_definitions_m
use MPI
use type_m , only : warning
use parameters_m , only : driver , EnvField_
public :: world , myid , master , slave , np
public :: ChebyComm , ChebyCrew , myCheby
public :: KernelComm , KernelCrew , myKernel
public :: ForceComm , ForceCrew , myForce , npForce
public :: EnvComm , EnvCrew , myEnvId , npEnv
public :: myAxisComm , AxisCrew , myAxis_rank , np_per_axis
public :: ChebyKernelComm , myChebyKernel
public :: ForceCrewComm
public :: launch_MPI , setup_MPI_labor_force
private
! module variables ...
integer :: world , myid , np
integer :: KernelComm , myKernel
integer :: ChebyComm , myCheby
integer :: ChebyKernelComm , myChebyKernel
integer :: ForceComm , myForce , npForce
integer :: ForceCrewComm
integer :: myAxisComm , myAxis_rank , np_per_axis
integer :: EnvComm , myEnvId , npEnv
logical :: master = .false. , slave = .true.
logical :: ChebyCrew = .false.
logical :: ForceCrew = .false.
logical :: KernelCrew = .false.
logical :: AxisCrew = .false.
logical :: EnvCrew = .false.
! module parameters ...
integer :: EnvProcs = 6 ! <== MPI procs dedicated to EnvFields; default = 6 ...
contains
!
!
!
!=====================
subroutine launch_MPI
!=====================
implicit none
! local variables ...
integer :: err
! define MPI_COMM_WORLD ...
world = MPI_COMM_WORLD
CALL MPI_INIT(err) ! <== initiates MPI environment
CALL MPI_COMM_RANK(world,myid,err) ! <== sets the rank of processes
CALL MPI_COMM_SIZE(world,np,err) ! <== gets the total number of processes
if( myid == 0 ) master = .true.
if( myid == 0 ) slave = .false.
if( np < 3 ) then
if( master ) CALL warning("halting: # of MPI processes < 3; # of MPI processes must be at least 3")
Call mpi_barrier( world , err )
stop
end if
end subroutine launch_MPI
!
!
!
!================================
subroutine setup_MPI_labor_force
!================================
implicit none
! local variables ...
integer :: err
select case ( driver )
case ( "slice_AO" , "slice_ElHl" )
CALL setup_Adiabatic_Crew
case ( "slice_Cheb" )
CALL setup_Chebyshev_Crew
case ( "slice_CSDM" )
CALL setup_CSDM_Crew
if( np < 4 ) then
if( master ) CALL warning("halting: # of MPI processes must be at least 4 for DRIVER=CSDM")
Call mpi_barrier( world , err )
stop
end if
case default
end select
end subroutine setup_MPI_labor_force
!
!
!
!===============================
subroutine setup_CSDM_Crew
!===============================
implicit none
! local variables ...
integer :: err , my_color , my_tune , ForceCrewLimit , xyz , my_rank
logical :: drafted = .false.
! define sub_groups and new communicators ...
!------------------------------------------------------------------------
! KernelComm group = (0,1,2,3) ; to work in "EhrenfestForce" along xyz ...
select case ( myid )
case (0)
my_color = 0
case (1:3)
my_color = 0
KernelCrew = .true.
case (4:)
my_color = MPI_undefined
end select
CALL MPI_Comm_split( world , my_color , myid , KernelComm , err )
If( KernelCrew ) CALL MPI_COMM_RANK ( KernelComm , myKernel , err ) ! <== sets the rank of processes in KernelComm
!------------------------------------------------------------------------
ForceCrewLimit = (np-1) - merge( EnvProcs , 0 , EnvField_ )
! defining ForceComm = master + ForceCrew ...
my_color = MPI_undefined
if( myid <= ForceCrewLimit ) then
my_color = 0
drafted = .true.
end if
CALL MPI_Comm_split( world , my_color , myid , ForceComm , err )
if( drafted ) then
CALL MPI_COMM_RANK (ForceComm , my_rank , err ) ! <== sets the rank of processes
end if
! defining myAxisComm = a Communication channel for each axis (x;y;z) ...
! AxisCrew dwells inside xyz loop ; Kernel Crew joins AxisCrew ...
my_color = MPI_undefined
my_tune = MPI_undefined
if( master ) then
! do nothing
elseif( myid <= ForceCrewLimit ) then
xyz = mod( (myid-1) , 3 ) + 1
my_color = xyz
AxisCrew = .true.
my_tune = 0
ForceCrew = .true.
end if
CALL MPI_Comm_split( world , my_color , myid , myAxisComm , err ) ! <== a Communication channel for each axis
if( AxisCrew ) then
CALL MPI_COMM_RANK (myAxisComm , myAxis_rank , err ) ! <== sets the rank of processes
CALL MPI_COMM_SIZE (myAxisComm , np_per_axis , err ) ! <== gets the total number of processes
end if
CALL MPI_Comm_split( world , my_tune , myid , ForceCrewComm , err ) ! <== a Communication channel for each axis
if( ForceCrew ) then
CALL MPI_COMM_RANK (ForceCrewComm , myForce , err ) ! <== sets the rank of processes
CALL MPI_COMM_SIZE (ForceCrewComm , npforce , err ) ! <== gets the total number of processes
end if
end subroutine setup_CSDM_Crew
!
!
!
!===============================
subroutine setup_Adiabatic_Crew
!===============================
implicit none
! local variables ...
integer :: err , my_color , ForceCrewLimit
logical :: drafted = .false.
! define sub_groups and new communicators ...
!------------------------------------------------------------------------
! KernelComm group = (0,1,2) ; to work in "EhrenfestForce" ...
select case ( myid )
case (0)
my_color = 0
case (1:2)
my_color = 0
KernelCrew = .true.
case (3:)
my_color = MPI_undefined
end select
CALL MPI_Comm_split( world , my_color , myid , KernelComm , err )
If( KernelCrew ) CALL MPI_COMM_RANK ( KernelComm , myKernel , err ) ! <== sets the rank of processes in KernelComm
!------------------------------------------------------------------------
! ForceComm group = KernelCrew + ForceCrew ; to work in "EhrenfestForce" ...
ForceCrewLimit = (np-1) - merge( EnvProcs , 0 , EnvField_ )
If( myid <= 2) then ! <== case(0:2)
my_color = 0
drafted = .true.
ElseIf( (3 <= myid) .AND. (myid <= ForceCrewLimit) ) then ! <== case(3:ForceCrewLimit)
my_color = 0
drafted = .true.
ForceCrew = .true.
Else ! <== case(ForceCrewLimit+1:)
my_color = MPI_undefined
EndIf
CALL MPI_Comm_split( world , my_color , myid , ForceComm , err )
If( drafted ) then
CALL MPI_COMM_RANK (ForceComm , myForce , err ) ! <== sets the rank of processes
CALL MPI_COMM_SIZE (ForceComm , npForce , err ) ! <== gets the total number of processes
end If
! processes released for next drafting ...
drafted = .false.
!------------------------------------------------------------------------
! EnvComm group = (0,[EnvProcs]) ; to work in "even_more_extended_huckel" ...
If( EnvField_ ) then
IF( myid == 0 ) then ! <== case(0)
my_color = 0
drafted = .true.
ElseIf( myid > ForceCrewLimit ) then ! <== case(ForceCrewLimit+1:)
my_color = 0
drafted = .true.
EnvCrew = .true.
Else
my_color = MPI_undefined
EndIf
CALL MPI_Comm_split( world , my_color , myid , EnvComm , err )
If( drafted ) then
CALL MPI_COMM_RANK (EnvComm , myEnvId , err ) ! <== sets the rank of processes
CALL MPI_COMM_SIZE (EnvComm , npEnv , err ) ! <== gets the total number of processes
end If
EndIf
!------------------------------------------------------------------------
end subroutine setup_Adiabatic_Crew
!
!
!
!===============================
subroutine setup_Chebyshev_Crew
!===============================
implicit none
! local variables ...
integer :: err , my_color , ForceCrewLimit
logical :: drafted = .false.
! define sub_groups and new communicators ...
!------------------------------------------------------------------------
! ChebyComm group = (0,1) ...
select case ( myid )
case (0,1)
my_color = 0
ChebyCrew = .true.
case (2:)
my_color = MPI_undefined
end select
CALL MPI_Comm_split( world , my_color , myid , ChebyComm , err )
If( ChebyCrew ) CALL MPI_COMM_RANK ( ChebyComm , myCheby , err ) ! <== sets the rank of processes in ChebyComm
! processes released for next drafting ...
drafted = .false.
!------------------------------------------------------------------------
! KernelComm group = (0,2) ...
select case ( myid )
case (0,2)
my_color = 0
drafted = .true.
case (1,3:)
my_color = MPI_undefined
end select
CALL MPI_Comm_split( world , my_color , myid , KernelComm , err )
If( drafted ) CALL MPI_COMM_RANK ( KernelComm , myKernel , err ) ! <== sets the rank of processes in KernelComm
! processes released for next drafting ...
drafted = .false.
!------------------------------------------------------------------------
! ChebyKernelComm group = (0,1,2) = ChebyComm + KernelComm ...
select case ( myid )
case (0:2)
my_color = 0
drafted = .true.
case (3:)
my_color = MPI_undefined
end select
CALL MPI_Comm_split( world , my_color , myid , ChebyKernelComm , err )
If( drafted ) CALL MPI_COMM_RANK ( ChebyKernelComm , myChebyKernel , err ) ! <== sets the rank of processes in KernelComm
! processes released for next drafting ...
drafted = .false.
!------------------------------------------------------------------------
! ForceComm group = KernelCrew + ForceCrew ...
ForceCrewLimit = (np-1) - merge( EnvProcs , 0 , EnvField_ )
If( myid == 0) then ! <== case(0)
my_color = 0
drafted = .true.
ElseIf( (2 <= myid) .AND. (myid <= ForceCrewLimit) ) then ! <== case(2:ForceCrewLimit)
my_color = 0
drafted = .true.
ForceCrew = .true.
Else ! <== case(1,ForceCrewLimit+1:)
my_color = MPI_undefined
EndIf
CALL MPI_Comm_split( world , my_color , myid , ForceComm , err )
If( drafted ) then
CALL MPI_COMM_RANK (ForceComm , myForce , err ) ! <== sets the rank of processes
CALL MPI_COMM_SIZE (ForceComm , npForce , err ) ! <== gets the total number of processes
end If
! processes released for next drafting ...
drafted = .false.
!------------------------------------------------------------------------
! EnvComm group = (0,[EnvProcs]) ; to work in "even_more_extended_huckel" ...
If( EnvField_ ) then
IF( myid == 0 ) then ! <== case(0)
my_color = 0
drafted = .true.
ElseIf( myid > ForceCrewLimit ) then ! <== case(ForceCrewLimit+1:)
my_color = 0
drafted = .true.
EnvCrew = .true.
Else
my_color = MPI_undefined
EndIf
CALL MPI_Comm_split( world , my_color , myid , EnvComm , err )
If( drafted ) then
CALL MPI_COMM_RANK (EnvComm , myEnvId , err ) ! <== sets the rank of processes
CALL MPI_COMM_SIZE (EnvComm , npEnv , err ) ! <== gets the total number of processes
end If
EndIf
!------------------------------------------------------------------------
end subroutine setup_Chebyshev_Crew
!
!
!
end module MPI_definitions_m