Skip to content

Commit 3821ddd

Browse files
authored
Merge pull request #198 from tbole/add_functions
Add wrappers for MPI_Info related routines, MPI_COMM_SPLIT and timers
2 parents b7f8da7 + b78112e commit 3821ddd

File tree

8 files changed

+118
-4
lines changed

8 files changed

+118
-4
lines changed

deps/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ FortranCInterface_HEADER(jlmpi_f2c.h MACRO_NAMESPACE "JLMPI_" SYMBOLS
4141
MPI_COMM_RANK
4242
MPI_COMM_SIZE
4343
MPI_COMM_SPLIT
44+
MPI_COMM_SPLIT_TYPE
4445
MPI_EXSCAN
4546
MPI_FINALIZE
4647
MPI_FINALIZED
@@ -49,6 +50,12 @@ FortranCInterface_HEADER(jlmpi_f2c.h MACRO_NAMESPACE "JLMPI_" SYMBOLS
4950
MPI_GATHERV
5051
MPI_GET_COUNT
5152
MPI_GET_PROCESSOR_NAME
53+
MPI_INFO_CREATE
54+
MPI_INFO_DELETE
55+
MPI_INFO_FREE
56+
MPI_INFO_GET
57+
MPI_INFO_GET_VALUELEN
58+
MPI_INFO_SET
5259
MPI_INIT
5360
MPI_INITIALIZED
5461
MPI_IPROBE
@@ -81,6 +88,7 @@ FortranCInterface_HEADER(jlmpi_f2c.h MACRO_NAMESPACE "JLMPI_" SYMBOLS
8188
MPI_WAITALL
8289
MPI_WAITANY
8390
MPI_WAITSOME
91+
MPI_WTICK
8492
MPI_WTIME
8593
)
8694

deps/gen_constants.f90

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ program gen_constants
2828
call output("MPI_COMM_SELF ", MPI_COMM_SELF)
2929
call output("MPI_COMM_WORLD ", MPI_COMM_WORLD)
3030

31+
call output("MPI_COMM_TYPE_SHARED", MPI_COMM_TYPE_SHARED)
32+
3133
call output("MPI_OP_NULL ", MPI_OP_NULL)
3234
call output("MPI_BAND ", MPI_BAND)
3335
call output("MPI_BOR ", MPI_BOR)
@@ -45,6 +47,8 @@ program gen_constants
4547

4648
call output("MPI_REQUEST_NULL", MPI_REQUEST_NULL)
4749

50+
call output("MPI_INFO_NULL ", MPI_INFO_NULL)
51+
4852
call output("MPI_STATUS_SIZE ", MPI_STATUS_SIZE)
4953
call output("MPI_ERROR ", MPI_ERROR)
5054
call output("MPI_SOURCE ", MPI_SOURCE)

deps/gen_functions.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ int main(int argc, char *argv[]) {
3232
printf(" :MPI_COMM_RANK => \"%s\",\n", STRING(MPI_COMM_RANK));
3333
printf(" :MPI_COMM_SIZE => \"%s\",\n", STRING(MPI_COMM_SIZE));
3434
printf(" :MPI_COMM_SPLIT => \"%s\",\n", STRING(MPI_COMM_SPLIT));
35+
printf(" :MPI_COMM_SPLIT_TYPE => \"%s\",\n", STRING(MPI_COMM_SPLIT_TYPE));
3536
printf(" :MPI_EXSCAN => \"%s\",\n", STRING(MPI_EXSCAN));
3637
printf(" :MPI_FINALIZE => \"%s\",\n", STRING(MPI_FINALIZE));
3738
printf(" :MPI_FINALIZED => \"%s\",\n", STRING(MPI_FINALIZED));
@@ -40,6 +41,12 @@ int main(int argc, char *argv[]) {
4041
printf(" :MPI_GET_COUNT => \"%s\",\n", STRING(MPI_GET_COUNT));
4142
printf(" :MPI_GET_PROCESSOR_NAME => \"%s\",\n",
4243
STRING(MPI_GET_PROCESSOR_NAME));
44+
printf(" :MPI_INFO_CREATE => \"%s\",\n", STRING(MPI_INFO_CREATE));
45+
printf(" :MPI_INFO_DELETE => \"%s\",\n", STRING(MPI_INFO_DELETE));
46+
printf(" :MPI_INFO_FREE => \"%s\",\n", STRING(MPI_INFO_FREE));
47+
printf(" :MPI_INFO_GET => \"%s\",\n", STRING(MPI_INFO_GET));
48+
printf(" :MPI_INFO_GET_VALUELEN => \"%s\",\n", STRING(MPI_INFO_GET_VALUELEN));
49+
printf(" :MPI_INFO_SET => \"%s\",\n", STRING(MPI_INFO_SET));
4350
printf(" :MPI_INIT => \"%s\",\n", STRING(MPI_INIT));
4451
printf(" :MPI_INITIALIZED => \"%s\",\n", STRING(MPI_INITIALIZED));
4552
printf(" :MPI_IPROBE => \"%s\",\n", STRING(MPI_IPROBE));
@@ -70,14 +77,15 @@ int main(int argc, char *argv[]) {
7077
printf(" :MPI_WAITALL => \"%s\",\n", STRING(MPI_WAITALL));
7178
printf(" :MPI_WAITANY => \"%s\",\n", STRING(MPI_WAITANY));
7279
printf(" :MPI_WAITSOME => \"%s\",\n", STRING(MPI_WAITSOME));
80+
printf(" :MPI_WTICK => \"%s\",\n", STRING(MPI_WTICK));
7381
printf(" :MPI_WTIME => \"%s\",\n", STRING(MPI_WTIME));
7482
printf(" :MPI_TYPE_CREATE_STRUCT => \"%s\",\n",
7583
STRING(MPI_TYPE_CREATE_STRUCT));
7684
printf(" :MPI_TYPE_COMMIT => \"%s\",\n",
7785
STRING(MPI_TYPE_COMMIT));
7886
printf(")\n");
7987
printf("\n");
80-
printf("bitstype %d CComm\n", (int)(sizeof(MPI_Comm) * 8));
88+
printf("primitive type CComm %d end\n", (int)(sizeof(MPI_Comm) * 8));
8189

8290
return 0;
8391
}

src/mpi-base.jl

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,54 @@ mutable struct Request
9393
end
9494
const REQUEST_NULL = Request(MPI_REQUEST_NULL, nothing)
9595

96+
mutable struct Info
97+
val::Cint
98+
#val::Cint
99+
function Info()
100+
newinfo = Ref{Cint}()
101+
ccall(MPI_INFO_CREATE, Void, (Ptr{Cint}, Ptr{Cint}), newinfo, &0 )
102+
info=new(newinfo[])
103+
finalizer(info, info -> ( ccall(MPI_INFO_FREE, Void,
104+
(Ptr{Cint}, Ptr{Cint}), &info.val, &0);
105+
info.val = MPI_INFO_NULL ) )
106+
info
107+
end
108+
end
109+
const INFO_NULL = MPI_INFO_NULL
110+
111+
# the info functions assume that Fortran hidden arguments are placed at the end of the argument list
112+
function Info_set(info::Info,key::AbstractString,value::AbstractString)
113+
@assert isascii(key) && isascii(value)
114+
ccall(MPI_INFO_SET, Void,
115+
(Ptr{Cint}, Ptr{UInt8}, Ptr{UInt8}, Ptr{Cint}, Csize_t, Csize_t),
116+
&info.val, key, value, &0, sizeof(key), sizeof(value))
117+
end
118+
119+
function Info_get(info::Info,key::AbstractString)
120+
@assert isascii(key)
121+
keyexists=Ref{Bool}()
122+
len=Ref{Cint}()
123+
ccall(MPI_INFO_GET_VALUELEN, Void,
124+
(Ptr{Cint}, Ptr{UInt8}, Ptr{Cint}, Ptr{Bool}, Ptr{Cint}, Csize_t),
125+
&info.val, key, len, keyexists, &0, sizeof(key))
126+
if keyexists[]
127+
value=" "^(len[])
128+
ccall(MPI_INFO_GET, Void,
129+
(Ptr{Cint}, Ptr{UInt8}, Ptr{Cint}, Ptr{UInt8}, Ptr{Bool}, Ptr{Cint}, Csize_t, Csize_t),
130+
&info.val, key, len, value, keyexists, &0, sizeof(key), sizeof(value) )
131+
else
132+
value=""
133+
end
134+
value
135+
end
136+
137+
function Info_delete(info::Info,key::AbstractString)
138+
@assert isascii(key)
139+
ccall(MPI_INFO_DELETE, Void,
140+
(Ptr{Cint}, Ptr{UInt8}, Ptr{Cint}, Csize_t), &info.val, key ,&0, sizeof(key) )
141+
end
142+
Info_free(info::Info) = finalize(info)
143+
96144
mutable struct Status
97145
val::Array{Cint,1}
98146
Status() = new(Array{Cint}(MPI_STATUS_SIZE))
@@ -169,6 +217,30 @@ function Comm_size(comm::Comm)
169217
Int(size[])
170218
end
171219

220+
function Comm_split(comm::Comm,color::Integer,key::Integer)
221+
newcomm = Ref{Cint}()
222+
ccall(MPI_COMM_SPLIT, Void,
223+
(Ptr{Cint}, Ptr{Cint}, Ptr{Cint}, Ptr{Cint}, Ptr{Cint}),
224+
&comm.val, &color, &key, newcomm, &0)
225+
MPI.Comm(newcomm[])
226+
end
227+
228+
function Comm_split_type(comm::Comm,split_type::Integer,key::Integer;info::Info=INFO_NULL)
229+
newcomm = Ref{Cint}()
230+
ccall(MPI_COMM_SPLIT_TYPE, Void,
231+
(Ptr{Cint}, Ptr{Cint}, Ptr{Cint}, Ptr{Cint}, Ptr{Cint}, Ptr{Cint}),
232+
&comm.val, &split_type, &key, &info.val, newcomm, &0)
233+
MPI.Comm(newcomm[])
234+
end
235+
236+
function Wtick()
237+
ccall(MPI_WTICK, Cdouble, () )
238+
end
239+
240+
function Wtime()
241+
ccall(MPI_WTIME, Cdouble, () )
242+
end
243+
172244
function type_create(T::DataType)
173245
if !isbits(T)
174246
throw(ArgumentError("Type must be isbits()"))

src/mpi-op.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,11 @@ function user_op(opfunc::Function)
5151
return _user_op
5252
end
5353

54-
# use function types in Julia 0.5 to automatically use built-in
54+
# use function types in Julia 0.7 to automatically use built-in
5555
# MPI operations for the corresponding Julia functions.
5656
for (f,op) in ((+,SUM), (*,PROD),
5757
(min,MIN), (max,MAX),
58-
(&, BAND), (|, BOR), ($, BXOR))
58+
(&, BAND), (|, BOR), (, BXOR))
5959
@eval user_op(::$(typeof(f))) = $op
6060
end
6161

src/win_mpiconstants.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ const MPI_INTEGER8 = Int32(0x4c000831)
2222
const MPI_COMM_NULL = Int32(67108864)
2323
const MPI_COMM_SELF = Int32(1140850689)
2424
const MPI_COMM_WORLD = Int32(1140850688)
25+
const MPI_COMM_TYPE_SHARED = Int32(1)
2526
const MPI_OP_NULL = Int32(402653184)
2627
const MPI_BAND = Int32(1476395014)
2728
const MPI_BOR = Int32(1476395016)
@@ -37,6 +38,7 @@ const MPI_PROD = Int32(1476395012)
3738
const MPI_REPLACE = Int32(1476395021)
3839
const MPI_SUM = Int32(1476395011)
3940
const MPI_REQUEST_NULL = Int32(738197504)
41+
const MPI_INFO_NULL = Int32(469762048)
4042
const MPI_STATUS_SIZE = Int32(5)
4143
const MPI_ERROR = Int32(5)
4244
const MPI_SOURCE = Int32(3)
@@ -51,6 +53,8 @@ const MPI_ABORT = (:MPI_ABORT, "msmpi.dll")
5153
const MPI_INIT = (:MPI_INIT, "msmpi.dll")
5254
const MPI_COMM_RANK = (:MPI_COMM_RANK, "msmpi.dll")
5355
const MPI_COMM_SIZE = (:MPI_COMM_SIZE, "msmpi.dll")
56+
const MPI_COMM_SPLIT = (:MPI_COMM_SPLIT, "msmpi.dll")
57+
const MPI_COMM_SPLIT_TYPE = (:MPI_COMM_SPLIT_TYPE, "msmpi.dll")
5458
const MPI_BARRIER = (:MPI_BARRIER, "msmpi.dll")
5559
const MPI_FINALIZE = (:MPI_FINALIZE, "msmpi.dll")
5660
const MPI_BCAST = (:MPI_BCAST, "msmpi.dll")

test/runtests.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ using Base.Test
33

44
using Compat
55
import Compat.String
6+
import Compat.Sys: BINDIR
67

78
# Code coverage command line options; must correspond to src/julia.h
89
# and src/ui/repl.c
@@ -21,7 +22,7 @@ singlefiles = []
2122

2223
function runtests()
2324
nprocs = clamp(Sys.CPU_CORES, 2, 4)
24-
exename = joinpath(JULIA_HOME, Base.julia_exename())
25+
exename = joinpath(BINDIR, Base.julia_exename())
2526
testdir = dirname(@__FILE__)
2627
istest(f) = endswith(f, ".jl") && startswith(f, "test_")
2728
testfiles = sort(filter(istest, readdir(testdir)))

test/test_info.jl

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using Base.Test
2+
using MPI
3+
4+
MPI.Init()
5+
6+
info = MPI.Info()
7+
@test typeof(info) == MPI.Info
8+
@test info.val != MPI.Info
9+
MPI.Info_set(info, "foo", "fast")
10+
MPI.Info_set(info, "bar", "evenfaster")
11+
@test MPI.Info_get(info, "foo" ) == "fast"
12+
MPI.Info_delete(info, "bar")
13+
@test MPI.Info_get(info, "bar" ) == ""
14+
finalize(info)
15+
@test info.val == MPI.INFO_NULL
16+
17+
MPI.Finalize()

0 commit comments

Comments
 (0)