diff --git a/.gitignore b/.gitignore index 7e3073987..db2f0a29a 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ libjuliampi.dylib *.cov *.mem Manifest.toml +.vscode diff --git a/src/io.jl b/src/io.jl index baa458e9a..f330181e4 100644 --- a/src/io.jl +++ b/src/io.jl @@ -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 @@ -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...) @@ -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) @@ -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) diff --git a/test/test_io.jl b/test/test_io.jl index 915ed116a..c910cb8ee 100644 --- a/test/test_io.jl +++ b/test/test_io.jl @@ -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