-
Notifications
You must be signed in to change notification settings - Fork 0
/
p0mod.f
529 lines (529 loc) · 16.6 KB
/
p0mod.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
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
!-----------------------------------------------------------------------
!
module p0d
!
! Fortran90 interface to 2d parallel PIC Fortran77 library p0lib.f
! p0mod.f contains interface procedures for communications with 1d
! partitions:
! defines module p0d
! get_funit returns an unconnected fortran unit number.
! pwtimer performs synchronized parallel wall clock timing.
! calls PTIMERA
! wtimer performs parallel local wall clock timing.
! calls PWTIMERA
! plsum => ipsum performs global sum of 1d real array.
! calls PSUM
! plsum => ipisum performs global sum of 1d integer array.
! calls PISUM
! plsum => ipcsum perform2 global sum of 1d complex array.
! calls PCSUM
! plmax => ipmax performs global maximum of 1d real array.
! calls PMAX
! plmax => ipimax performs global maximum of 1d integer array.
! calls PIMAX
! plscan => ipscan performs parallel prefix sum reduction of 1d real
! array.
! calls PSCAN
! plscan => ipiscan performs parallel prefix sum reduction of 1d integer
! array.
! calls PISCAN
! plbcast => ipbcast broadcasts 1d real array.
! calls PBCAST
! plbcast => ipbicast broadcasts 1d integer array.
! calls PBICAST
! plbcast => ipbccast broadcasts 1d complex array.
! calls PBCCAST
! writef => ipwrite1 collects distributed real 2d scalar array and
! writes it to a direct access binary file.
! calls PWRITE1
! readf => ipread1 reads distributed real 2d scalar array from a direct
! access binary file and distributes it.
! calls PREAD1
! wrdata => ipwrdata0 collects distributed real 1d scalar data and
! writes it to a fortran unformatted sequential file.
! calls PWRDATA
! rddata => iprddata0 reads real 1d scalar data from a fortran
! unformatted sequential file and distributes it.
! calls PRDDATA
! wrdata => ipwrcdata0 collects distributed complex 1d scalar data and
! writes it to a fortran unformatted sequential file.
! calls PWRDATA
! rddata => iprdcdata0 reads complex 1d scalar data from a fortran
! unformatted sequential file and distributes it.
! calls PRDDATA
! wrdata => ipwrpart collects distributed particle data and writes it to
! a fortran unformatted sequential file.
! calls PWRDATA
! rddata => iprdpart reads particle data from a fortran unformatted
! sequential file and distributes it .
! calls PRDPART
! written by viktor k. decyk, ucla
! copyright 2000, regents of the university of california
! update: november 13, 2009
!
use globals, only: LINEAR, QUADRATIC, STANDARD, LOOKAHEAD, VECTOR
implicit none
private
public :: LINEAR, QUADRATIC, STANDARD, LOOKAHEAD, VECTOR
public :: PPINIT, PPID, PPEXIT, HARTBEAT, PWRITE1, PREAD1
public :: get_funit, pwtimer, wtimer
public :: plsum, plmax, plscan, plbcast
public :: writef, readf, wrdata, rddata
!
! define interface to original Fortran77 procedures
!
interface
subroutine PPINIT(idproc,id0,nvp)
implicit none
integer :: idproc, id0, nvp
end subroutine
end interface
interface
subroutine PPID(idproc,id0,nvp)
implicit none
integer :: idproc, id0, nvp
end subroutine
end interface
interface
subroutine PPEXIT
end subroutine
end interface
interface
subroutine HARTBEAT(msg,n)
implicit none
integer :: n
double precision, dimension(n) :: msg
end subroutine
end interface
interface
subroutine PTIMERA(icntrl,time,dtime)
implicit none
integer :: icntrl
real, dimension(2) :: time
double precision :: dtime
end subroutine
end interface
interface
subroutine PWTIMERA(icntrl,time,dtime)
implicit none
integer :: icntrl
real :: time
double precision :: dtime
end subroutine
end interface
interface
subroutine PSUM(f,g,nxp,nblok)
implicit none
integer :: nxp, nblok
real, dimension(nxp,nblok) :: f, g
end subroutine
end interface
interface
subroutine PISUM(if,ig,nxp,nblok)
implicit none
integer :: nxp, nblok
integer, dimension(nxp,nblok) :: if, ig
end subroutine
end interface
interface
subroutine PCSUM(f,g,nxp,nblok)
implicit none
integer :: nxp, nblok
complex, dimension(nxp,nblok) :: f, g
end subroutine
end interface
interface
subroutine PDSUM(f,g,nxp,nblok)
implicit none
integer :: nxp, nblok
double precision, dimension(nxp,nblok) :: f, g
end subroutine
end interface
interface
subroutine PMAX(f,g,nxp,nblok)
implicit none
integer :: nxp, nblok
real, dimension(nxp,nblok) :: f, g
end subroutine
end interface
interface
subroutine PIMAX(if,ig,nxp,nblok)
implicit none
integer :: nxp, nblok
integer, dimension(nxp,nblok) :: if, ig
end subroutine
end interface
interface
subroutine PDMAX(f,g,nxp,nblok)
implicit none
integer :: nxp, nblok
double precision, dimension(nxp,nblok) :: f, g
end subroutine
end interface
interface
subroutine PSCAN(f,g,s,nxp,nblok)
implicit none
integer :: nxp, nblok
real, dimension(nxp,nblok) :: f, g, s
end subroutine
end interface
interface
subroutine PISCAN(if,ig,is,nxp,nblok)
implicit none
integer :: nxp, nblok
integer, dimension(nxp,nblok) :: if, ig, is
end subroutine
end interface
interface
subroutine PDSCAN(f,g,s,nxp,nblok)
implicit none
integer :: nxp, nblok
double precision, dimension(nxp,nblok) :: f, g, s
end subroutine
end interface
interface
subroutine PBCAST(f,nxp)
implicit none
integer :: nxp
real, dimension(nxp) :: f
end subroutine
end interface
interface
subroutine PBICAST(f,nxp)
implicit none
integer :: nxp
integer, dimension(nxp) :: f
end subroutine
end interface
interface
subroutine PBCCAST(f,nxp)
implicit none
integer :: nxp
complex, dimension(nxp) :: f
end subroutine
end interface
interface
subroutine PBDCAST(f,nxp)
implicit none
integer :: nxp
double precision, dimension(nxp) :: f
end subroutine
end interface
interface
subroutine PWRITE1(f,nxp,iunit,nrec,name)
implicit none
integer :: nxp, iunit, nrec
character(len=*) :: name
real, dimension(nxp) :: f
end subroutine
end interface
interface
subroutine PREAD1(f,nxp,iunit,nrec,name)
implicit none
integer :: nxp, iunit, nrec
character(len=*) :: name
real, dimension(nxp) :: f
end subroutine
end interface
interface
subroutine PWRPART(part,npp,idimp,npmax,nblok,iunit)
implicit none
integer :: idimp, npmax, nblok, iunit
real, dimension(idimp,npmax,nblok) :: part
integer, dimension(nblok) :: npp
end subroutine
end interface
interface
subroutine PRDPART(part,npp,idimp,npmax,nblok,iunit,ierror)
implicit none
integer :: idimp, npmax, nblok, iunit, ierror
real, dimension(idimp,npmax,nblok) :: part
integer, dimension(nblok) :: npp
end subroutine
end interface
!
! define generic interface to Fortran90 library
!
interface plsum
module procedure ipsum
module procedure ipisum
module procedure ipcsum
end interface
!
interface plmax
module procedure ipmax
module procedure ipimax
end interface
!
interface plscan
module procedure ipscan
module procedure ipiscan
end interface
!
interface plbcast
module procedure ipbcast
module procedure ipbicast
module procedure ipbccast
end interface
!
interface writef
module procedure ipwrite1
end interface
!
interface readf
module procedure ipread1
end interface
!
interface wrdata
module procedure ipwrdata0
module procedure ipwrcdata0
module procedure ipwrpart
end interface
!
interface rddata
module procedure iprddata0
module procedure iprdcdata0
module procedure iprdpart
end interface
!
! define Fortran90 interface functions to Fortran77 library
!
contains
!
function get_funit(start) result(funit)
! this function returns an unconnected fortran unit number,
! starting with unit = start. returns -1 if none found
integer, intent(in) :: start
integer :: funit
! local data
integer :: i
logical :: connected
funit = -1
! check connection status
do i = start, 98
inquire(unit=i,opened=connected)
if (.not.connected) then
funit = i
exit
endif
enddo
end function get_funit
!
subroutine pwtimer(time,dtime,icntrl)
! parallel wall clock timer
implicit none
real, dimension(2), intent(out) :: time
double precision, intent(inout) :: dtime
integer, intent(in), optional :: icntrl
integer :: ltime
ltime = 1
if (present(icntrl)) ltime = icntrl
if (ltime==0) return
call PTIMERA(ltime,time,dtime)
end subroutine pwtimer
!
subroutine wtimer(time,dtime,icntrl)
! local wall clock timer
implicit none
real, intent(out) :: time
double precision, intent(inout) :: dtime
integer, intent(in), optional :: icntrl
integer :: ltime
ltime = 1
if (present(icntrl)) ltime = icntrl
if (ltime==0) return
call PWTIMERA(ltime,time,dtime)
end subroutine wtimer
!
subroutine ipsum(f)
! perform global sum of 1d real array
implicit none
real, dimension(:) :: f
integer :: nxp, nblok
real, dimension(size(f)) :: g
nxp = size(f); nblok = 1
call PSUM(f,g,nxp,nblok)
end subroutine ipsum
!
subroutine ipisum(if)
! perform global sum of 1d integer array
implicit none
integer, dimension(:) :: if
integer :: nxp, nblok
integer, dimension(size(if)) :: ig
nxp = size(if); nblok = 1
call PISUM(if,ig,nxp,nblok)
end subroutine ipisum
!
subroutine ipcsum(f)
! perform global sum of 1d complex array
implicit none
complex, dimension(:) :: f
integer :: nxp, nblok
complex, dimension(size(f)) :: g
nxp = size(f); nblok = 1
call PCSUM(f,g,nxp,nblok)
end subroutine ipcsum
!
subroutine ipmax(f)
! perform global maximum of 1d real array
implicit none
real, dimension(:) :: f
integer :: nxp, nblok
real, dimension(size(f)) :: g
nxp = size(f); nblok = 1
call PMAX(f,g,nxp,nblok)
end subroutine ipmax
!
subroutine ipimax(if)
! perform global maximum of 1d integer array
implicit none
integer, dimension(:) :: if
integer :: nxp, nblok
integer, dimension(size(if)) :: ig
nxp = size(if); nblok = 1
call PIMAX(if,ig,nxp,nblok)
end subroutine ipimax
!
subroutine ipscan(f)
! perform parallel prefix sum reduction of 1d real array
implicit none
real, dimension(:) :: f
integer :: nxp, nblok
real, dimension(size(f)) :: g, s
nxp = size(f); nblok = 1
call PSCAN(f,g,s,nxp,nblok)
end subroutine ipscan
!
subroutine ipiscan(if)
! perform parallel prefix sum reduction of 1d integer array
implicit none
integer, dimension(:) :: if
integer :: nxp, nblok
integer, dimension(size(if)) :: ig, is
nxp = size(if); nblok = 1
call PISCAN(if,ig,is,nxp,nblok)
end subroutine ipiscan
!
subroutine ipbcast(f)
! broadcast 1d real array
implicit none
real, dimension(:) :: f
integer :: nxp
nxp = size(f)
call PBCAST(f,nxp)
end subroutine ipbcast
!
subroutine ipbicast(if)
! broadcast 1d integer array
implicit none
integer, dimension(:) :: if
integer :: nxp
nxp = size(if)
call PBICAST(if,nxp)
end subroutine ipbicast
!
subroutine ipbccast(f)
! broadcast 1d complex array
implicit none
complex, dimension(:) :: f
integer :: nxp
nxp = size(f)
call PBCCAST(f,nxp)
end subroutine ipbccast
!
subroutine ipwrite1(f,iunit,nrec,name)
! collects distributed real 2d scalar array and writes it to a
! direct access binary file, for uniform 1d partitions
implicit none
integer :: iunit, nrec
real, dimension(:,:,:), pointer :: f
character(len=*) :: name
integer :: nxp
nxp = size(f)
call PWRITE1(f,nxp,iunit,nrec,name)
end subroutine ipwrite1
!
subroutine ipread1(f,iunit,nrec,name)
! reads distributed real 2d scalar array from a direct access
! binary file and distributes it, for uniform 1d partitions
implicit none
integer :: iunit, nrec
real, dimension(:,:,:), pointer :: f
character(len=*) :: name
integer :: nxp
nxp = size(f)
call PREAD1(f,nxp,iunit,nrec,name)
end subroutine ipread1
!
subroutine ipwrdata0(f,nvp,iunit)
! collects distributed real 1d scalar data and writes it to a
! fortran unformatted sequential file, for uniform 1d partitions
implicit none
integer :: nvp, iunit
real, dimension(:,:), pointer :: f
integer :: nxp, nblok
nxp = size(f); nblok = 1
call PWRDATA(f,nvp,nxp,nblok,iunit)
end subroutine ipwrdata0
!
subroutine iprddata0(f,nvp,iunit,ierror)
! reads real 1d scalar data from a fortran unformatted sequential file
! and distributes it, for uniform 1d partitions
implicit none
integer :: nvp, iunit, ierror
real, dimension(:,:), pointer :: f
integer :: nxp, nblok
nxp = size(f); nblok = 1
call PRDDATA(f,nvp,nxp,nblok,iunit,ierror)
end subroutine iprddata0
!
subroutine ipwrcdata0(f,nvp,iunit)
! collects distributed complex 1d scalar data and writes it to a
! fortran unformatted sequential file, for uniform 1d partitions
implicit none
integer :: nvp, iunit
complex, dimension(:,:), pointer :: f
integer :: nxp, nblok
nxp = size(f); nblok = 1
call PWRDATA(f,nvp,2*nxp,nblok,iunit)
end subroutine ipwrcdata0
!
subroutine iprdcdata0(f,nvp,iunit,ierror)
! reads complex 1d scalar data from a fortran unformatted sequential
! file and distributes it, for uniform 1d partitions
implicit none
integer :: nvp, iunit, ierror
complex, dimension(:,:), pointer :: f
integer :: nxp, nblok
nxp = size(f); nblok = 1
call PRDDATA(f,nvp,2*nxp,nblok,iunit,ierror)
end subroutine iprdcdata0
!
subroutine ipwrpart(part,npp,iunit)
! collects distributed particle data and writes it to a fortran
! unformatted sequential file, for 1d partitions
implicit none
integer :: iunit
real, dimension(:,:,:), pointer :: part
integer, dimension(:), pointer :: npp
integer :: idimp, npmax, nblok
idimp = size(part,1); npmax = size(part,2)
nblok = size(part,3)
call PWRPART(part,npp,idimp,npmax,nblok,iunit)
end subroutine ipwrpart
!
subroutine iprdpart(part,npp,iunit,ierror)
! reads particle data from a fortran unformatted sequential file and
! distributes it, for 1d partitions
implicit none
integer :: iunit, ierror
real, dimension(:,:,:), pointer :: part
integer, dimension(:), pointer :: npp
integer :: idimp, npmax, nblok
idimp = size(part,1); npmax = size(part,2)
nblok = size(part,3)
call PRDPART(part,npp,idimp,npmax,nblok,iunit,ierror)
end subroutine iprdpart
!
end module p0d