Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing get/set MPI.File info functions #421

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
jakebolewski marked this conversation as resolved.
Show resolved Hide resolved
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

@jakebolewski jakebolewski Sep 8, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think i need to play around with OpenMPI's MPI IO implementation some more to understand what the defaults are across different versions. The CI build also doesn't seem to preserve valid file hints.


# 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