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 2789705
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 3 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
38 changes: 35 additions & 3 deletions src/io.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ FileHandle() = FileHandle(FILE_NULL.val)

module File

import MPI: MPI, @mpichk, _doc_external, MPIPtr, libmpi, refcount_inc, refcount_dec,
import MPI: MPI, @mpichk, _doc_external, MPIPtr, libmpi, refcount_inc, refcount_dec, free,
Comm, MPI_Comm, FileHandle, MPI_File, Info, MPI_Info, FILE_NULL,
Datatype, MPI_Datatype, MPI_Offset, Status, Buffer, Buffer_send
import Base: close
Expand Down Expand Up @@ -71,6 +71,38 @@ 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)
refcount_inc()
finalizer(free, 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 +354,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 +367,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
36 changes: 36 additions & 0 deletions test/test_io.jl
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,39 @@ 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)

# 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)

# MPICH sets some default MPI-IO hints
@test length(keys(fh_info)) > 0

# 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

# OpenMPI does not set any MPI-IO hints by default
@test length(keys(fh_info)) == 0

# 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 2789705

Please sign in to comment.