@@ -10,7 +10,7 @@ typealias MPIDatatype Union{Char,
10
10
# accessor function for getting MPI datatypes
11
11
# use a function in case more behavior is needed later
12
12
function mpitype {T} (:: Type{T} )
13
- return mpitype_dict[T]
13
+ return mpitype_dict[T]
14
14
end
15
15
16
16
type Comm
@@ -119,58 +119,55 @@ function Comm_size(comm::Comm)
119
119
end
120
120
121
121
function type_create (T:: DataType )
122
+ if ! isbits (T)
123
+ throw (ArgumentError (" Type must be isbits()" ))
124
+ end
122
125
123
- if ! isbits (T)
124
- throw (ArgumentError (" Type must be isbits()" ))
125
- end
126
-
127
- if haskey (mpitype_dict, T) # if the datatype already exists
128
- return nothing
129
- end
130
-
131
- # get the data from the type
132
- fieldtypes = T. types
133
- offsets = fieldoffsets (T)
134
- nfields = Cint (length (fieldtypes))
135
-
136
- # put data in MPI format
137
- blocklengths = ones (Cint, nfields)
138
- displacements = zeros (Cptrdiff_t, nfields) # size_t == MPI_Aint ?
139
- types = zeros (Cint, nfields)
140
- for i= 1 : nfields
141
- displacements[i] = offsets[i]
142
-
143
- # create an MPI_Datatype for the current field if it does not exist yet
144
- if ! haskey (mpitype_dict, fieldtypes[i])
145
- type_create (fieldtypes[i])
126
+ if haskey (mpitype_dict, T) # if the datatype already exists
127
+ return nothing
146
128
end
147
129
148
- types[i] = mpitype (fieldtypes[i])
149
- end
130
+ # get the data from the type
131
+ fieldtypes = T. types
132
+ offsets = fieldoffsets (T)
133
+ nfields = Cint (length (fieldtypes))
134
+
135
+ # put data in MPI format
136
+ blocklengths = ones (Cint, nfields)
137
+ displacements = zeros (Cptrdiff_t, nfields) # size_t == MPI_Aint ?
138
+ types = zeros (Cint, nfields)
139
+ for i= 1 : nfields
140
+ displacements[i] = offsets[i]
141
+ # create an MPI_Datatype for the current field if it does not exist yet
142
+ if ! haskey (mpitype_dict, fieldtypes[i])
143
+ type_create (fieldtypes[i])
144
+ end
145
+ types[i] = mpitype (fieldtypes[i])
146
+ end
150
147
151
- # create the datatype
152
- newtype_ref = Ref {Cint} ()
153
- flag = Ref {Cint} ()
154
- ccall (MPI_TYPE_CREATE_STRUCT, Void, (Ptr{Cint}, Ptr{Cint}, Ptr{Cptrdiff_t},
155
- Ptr{Cint}, Ptr{Cint}, Ptr{Cint}), & nfields, blocklengths, displacements, types ,
156
- newtype_ref, flag)
148
+ # create the datatype
149
+ newtype_ref = Ref {Cint} ()
150
+ flag = Ref {Cint} ()
151
+ ccall (MPI_TYPE_CREATE_STRUCT, Void, (Ptr{Cint}, Ptr{Cint}, Ptr{Cptrdiff_t},
152
+ Ptr{Cint}, Ptr{Cint}, Ptr{Cint}), & nfields, blocklengths, displacements,
153
+ types, newtype_ref, flag)
157
154
158
- if flag[] != 0
159
- throw (ErrorException (" MPI_Type_create_struct returned non-zero exit status" ))
160
- end
155
+ if flag[] != 0
156
+ throw (ErrorException (" MPI_Type_create_struct returned non-zero exit status" ))
157
+ end
161
158
162
- # commit the datatatype
163
- flag2 = Ref {Cint} ()
164
- ccall (MPI_TYPE_COMMIT, Void, (Ptr{Cint}, Ptr{Cint}), newtype_ref, flag2)
159
+ # commit the datatatype
160
+ flag2 = Ref {Cint} ()
161
+ ccall (MPI_TYPE_COMMIT, Void, (Ptr{Cint}, Ptr{Cint}), newtype_ref, flag2)
165
162
166
- if flag2[] != 0
167
- throw (ErrorException (" MPI_Type_commit returned non-zero exit status" ))
168
- end
163
+ if flag2[] != 0
164
+ throw (ErrorException (" MPI_Type_commit returned non-zero exit status" ))
165
+ end
169
166
170
- # add it to the dictonary of known types
171
- mpitype_dict[T] = newtype_ref[]
167
+ # add it to the dictonary of known types
168
+ mpitype_dict[T] = newtype_ref[]
172
169
173
- return nothing
170
+ return nothing
174
171
end
175
172
176
173
0 commit comments