Skip to content

Commit

Permalink
add missing get/set MPI.File info functions
Browse files Browse the repository at this point in the history
  • Loading branch information
jakebolewski committed Sep 4, 2020
1 parent e803f2b commit 74d2d6e
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ libjuliampi.dylib
*.cov
*.mem
Manifest.toml
.vscode
34 changes: 32 additions & 2 deletions src/io.jl
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,36 @@ function close(file::FileHandle)
return nothing
end

# Info
"""
MPI.File.get_info(file::FileHandle)
Returns the hints for a file that are actually being used by MPI.
# External links
$(_doc_external("MPI_File_get_info"))
"""
function get_info(file::FileHandle)
file_info = Info(init=false)
@mpichk ccall((:MPI_File_get_info, libmpi), Cint,
(MPI_File, Ptr{MPI_Info}), file, file_info)
return file_info
end

"""
MPI.File.set_info!(file::FileHandle, info::Info)
Collectively sets new values for the hints associated with a MPI.File.FileHandle.
# External links
$(_doc_external("MPI_File_set_info"))
"""
function set_info!(file::FileHandle, info::Info)
@mpichk ccall((:MPI_File_set_info, libmpi), Cint,
(MPI_File, MPI_Info), file, info)
return file
end

# View
"""
MPI.File.set_view!(file::FileHandle, disp::Integer, etype::Datatype, filetype::Datatype, datarep::AbstractString; kwargs...)
Expand Down Expand Up @@ -322,7 +352,7 @@ $(_doc_external("MPI_File_write_ordered"))
function write_ordered(file::FileHandle, buf::Buffer)
stat_ref = Ref{Status}(MPI.STATUS_EMPTY)
# int MPI_File_write_ordered(MPI_File fh, const void *buf, int count,
# MPI_Datatype datatype, MPI_Status *status)
# MPI_Datatype datatype, MPI_Status *status)
@mpichk ccall((:MPI_File_write_ordered, libmpi), Cint,
(MPI_File, MPIPtr, Cint, MPI_Datatype, Ptr{Status}),
file, buf.data, buf.count, buf.datatype, stat_ref)
Expand All @@ -335,7 +365,7 @@ write_ordered(file::FileHandle, buf) = write_ordered(file, Buffer_send(buf))
SEEK_SET = MPI.MPI_SEEK_SET
SEEK_CUR = MPI.MPI_SEEK_CUR
SEEK_END = MPI.MPI_SEEK_END
end
end

"""
MPI.File.seek_shared(file::FileHandle, offset::Integer, whence::Seek=SEEK_SET)
Expand Down
33 changes: 33 additions & 0 deletions test/test_io.jl
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,36 @@ data = zeros(Int64, 1)
MPI.File.read_at_all!(fh, rank*2, data)
@test data == [rank == 0 ? -1 : rank+1]
close(fh)

MPI.Barrier(comm)

# File Info hints
fh = MPI.File.open(comm, filename, read=true)
fh_info = MPI.File.get_info(fh)

# test that there are some default file mpi-io hints
# specific hints are implementation specific
@test length(keys(fh_info)) > 0

# File Info hints are implementation specific
# so test MPICH dervived implementations
if MPI.MPI_LIBRARY in (MPI.MPICH, MPI.MicrosoftMPI, MPI.IntelMPI, MPI.MVAPICH, MPI.CrayMPICH)
# Test that default info hints on mpi-io implementation are present
# cb_buffer_size is one of the reserved MPI 3.1 keywords
@test parse(Int, fh_info[:cb_buffer_size]) > 0

# Test that we can attach custom info to an existing FileHandle
MPI.File.set_info!(fh, MPI.Info(:cb_buffer_size=>33554432))
fh_info = MPI.File.get_info(fh)
@test parse(Int, fh_info[:cb_buffer_size]) == 33554432

elseif MPI.MPI_LIBRARY == MPI.OpenMPI

# Test that default info hints on mpi-io implementation are present
@test parse(Int, fh_info[:coll_write_bufsize]) > 0

# Test that we can attach custom info to an existing FileHandle
MPI.File.set_info!(fh, MPI.Info(:coll_write_bufsize=>33554432))
fh_info = MPI.File.get_info(fh)
@test parse(Int, fh_info[:coll_write_bufsize]) == 33554432
end

0 comments on commit 74d2d6e

Please sign in to comment.