@@ -4,10 +4,8 @@ typealias MPIDatatype Union{Char,
44 Float32, Float64, Complex64, Complex128}
55
66# Define a function mpitype(T) that returns the MPI datatype code
7- # for a given type T. This works better with precompilation
8- # than a dictionary (since DataType keys need to be re-hashed at runtime),
9- # and also allows the datatype code to be inlined at compile-time.
10-
7+ # for a given type T. The dictonary is defined in __init__ so
8+ # the module can be precompiled
119
1210# accessor function for getting MPI datatypes
1311# use a function in case more behavior is needed later
@@ -120,10 +118,17 @@ function Comm_size(comm::Comm)
120118 Int (size[])
121119end
122120
123- function Type_create_struct {T <: Any} (:: Type{T} ) # <: Any effectively
121+ function type_create {T <: Any} (:: Type{T} ) # <: Any effectively
124122 # limits T to being a Type
125123
126- @assert isbits (T)
124+ if ! isbits (T)
125+ throw (ArgumentError (" Type must be isbits()" ))
126+ end
127+
128+ if haskey (mpitype_dict, T) # if the datatype already exists
129+ return nothing
130+ end
131+
127132 # get the data from the type
128133 fieldtypes = T. types
129134 offsets = fieldoffsets (T)
@@ -135,6 +140,12 @@ function Type_create_struct{T <: Any}(::Type{T}) # <: Any effectively
135140 types = zeros (Cint, nfields)
136141 for i= 1 : nfields
137142 displacements[i] = offsets[i]
143+
144+ # create an MPI_Datatype for the current field if it does not exist yet
145+ if ! haskey (mpitype_dict, fieldtypes[i])
146+ type_create (fieldtypes[i])
147+ end
148+
138149 types[i] = mpitype (fieldtypes[i])
139150 end
140151
@@ -146,16 +157,15 @@ function Type_create_struct{T <: Any}(::Type{T}) # <: Any effectively
146157 newtype_ref, flag)
147158
148159 if flag[] != 0
149- println (STDERR, " Warning: MPI_TYPE_CREATE_STRUCT returned non-zero exit stats " )
160+ throw ( ErrorException ( " MPI_Type_create_struct returned non-zero exit status " ) )
150161 end
151162
152163 # commit the datatatype
153164 flag2 = Ref {Cint} ()
154-
155165 ccall (MPI_TYPE_COMMIT, Void, (Ptr{Cint}, Ptr{Cint}), newtype_ref, flag2)
156166
157167 if flag2[] != 0
158- println (STDERR, " Warning: MPI_TYPE_COMMIT returned non-zero exit status" )
168+ throw ( ErrorException ( " MPI_Type_commit returned non-zero exit status" ) )
159169 end
160170
161171 # add it to the dictonary of known types
0 commit comments