Skip to content

Commit 2789705

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

File tree

3 files changed

+72
-3
lines changed

3 files changed

+72
-3
lines changed

.gitignore

+1
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

+35-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ FileHandle() = FileHandle(FILE_NULL.val)
44

55
module File
66

7-
import MPI: MPI, @mpichk, _doc_external, MPIPtr, libmpi, refcount_inc, refcount_dec,
7+
import MPI: MPI, @mpichk, _doc_external, MPIPtr, libmpi, refcount_inc, refcount_dec, free,
88
Comm, MPI_Comm, FileHandle, MPI_File, Info, MPI_Info, FILE_NULL,
99
Datatype, MPI_Datatype, MPI_Offset, Status, Buffer, Buffer_send
1010
import Base: close
@@ -71,6 +71,38 @@ 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+
refcount_inc()
88+
finalizer(free, file_info)
89+
return file_info
90+
end
91+
92+
"""
93+
MPI.File.set_info!(file::FileHandle, info::Info)
94+
95+
Collectively sets new values for the hints associated with a MPI.File.FileHandle.
96+
97+
# External links
98+
$(_doc_external("MPI_File_set_info"))
99+
"""
100+
function set_info!(file::FileHandle, info::Info)
101+
@mpichk ccall((:MPI_File_set_info, libmpi), Cint,
102+
(MPI_File, MPI_Info), file, info)
103+
return file
104+
end
105+
74106
# View
75107
"""
76108
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"))
322354
function write_ordered(file::FileHandle, buf::Buffer)
323355
stat_ref = Ref{Status}(MPI.STATUS_EMPTY)
324356
# int MPI_File_write_ordered(MPI_File fh, const void *buf, int count,
325-
# MPI_Datatype datatype, MPI_Status *status)
357+
# MPI_Datatype datatype, MPI_Status *status)
326358
@mpichk ccall((:MPI_File_write_ordered, libmpi), Cint,
327359
(MPI_File, MPIPtr, Cint, MPI_Datatype, Ptr{Status}),
328360
file, buf.data, buf.count, buf.datatype, stat_ref)
@@ -335,7 +367,7 @@ write_ordered(file::FileHandle, buf) = write_ordered(file, Buffer_send(buf))
335367
SEEK_SET = MPI.MPI_SEEK_SET
336368
SEEK_CUR = MPI.MPI_SEEK_CUR
337369
SEEK_END = MPI.MPI_SEEK_END
338-
end
370+
end
339371

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

test/test_io.jl

+36
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,39 @@ 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+
# File Info hints are implementation specific
56+
# so test MPICH dervived implementations
57+
if MPI.MPI_LIBRARY in (MPI.MPICH, MPI.MicrosoftMPI, MPI.IntelMPI, MPI.MVAPICH, MPI.CrayMPICH)
58+
59+
# MPICH sets some default MPI-IO hints
60+
@test length(keys(fh_info)) > 0
61+
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+
# OpenMPI does not set any MPI-IO hints by default
74+
@test length(keys(fh_info)) == 0
75+
76+
# Test that default info hints on mpi-io implementation are present
77+
@test parse(Int, fh_info[:coll_write_bufsize]) > 0
78+
79+
# Test that we can attach custom info to an existing FileHandle
80+
MPI.File.set_info!(fh, MPI.Info(:coll_write_bufsize=>33554432))
81+
fh_info = MPI.File.get_info(fh)
82+
@test parse(Int, fh_info[:coll_write_bufsize]) == 33554432
83+
end

0 commit comments

Comments
 (0)