Skip to content

Commit 74d2d6e

Browse files
committed
add missing get/set MPI.File info functions
1 parent e803f2b commit 74d2d6e

File tree

3 files changed

+66
-2
lines changed

3 files changed

+66
-2
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ libjuliampi.dylib
33
*.cov
44
*.mem
55
Manifest.toml
6+
.vscode

src/io.jl

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,36 @@ function close(file::FileHandle)
7171
return nothing
7272
end
7373

74+
# Info
75+
"""
76+
MPI.File.get_info(file::FileHandle)
77+
78+
Returns the hints for a file that are actually being used by MPI.
79+
80+
# External links
81+
$(_doc_external("MPI_File_get_info"))
82+
"""
83+
function get_info(file::FileHandle)
84+
file_info = Info(init=false)
85+
@mpichk ccall((:MPI_File_get_info, libmpi), Cint,
86+
(MPI_File, Ptr{MPI_Info}), file, file_info)
87+
return file_info
88+
end
89+
90+
"""
91+
MPI.File.set_info!(file::FileHandle, info::Info)
92+
93+
Collectively sets new values for the hints associated with a MPI.File.FileHandle.
94+
95+
# External links
96+
$(_doc_external("MPI_File_set_info"))
97+
"""
98+
function set_info!(file::FileHandle, info::Info)
99+
@mpichk ccall((:MPI_File_set_info, libmpi), Cint,
100+
(MPI_File, MPI_Info), file, info)
101+
return file
102+
end
103+
74104
# View
75105
"""
76106
MPI.File.set_view!(file::FileHandle, disp::Integer, etype::Datatype, filetype::Datatype, datarep::AbstractString; kwargs...)
@@ -322,7 +352,7 @@ $(_doc_external("MPI_File_write_ordered"))
322352
function write_ordered(file::FileHandle, buf::Buffer)
323353
stat_ref = Ref{Status}(MPI.STATUS_EMPTY)
324354
# int MPI_File_write_ordered(MPI_File fh, const void *buf, int count,
325-
# MPI_Datatype datatype, MPI_Status *status)
355+
# MPI_Datatype datatype, MPI_Status *status)
326356
@mpichk ccall((:MPI_File_write_ordered, libmpi), Cint,
327357
(MPI_File, MPIPtr, Cint, MPI_Datatype, Ptr{Status}),
328358
file, buf.data, buf.count, buf.datatype, stat_ref)
@@ -335,7 +365,7 @@ write_ordered(file::FileHandle, buf) = write_ordered(file, Buffer_send(buf))
335365
SEEK_SET = MPI.MPI_SEEK_SET
336366
SEEK_CUR = MPI.MPI_SEEK_CUR
337367
SEEK_END = MPI.MPI_SEEK_END
338-
end
368+
end
339369

340370
"""
341371
MPI.File.seek_shared(file::FileHandle, offset::Integer, whence::Seek=SEEK_SET)

test/test_io.jl

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,36 @@ data = zeros(Int64, 1)
4545
MPI.File.read_at_all!(fh, rank*2, data)
4646
@test data == [rank == 0 ? -1 : rank+1]
4747
close(fh)
48+
49+
MPI.Barrier(comm)
50+
51+
# File Info hints
52+
fh = MPI.File.open(comm, filename, read=true)
53+
fh_info = MPI.File.get_info(fh)
54+
55+
# test that there are some default file mpi-io hints
56+
# specific hints are implementation specific
57+
@test length(keys(fh_info)) > 0
58+
59+
# File Info hints are implementation specific
60+
# so test MPICH dervived implementations
61+
if MPI.MPI_LIBRARY in (MPI.MPICH, MPI.MicrosoftMPI, MPI.IntelMPI, MPI.MVAPICH, MPI.CrayMPICH)
62+
# Test that default info hints on mpi-io implementation are present
63+
# cb_buffer_size is one of the reserved MPI 3.1 keywords
64+
@test parse(Int, fh_info[:cb_buffer_size]) > 0
65+
66+
# Test that we can attach custom info to an existing FileHandle
67+
MPI.File.set_info!(fh, MPI.Info(:cb_buffer_size=>33554432))
68+
fh_info = MPI.File.get_info(fh)
69+
@test parse(Int, fh_info[:cb_buffer_size]) == 33554432
70+
71+
elseif MPI.MPI_LIBRARY == MPI.OpenMPI
72+
73+
# Test that default info hints on mpi-io implementation are present
74+
@test parse(Int, fh_info[:coll_write_bufsize]) > 0
75+
76+
# Test that we can attach custom info to an existing FileHandle
77+
MPI.File.set_info!(fh, MPI.Info(:coll_write_bufsize=>33554432))
78+
fh_info = MPI.File.get_info(fh)
79+
@test parse(Int, fh_info[:coll_write_bufsize]) == 33554432
80+
end

0 commit comments

Comments
 (0)