Skip to content

Commit 6f6b492

Browse files
committed
test: Improve readability
1 parent 4f33a8c commit 6f6b492

1 file changed

Lines changed: 19 additions & 18 deletions

File tree

test/test_io_shared.jl

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
include("common.jl")
22

3+
# Syncing parallel MPI I/O is a bit involved:
4+
function sync(comm, fh)
5+
# First ensure that all local changes are flushed ...
6+
MPI.File.sync(fh)
7+
# ... then wait for all other process to finish doing that ...
8+
MPI.Barrier(comm)
9+
# ... then make sure we see all changes that the other processes made.
10+
MPI.File.sync(fh)
11+
end
12+
313
# Find MPI vendor
414
library_version = MPI.Get_library_version()
515
# Peel off MPItrampoline if present
@@ -25,66 +35,57 @@ filename = MPI.bcast(tempname(), 0, comm)
2535
fh = MPI.File.open(comm, filename, read=true, write=true, create=true)
2636
@test MPI.File.get_position_shared(fh) == 0
2737

28-
function sync()
29-
# First ensure that all local changes are flushed ...
30-
MPI.File.sync(fh)
31-
# ... then wait for all other process to finish doing that ...
32-
MPI.Barrier(comm)
33-
# ... then make sure we see all changes that the other processes made.
34-
MPI.File.sync(fh)
35-
end
36-
3738
if !MPI.File.get_atomicity(fh)
3839
MPI.File.set_atomicity(fh, true)
3940
end
4041
@test MPI.File.get_atomicity(fh)
41-
sync()
42+
sync(comm, fh)
4243

4344
header = "my header"
4445

4546
if rank == 0
4647
MPI.File.write_shared(fh, header)
4748
end
48-
sync()
49+
sync(comm, fh)
4950

5051
offset = MPI.File.get_position_shared(fh)
5152
@test offset == sizeof(header)
5253
byte_offset = MPI.File.get_byte_offset(fh, offset)
5354
@test byte_offset == offset
5455

5556
MPI.File.set_view!(fh, byte_offset, MPI.Datatype(Int64), MPI.Datatype(Int64))
56-
sync()
57+
sync(comm, fh)
5758
@test MPI.File.get_position_shared(fh) == 0
5859

5960
MPI.File.write_ordered(fh, fill(Int64(rank), rank+1))
60-
sync()
61+
sync(comm, fh)
6162
# https://github.com/JuliaParallel/MPI.jl/issues/879
6263
@test MPI.File.get_position_shared(fh) == sum(1:sz) skip = (vendor == :MPICH && Sys.isapple())
6364

6465
MPI.File.seek_shared(fh, 0)
6566
@test MPI.File.get_position_shared(fh) == 0
66-
sync()
67+
sync(comm, fh)
6768

6869
buf = zeros(Int64, rank+1)
6970
MPI.File.read_ordered!(fh, buf)
7071
@test buf == fill(Int64(rank), rank+1)
71-
sync()
72+
sync(comm, fh)
7273

7374
# https://github.com/JuliaParallel/MPI.jl/issues/555
7475
@test MPI.File.get_position_shared(fh) == sum(1:sz) skip = Sys.iswindows()
7576

7677
MPI.File.set_view!(fh, 0, MPI.Datatype(UInt8), MPI.Datatype(UInt8))
77-
sync()
78+
sync(comm, fh)
7879
MPI.File.seek_shared(fh, 0)
7980
@test MPI.File.get_position_shared(fh) == 0
80-
sync()
81+
sync(comm, fh)
8182

8283
if rank == sz-1
8384
buf = Array{UInt8}(undef, sizeof(header))
8485
MPI.File.read_shared!(fh, buf)
8586
@test String(buf) == header
8687
end
87-
sync()
88+
sync(comm, fh)
8889

8990
@test MPI.File.get_position_shared(fh) == sizeof(header)
9091

0 commit comments

Comments
 (0)