Newer
Older
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
360
361
362
363
364
365
366
367
!***********************************************************************
!
!
PROGRAM FLY
!
!
! FLY Ver. 5.0: December , 2012
!
! Multi Platform one-side comm. based code
! for TREE cosmological LSS evolution
!
! (U. BECCIANI et al.)
!
! At variance with TREECODE we adopt the standard leapfrog integrator
! of Efstathiou and Eastwood (Hockney and Eastwood, eqs. 11.59a,b).
!
! Thanks to Lars Hernquist, Institute for Advanced Study, for the
! original source code of the serial version
!
!***********************************************************************
!
!=======================================================================
!
USE fly_h
implicit none
INCLUDE 'mpif.h'
! Declaration of local variables.
! -------------------------------
INTEGER(KIND=8) :: n,i,j
REAL(KIND=8) :: init_rt, init_tot,init_tot1,init_tot2,step_rt
REAL(KIND=8) :: psec,tot_sec,prev_sec
REAL(KIND=8) :: min_rmt_time,max_rmt_time
INTEGER :: istatus(MPI_STATUS_SIZE),ind_pe,tag0=0,tag1=1,tag2=2,tag3=3,lname
INTEGER :: index_min, index_max
character*(MPI_MAX_PROCESSOR_NAME) hostname_me
#ifdef FLASH
character*(MPI_MAX_PORT_NAME) portName
#endif
!
!
!=======================================================================
!
!-----------------------------------------------------------------------------
! Initialize state of the system.
!-----------------------------------------------------------------------------
!
tot_sec=0.0
prev_sec=0.0
CALL MPI_Init(ierror)
CALL MPI_COMM_RANK(MPI_COMM_WORLD, me, ierror)
CALL MPI_COMM_SIZE(MPI_COMM_WORLD, npes, ierror)
CALL MPI_GET_PROCESSOR_NAME(hostname_me, lname, ierror)
WRITE(uterm, *) "FLY - RUN. PE=",me," HOSTNAME:",hostname_me(1:lname),' npes=',npes
CALL flush(uterm)
init_tot1=MPI_WTIME() ! start time counter of GLOBAL code
!-----------------------------------------------------------------------------
! Verify the system consistence
!-----------------------------------------------------------------------------
IF(N_PES.NE.npes) THEN
write(uterm,*)'Error: N_PES=',N_PES,' and number of PEs= ',npes, &
' DOES NOT match',' me=',me
STOP
ENDIF
IF(nb_loc*N_PES .lt. nbodsmax) THEN
IF(me.eq.0) write(uterm,*)'Error: nbodsmax=',nbodsmax,' and number of PEs= ',npes, &
' DOES NOT match'
STOP
ENDIF
IF(nc_loc*N_PES .lt. nbodsmax) THEN
IF(me.eq.0) write(uterm,*)'Error: ncells=',ncells,' and number of PEs= ',npes, &
' DOES NOT match'
STOP
ENDIF
IF(nb_loc .gt. 2147483646/3) THEN
IF(me.eq.0) write(uterm,*)'Error: nbodsmax=',nbodsmax,' too big nb_loc=',nb_loc
STOP
ENDIF
DO i=1,15
IF(npes .eq. 2**i) EXIT
ENDDO
IF(i.eq.16) THEN
POW2=.FALSE.
IF(me.eq.0) write(6,*)"Power of two not enabled"
ELSE
POW2=.TRUE.
IF(me.eq.0) write(6,*)"Power of two enabled"
ENDIF
!
!-----------------------------------------------------------------------------
! Start FLY inizialization phase
!-----------------------------------------------------------------------------
init_rt = MPI_WTIME() ! start time counter of the initialization + initial load balance phase
CALL null ! routine to initialize variables
CALL sys_init ! system initialization: read bodies, parameter, and initilize variables
!-----------------------------------------------------------------------------
! WRITE OUT INFORMATION
!-----------------------------------------------------------------------------
!
IF(me.EQ.0) THEN
write(uterm,*) 'Running with ',N_PES,' processors and tol=',tol
write(uterm,*) 'GROUPING LEVEL=',ncrit,' Body in cell group=',nbodcrit
call flush(uterm)
ENDIF
init_rt = MPI_WTIME()-init_rt
CALL MPI_BARRIER(MPI_COMM_WORLD,ierror)
IF(me.eq.0) THEN
write(uterm,*)'INIT: executed =',init_rt,' sec.'
call flush(uterm)
ENDIF
!-----------------------------------------------------------------------------
! START THE STEP SYSTEM EVOLUTION FOR nsteps
!-----------------------------------------------------------------------------
DO 100 n=1,nsteps
step_rt = MPI_WTIME()
!-----------------------------------------------------------------------
! Dynamic input parameter - START
!-----------------------------------------------------------------------
!-----------------------------------------------------------------------
! Open data files, read input parameters and initial system state,
! and reset system parameters.
!-----------------------------------------------------------------------
CALL inpar_dyn
!-----------------------------------------------------------------------
! Open out_32.tab file: List of programmed output (in redshift value)
! and reset system parameters.
!-----------------------------------------------------------------------
CALL read_redsh ! reading out32
!-----------------------------------------------------------------------
! Dynamic input parameter - STOP
!-----------------------------------------------------------------------
IF(halt_sim.eq.1 .or. halt_sim.eq.2) EXIT !Stop Simulation
!-----------------------------------------------------------------------
! System Evolution
!-----------------------------------------------------------------------
CALL step(n)
CALL MPI_BARRIER(MPI_COMM_WORLD,ierror)
step_rt=MPI_WTIME()-step_rt
psec=step_rt
IF(me.eq.0) THEN
write(uterm,*) '--------------- step ',tstep, &
' executed sec =',step_rt
call flush(uterm)
ENDIF
CALL MPI_BARRIER(MPI_COMM_WORLD,ierror)
!-------------------------------------------------
! WRITE STATISTICAL TIMING
!-------------------------------------------------
IF(me.eq.0) THEN
write(uterm,*) '--------------- Local_computation: ----------------- '
write(uterm,1000) 'PE',me,': ACCGRAV ', ctota
call flush(uterm)
DO ind_pe=1,npes-1
CALL MPI_RECV(ctota, 1, MPI_REAL8, ind_pe, tag0 ,MPI_COMM_WORLD , istatus,ierror)
write(uterm,1000) 'PE', ind_pe,': ACCGRAV ', ctota
call flush(uterm)
ENDDO
ELSE
CALL MPI_SEND(ctota,1,MPI_REAL8,PE0,tag0,MPI_COMM_WORLD, ierror)
ENDIF
CALL MPI_BARRIER(MPI_COMM_WORLD,ierror)
CALL MPI_BARRIER(MPI_COMM_WORLD,ierror)
IF(me.eq.0) THEN
write(uterm,*) '--------------- Remote_computation: ----------------- '
write(uterm,1000) 'PE',me,': ACC_EX ',ctotc
call flush(uterm)
DO ind_pe=1,npes-1
CALL MPI_RECV(ctotc, 1, MPI_REAL8, ind_pe, tag0 ,MPI_COMM_WORLD , istatus,ierror)
write(uterm,1000) 'PE', ind_pe,': ACC_EX ',ctotc
call flush(uterm)
ENDDO
write(uterm,*) '------------------------------------------------------ '
write(uterm,*)'PARTICLE/seconds =',nbodies/psec
call flush(uterm)
ELSE
CALL MPI_SEND(ctotc,1,MPI_REAL8,PE0,tag0,MPI_COMM_WORLD, ierror)
ENDIF
1000 format(x,a,i3,2x,3(a,g18.8,2X))
1100 format(x,3(a,g18.8,2X))
!-----------------------------------------------------------------------------
! Check for stop simulation
!-----------------------------------------------------------------------------
IF(halt_sim.ne.0) EXIT !Stop Simulation
tot_sec=tot_sec+psec
prev_sec=tot_sec+2*psec*1.20
IF(max_time .gt. 0) THEN
IF(prev_sec .ge. max_time) THEN
halt_sim=3
IF(me.eq.0) THEN
write(uterm,*)' '
write(uterm,*)'--------------------------------------------'
write(uterm,*)' CPU TIME LIMIT REACHED NEXT STEP '
write(uterm,*)'--------------------------------------------'
write(uterm,*)'Actual cpu time = ',tot_sec
write(uterm,*)'Forecast cpu time = ',tot_sec+2*psec*1.20
write(uterm,*)'Maximum cpu time = ',max_time
write(uterm,*)'--------------------------------------------'
write(uterm,*)' '
ENDIF
ELSE
IF(me.eq.0) THEN
write(uterm,*)' '
write(uterm,*)'--------------------------------------------'
write(uterm,*)' CPU TIME LIMIT COUNTING '
write(uterm,*)'--------------------------------------------'
write(uterm,*)'Actual cpu time = ',tot_sec
write(uterm,*)'Forecast cpu time = ',tot_sec+2*psec*1.20
write(uterm,*)'Maximum cpu time = ',max_time
write(uterm,*)'--------------------------------------------'
write(uterm,*)' '
ENDIF
ENDIF
ENDIF
100 CONTINUE ! continue to the next step system evolution
!-----------------------------------------------------------------------------
! END OF STEP SYSTEM EVOLUTION and Terminate the run
!-----------------------------------------------------------------------------
CALL MPI_BARRIER(MPI_COMM_WORLD,ierror)
init_tot2 = MPI_WTIME()
init_tot = init_tot2 - init_tot1
IF((tst_max.le.tstep).and.(halt_sim.eq.0) ) halt_sim=3
IF(me.eq.0) THEN
write(uterm,*)'TOTAL: executed =',init_tot,' sec.'
IF(tst_max.le.tstep) THEN
write(uterm,*)'SIMULATION STOPED: reached MAX STEP value'
ENDIF
IF(halt_sim.eq.1 .or. halt_sim.eq.2) THEN
write(uterm,*)'SIMULATION STOPED: reached final readshift value'
ENDIF
IF(halt_sim.eq.3) THEN
write(uterm,*)'SIMULATION STOPED: reached maximum cpu limit'
ENDIF
ENDIF
#ifdef FLASH
if(me == 0) then
call MPI_UNPUBLISH_NAME('particleInterface', MPI_INFO_NULL, &
portName, ierror)
call MPI_CLOSE_PORT(portName, ierror)
end if
call MPI_COMM_DISCONNECT(flashComm, ierror)
#endif
call MPI_Finalize(ierror)
STOP
END