-
Notifications
You must be signed in to change notification settings - Fork 5
/
benchio.f90
381 lines (267 loc) · 8.51 KB
/
benchio.f90
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
program benchio
use benchclock
use benchcomm
use mpiio
use ioserial
use iohdf5
use ionetcdf
use adios
implicit none
integer, parameter :: numiolayer = 7
integer, parameter :: numstriping = 3
integer, parameter :: maxlen = 64
character*(maxlen), dimension(numiolayer) :: iostring, iolayername
character*(maxlen), dimension(numstriping) :: stripestring
character*(maxlen) :: argstring
logical :: ioflag, stripeflag, globalflag
logical, dimension(numiolayer) :: doio
logical, dimension(numstriping) :: dostripe
character*(maxlen) :: filename, suffix
integer :: iolayer, istriping, iolayermulti, iolayernode, numarg, iarg
! Set local array size - global sizes l1, l2 and l3 are scaled
! by number of processes in each dimension
integer, parameter :: n1def = 128
integer, parameter :: n2def = 128
integer, parameter :: n3def = 128
integer :: i1, i2, i3, j1, j2, j3, n1, n2, n3, l1, l2, l3, p1, p2, p3
double precision, allocatable, dimension(:,:,:) :: iodata
integer :: rank, size, ierr, comm, cartcomm, iocomm, dblesize
integer, dimension(ndim) :: dims, coords
integer, parameter :: iounit = 12
integer, parameter :: kib = 1024
integer, parameter :: mib = kib*kib
integer, parameter :: gib = kib*mib
logical :: reorder = .false.
logical, dimension(ndim) :: periods = [.false., .false., .false.]
double precision :: t0, t1, time, iorate, gibdata
stripestring(1) = "unstriped"
stripestring(2) = "striped"
stripestring(3) = "fullstriped"
! These versions are special as they creates many files so need to record this
iolayermulti = 2
iolayernode = 3
iostring(1) = "Serial"
iostring(2) = " Proc"
iostring(3) = " Node "
iostring(4) = "MPI-IO"
iostring(5) = " HDF5 "
iostring(6) = "NetCDF"
iostring(7) = "Adios2"
iolayername(1) = "serial"
iolayername(2) = "proc"
iolayername(3) = "node"
iolayername(4) = "mpiio"
iolayername(5) = "hdf5"
iolayername(6) = "netcdf"
iolayername(7) = "adios"
call MPI_Init(ierr)
comm = MPI_COMM_WORLD
call MPI_Comm_size(comm, size, ierr)
call MPI_Comm_rank(comm, rank, ierr)
! Parse the arguments
doio(:) = .false.
dostripe(:) = .false.
numarg = command_argument_count()
if (numarg < 4) then
if (rank == 0) then
write(*,*) "usage: benchio (n1, n2, n3) (local|global) [serial] [proc] [node]"
write(*,*) " [mpiio] [hdf5] [netcdf] [adios] [unstriped] [striped] [fullstriped]"
end if
call MPI_Finalize(ierr)
stop
end if
call get_command_argument(1, argstring)
read(argstring,*) n1
call get_command_argument(2, argstring)
read(argstring,*) n2
call get_command_argument(3, argstring)
read(argstring,*) n3
globalflag = .true.
call get_command_argument(4, argstring)
if (argstring == "local") globalflag = .false.
do iarg = 5, numarg
ioflag = .false.
stripeflag = .false.
call get_command_argument(iarg, argstring)
do iolayer = 1, numiolayer
if (iolayername(iolayer) == argstring) then
ioflag = .true.
doio(iolayer) = .true.
end if
end do
do istriping = 1, numstriping
if (stripestring(istriping) == argstring) then
stripeflag = .true.
dostripe(istriping) = .true.
end if
end do
if (.not.ioflag .and. .not.stripeflag) then
write(*,*) "Illegal argument: ", argstring
call MPI_Finalize(ierr)
stop
end if
end do
! Check defaults
if (count(doio(:)) == 0) then
doio(:) = .true.
end if
if (count(dostripe(:)) == 0) then
dostripe(:) = .true.
end if
! Set 3D processor grid
dims(:) = 0
call MPI_Dims_create(size, ndim, dims, ierr)
! Reverse dimensions as MPI assumes C ordering (this is not essential)
p1 = dims(3)
p2 = dims(2)
p3 = dims(1)
! Compute local sizes if required
if (globalflag) then
n1 = n1/p1
n2 = n2/p2
n3 = n3/p3
end if
! Compute global sizes
l1 = p1*n1
l2 = p2*n2
l3 = p3*n3
call MPI_Type_size(MPI_DOUBLE_PRECISION, dblesize, ierr)
gibdata = float(dblesize)*float(n1)*float(n2)*float(n3)*float(p1*p2*p3)
gibdata = gibdata/float(gib)
dims(1) = p1
dims(2) = p2
dims(3) = p3
call MPI_Cart_create(comm, ndim, dims, periods, reorder, cartcomm, ierr)
if (rank == 0) then
write(*,*)
write(*,*) "Simple Parallel IO benchmark"
write(*,*) "----------------------------"
write(*,*)
write(*,*) "Running on ", size, " process(es)"
write(*,*)
end if
! Set up nodal stuff
call initbenchnode(cartcomm)
if (rank == 0) then
write(*,*)
write(*,*) "Process grid is (", p1, ", ", p2, ", ", p3, ")"
write(*,*) "Array size is (", n1, ", ", n2, ", ", n3, ")"
write(*,*) "Global size is (", l1, ", ", l2, ", ", l3, ")"
write(*,*)
write(*,*) "Total amount of data = ", gibdata, " GiB"
write(*,*)
write(*,*) "Clock resolution is ", benchtick()*1.0e6, ", usecs"
write(*,*)
write(*,*) "Using the following IO methods"
write(*,*) "------------------------------"
do iolayer = 1, numiolayer
if (doio(iolayer)) write(*,*) iolayername(iolayer)
end do
write(*,*)
write(*,*) "Using the following stripings"
write(*,*) "-----------------------------"
do istriping = 1, numstriping
if (dostripe(istriping)) write(*,*) stripestring(istriping)
end do
write(*,*)
end if
! Allocate data
allocate(iodata(0:n1+1, 0:n2+1, 0:n3+1))
! Set halos to illegal values
iodata(:,:,:) = -1
! Set iodata core to have unique values 1, 2, ..., p1*n1*p2*n2*p3*n3
call MPI_Cart_coords(cartcomm, rank, ndim, coords, ierr)
do i3 = 1, n3
do i2 = 1, n2
do i1 = 1, n1
j1 = coords(1)*n1 + i1
j2 = coords(2)*n2 + i2
j3 = coords(3)*n3 + i3
iodata(i1,i2,i3) = (j3-1)*l1*l2 + (j2-1)*l1 + j1
end do
end do
end do
do iolayer = 1, numiolayer
if (.not. doio(iolayer)) cycle
if (rank == 0) then
write(*,*)
write(*,*) "------"
write(*,*) iostring(iolayer)
write(*,*) "------"
write(*,*)
end if
! if (iolayer == 3 .or. iolayer == 4) then
!
! if (rank == 0) then
! write(*,*) "WARNING: Skipping ", iostring(iolayer)
! end if
!
! cycle
!
! end if
do istriping = 1, numstriping
if (.not. dostripe(istriping)) cycle
filename = trim(stripestring(istriping))//"/"//trim(iolayername(iolayer))
suffix = ""
iocomm = cartcomm
! Deal with multiple files
if (iolayer == iolayermulti) then
iocomm = MPI_COMM_SELF
write(suffix,fmt="(i6.6)") rank
end if
if (iolayer == iolayernode) then
iocomm = nodecomm
write(suffix,fmt="(i6.6)") nodenum
end if
suffix = trim(suffix)//".dat"
filename = trim(filename)//suffix
if (rank == 0) then
write(*,*) "Writing to ", filename
end if
call MPI_Barrier(comm, ierr)
t0 = benchtime()
select case (iolayer)
case(1:3)
call serialwrite(filename, iodata, n1, n2, n3, iocomm)
case(4)
call mpiiowrite(filename, iodata, n1, n2, n3, iocomm)
case(5)
call hdf5write(filename, iodata, n1, n2, n3, iocomm)
case(6)
call netcdfwrite(filename, iodata, n1, n2, n3, iocomm)
case(7)
call adioswrite(filename, iodata, n1, n2, n3, iocomm)
case default
write(*,*) "Illegal value of iolayer = ", iolayer
stop
end select
call MPI_Barrier(comm, ierr)
t1 = benchtime()
time = t1 - t0
iorate = gibdata/time
if (rank == 0) then
write(*,*) "time = ", time, ", rate = ", iorate, " GiB/s"
end if
! Rank 0 in iocomm deletes
if (iolayer == 7) then
! ADIOS makes a directory so the file deletion function will not work
! use the shell instead
call MPI_Barrier(comm, ierr)
if (rank == 0) then
call execute_command_line("rm -r "//filename)
end if
call MPI_Barrier(comm, ierr)
else
call bossdelete(filename, iocomm)
endif
end do
end do
if (rank == 0) then
write(*,*)
write(*,*) "--------"
write(*,*) "Finished"
write(*,*) "--------"
write(*,*)
end if
call MPI_Finalize(ierr)
end program benchio