@@ -19,7 +19,7 @@ const DATATYPE_NULL = _Datatype(MPI_DATATYPE_NULL)
1919
2020const MPI_Datatype_default = MPI_Datatype == Cint ? MPI_DATATYPE_NULL : C_NULL
2121Datatype () = Datatype (MPI_Datatype_default)
22-
22+
2323
2424function free (dt:: Datatype )
2525 if dt. val != DATATYPE_NULL. val && ! Finalized ()
8080
8181# names
8282function get_name (datatype:: Datatype )
83+ MPI. Initialized () || return " "
8384 buffer = Array {UInt8} (undef, MPI_MAX_OBJECT_NAME)
8485 lenref = Ref {Cint} ()
8586 @mpichk ccall ((:MPI_Type_get_name , libmpi), Cint,
86- (MPI_Datatype, Ptr{UInt8}, Ptr{Cint}),
87+ (MPI_Datatype, Ptr{UInt8}, Ptr{Cint}),
8788 datatype, buffer, lenref)
88- String (resize! (buffer, lenref[]))
89+ return String (resize! (buffer, lenref[]))
8990end
9091
9192# datatype attribute to store Julia type
@@ -99,11 +100,13 @@ Return the Julia type corresponding to the MPI [`Datatype`](@ref) `datatype`, or
99100if it doesn't correspond directly.
100101"""
101102function to_type (datatype:: Datatype )
102- ptr = get_attr (datatype, JULIA_TYPE_PTR_ATTR[])
103- if isnothing (ptr)
104- return ptr
103+ if MPI. Initialized ()
104+ ptr = get_attr (datatype, JULIA_TYPE_PTR_ATTR[])
105+ if ! isnothing (ptr)
106+ return unsafe_pointer_to_objref (ptr)
107+ end
105108 end
106- return unsafe_pointer_to_objref (ptr)
109+ return nothing
107110end
108111
109112
159162
160163
161164function Base. show (io:: IO , datatype:: Datatype )
162- juliatype = to_type (datatype)
163165 show (io, Datatype)
164166 print (io, ' (' )
167+ juliatype = to_type (datatype)
165168 if isnothing (juliatype)
166169 show (io, datatype. val)
167170 else
@@ -174,7 +177,7 @@ function Base.show(io::IO, datatype::Datatype)
174177 print (io, name)
175178 end
176179end
177-
180+
178181
179182
180183module Types
231234 MPI.Types.create_vector(count::Integer, blocklength::Integer, stride::Integer, oldtype::MPI.Datatype)
232235
233236Create a derived [`Datatype`](@ref) that replicates `oldtype` into locations that
234- consist of equally spaced blocks.
237+ consist of equally spaced blocks.
235238
236239Note that [`MPI.Types.commit!`](@ref) must be used before the datatype can be used for
237240communication.
274277"""
275278 MPI.Types.create_subarray(sizes, subsizes, offset, oldtype::Datatype;
276279 rowmajor=false)
277-
280+
278281Creates a derived [`Datatype`](@ref) describing an `N`-dimensional subarray of size
279282`subsizes` of an `N`-dimensional array of size `sizes` and element type `oldtype`, with
280283the first element offset by `offset` (i.e. the 0-based index of the first element).
@@ -298,7 +301,7 @@ function create_subarray!(newtype::Datatype, sizes, subsizes, offset, oldtype::D
298301 sizes = sizes isa Vector{Cint} ? sizes : Cint[s for s in sizes]
299302 subsizes = subsizes isa Vector{Cint} ? subsizes : Cint[s for s in subsizes]
300303 offset = offset isa Vector{Cint} ? offset : Cint[s for s in offset]
301-
304+
302305 @mpichk ccall ((:MPI_Type_create_subarray , libmpi), Cint,
303306 (Cint, Ptr{Cint}, Ptr{Cint}, Ptr{Cint}, Cint, MPI_Datatype, Ptr{MPI_Datatype}),
304307 N, sizes, subsizes, offset,
0 commit comments