@@ -26,41 +26,67 @@ If `init=false` is used in the costructor (the default), a "null" `Info` object
26
26
returned: no keys can be added to such an object.
27
27
"""
28
28
mutable struct Info <: AbstractDict{Symbol,String}
29
- val:: Cint
29
+ cinfo:: CInfo
30
+
31
+ function Info (cinfo:: CInfo )
32
+ new (cinfo)
33
+ end
30
34
function Info (;init= false )
31
- info = new (MPI_INFO_NULL )
35
+ info = Info (INFO_NULL . cinfo )
32
36
if init
33
- ccall (MPI_INFO_CREATE, Nothing, (Ptr{ Cint}, Ref{Cint} ), info, 0 )
37
+ @mpichk ccall (( :MPI_Info_create , libmpi), Cint, (Ptr{CInfo}, ), info)
34
38
refcount_inc ()
35
39
finalizer (free, info)
36
40
end
37
41
return info
38
42
end
39
43
end
40
44
41
- # allows us to pass Info objects directly into Ptr{Cint} ccall signatures
42
- function Base. unsafe_convert (:: Type{Ptr{Cint}} , info:: Info )
43
- convert (Ptr{Cint}, pointer_from_objref (info))
45
+ # allows us to pass Info objects directly into CInfo ccall signatures
46
+ function Base. cconvert (:: Type{CInfo} , info:: Info )
47
+ info. cinfo
48
+ end
49
+ # allows us to pass Info objects directly into Ptr{CInfo} ccall signatures
50
+ function Base. unsafe_convert (:: Type{Ptr{CInfo}} , info:: Info )
51
+ convert (Ptr{CInfo}, pointer_from_objref (info))
44
52
end
45
53
54
+ if HAVE_MPI_COMM_C2F
55
+ # Assume info is treated the same way
56
+ function CInfo (finfo:: Cint )
57
+ ccall ((:MPI_Info_f2c , libmpi), CInfo, (Cint,), finfo)
58
+ end
59
+
60
+ # only used for use with Fortran API
61
+ # can be removed once we have switched to C API
62
+ function Base. cconvert (:: Type{Ptr{Cint}} , info:: Info )
63
+ Ref (ccall ((:MPI_Info_c2f , libmpi), Cint, (CInfo,), info. cinfo))
64
+ end
65
+ else
66
+ function CInfo (finfo:: Cint )
67
+ reinterpret (CInfo, finfo)
68
+ end
69
+ function Base. cconvert (:: Type{Ptr{Cint}} , info:: Info )
70
+ Ref (reinterpret (Cint, info. cinfo))
71
+ end
72
+ end
73
+
74
+ const INFO_NULL = Info (Ref {CInfo} ()[]) # get an arbitrary bit-pattern: this will be set correctly at Init time
75
+
46
76
function free (info:: Info )
47
- if info. val != MPI_INFO_NULL
48
- ccall (MPI_INFO_FREE, Nothing, (Ptr{ Cint}, Ref{Cint} ), info, 0 )
77
+ if info. cinfo != INFO_NULL . cinfo
78
+ @mpichk ccall (( :MPI_Info_free , libmpi), Cint, (Ptr{CInfo}, ), info)
49
79
refcount_dec ()
50
80
end
51
81
return nothing
52
82
end
53
83
54
- const INFO_NULL = Info (init= false )
55
-
56
- # the info functions assume that Fortran hidden arguments are placed at the end of the argument list
57
84
function Base. setindex! (info:: Info , value:: AbstractString , key:: Symbol )
58
85
skey = String (key)
59
86
@assert isascii (skey) && isascii (value) &&
60
87
length (skey) <= MPI_MAX_INFO_KEY && length (value) <= MPI_MAX_INFO_VAL
61
- ccall (MPI_INFO_SET, Nothing,
62
- (Ptr{Cint}, Ptr{UInt8}, Ptr{UInt8}, Ref{Cint}, Csize_t, Csize_t),
63
- info, skey, value, 0 , sizeof (skey), sizeof (value))
88
+ @mpichk ccall ((:MPI_Info_set , libmpi), Cint,
89
+ (CInfo, Cstring, Cstring), info, skey, value)
64
90
end
65
91
66
92
Base. setindex! (info:: Info , value:: Any , key:: Symbol ) = info[key] = infoval (value)
90
116
function Base. getindex (info:: Info , key:: Symbol )
91
117
skey = String (key)
92
118
@assert isascii (skey) && length (skey) <= MPI_MAX_INFO_KEY
93
- keyexists = Ref {Cint} ()
94
- len = Ref {Cint} ()
95
- ccall (MPI_INFO_GET_VALUELEN, Nothing ,
96
- (Ptr{Cint}, Ptr{UInt8} , Ptr{Cint}, Ptr{Cint}, Ref{Cint}, Csize_t ),
97
- info, skey, len, keyexists, 0 , sizeof (skey) )
119
+ valuelen = Ref {Cint} ()
120
+ flag = Ref {Cint} ()
121
+ @mpichk ccall (( :MPI_Info_get_valuelen , libmpi), Cint ,
122
+ (CInfo, Cstring , Ptr{Cint}, Ptr{Cint}),
123
+ info, skey, valuelen, flag )
98
124
99
- if keyexists [] == 0
125
+ if flag [] == 0
100
126
throw (KeyError (key))
101
127
end
102
128
103
- buffer = Vector {UInt8} (undef, len[])
104
- ccall (MPI_INFO_GET, Nothing,
105
- (Ptr{Cint}, Ptr{UInt8}, Ptr{Cint}, Ptr{UInt8}, Ptr{Cint}, Ref{Cint}, Csize_t, Csize_t),
106
- info, skey, len, buffer, keyexists, 0 , sizeof (skey), sizeof (buffer))
129
+ n = valuelen[]
130
+ buffer = Vector {UInt8} (undef, n)
131
+ @mpichk ccall ((:MPI_Info_get , libmpi), Cint,
132
+ (CInfo, Cstring, Cint, Ptr{UInt8}, Ptr{Cint}),
133
+ info, skey, n, buffer, flag)
107
134
return String (buffer)
108
135
end
109
136
110
137
function Base. delete! (info:: Info ,key:: Symbol )
111
138
skey = String (key)
112
139
@assert isascii (skey) && length (skey) <= MPI_MAX_INFO_KEY
113
- ccall (MPI_INFO_DELETE, Nothing,
114
- (Ptr{Cint}, Ptr{UInt8}, Ref{Cint}, Csize_t),
115
- info, skey, 0 , sizeof (skey))
140
+ @mpichk ccall ((:MPI_Info_delete , libmpi), Cint,
141
+ (CInfo, Cstring), info, skey)
116
142
end
117
143
118
144
function Base. length (info:: Info )
119
- if info. val == MPI_INFO_NULL
145
+ if info. cinfo == INFO_NULL . cinfo
120
146
return 0
121
147
end
122
148
nkeys = Ref {Cint} ()
123
- ccall (MPI_INFO_GET_NKEYS, Nothing,
124
- (Ptr{Cint}, Ptr{Cint}, Ref{Cint}),
125
- info, nkeys, 0 )
149
+ @mpichk ccall ((:MPI_Info_get_nkeys , libmpi), Cint,
150
+ (CInfo, Ptr{Cint}), info, nkeys)
126
151
return Int (nkeys[])
127
152
end
128
153
129
154
function nthkey (info:: Info , n:: Integer )
130
155
buffer = Vector {UInt8} (undef, MPI_MAX_INFO_KEY)
131
- ccall (MPI_INFO_GET_NTHKEY, Nothing,
132
- (Ptr{Cint}, Ref{Cint}, Ptr{UInt8}, Ref{Cint}, Csize_t),
133
- info, n, buffer, 0 , length (buffer))
134
- i = findlast (! isequal (UInt8 (' ' )), buffer)
135
- resize! (buffer, i)
156
+ @mpichk ccall ((:MPI_Info_get_nthkey , libmpi), Cint,
157
+ (CInfo, Cint, Ptr{UInt8}), info, n, buffer)
158
+ i = findfirst (isequal (UInt8 (0 )), buffer)
159
+ if i != = nothing
160
+ resize! (buffer, i- 1 )
161
+ end
136
162
Symbol (buffer)
137
163
end
138
164
0 commit comments