Skip to content

Commit fd7dcc1

Browse files
committed
first attempt at creating a new datatype
1 parent 98c2db3 commit fd7dcc1

File tree

3 files changed

+47
-1
lines changed

3 files changed

+47
-1
lines changed

deps/gen_functions.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ int main(int argc, char *argv[]) {
6464
printf(" :MPI_WAITANY => \"%s\",\n", STRING(MPI_WAITANY));
6565
printf(" :MPI_WAITSOME => \"%s\",\n", STRING(MPI_WAITSOME));
6666
printf(" :MPI_WTIME => \"%s\",\n", STRING(MPI_WTIME));
67+
printf(" :MPI_TYPE_CREATE_STRUCT => \"%s\",\n",
68+
STRING(MPI_TYPE_CREATE_STRUCT));
69+
printf(" :MPI_TYPE_COMMIT => \"%s\",\n",
70+
STRING(MPI_TYPE_COMMIT));
6771
printf(")\n");
6872
printf("\n");
6973
printf("bitstype %d CComm\n", (int)(sizeof(MPI_Comm) * 8));

src/MPI.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
__precompile__()
1+
#__precompile__()
22

33
module MPI
44

src/mpi-base.jl

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,48 @@ function Comm_size(comm::Comm)
120120
Int(size[])
121121
end
122122

123+
function Type_create_struct{T <: DataType}(::Type{T})
124+
125+
@assert isbits(T)
126+
fieldtypes = T.types
127+
offsets = fieldoffsets(T)
128+
nfields = Cint(length(fieldtypes))
129+
130+
blocklengths = ones(Cint, nfields)
131+
displacements = zeros(Cint, nfields)
132+
types = zeros(Cint, nfields)
133+
for i=1:nfields
134+
displacements[i] = offsets[i]
135+
types[i] = mpitype(fieldtypes[i])
136+
end
137+
138+
newtype_ref = Ref{Cint}()
139+
flag = Ref{Cint}()
140+
ccall(MPI_TYPE_CREATE_STRUCT, Void, (Ptr{Cint}, Ptr{Cint}, Ptr{Cint},
141+
Ptr{Cint}, Ptr{Cint}), &nfields, blocklengths, displacements, types,
142+
newtype_ref, flag)
143+
144+
if flag[] != 0
145+
println(STDERR, "Warning: MPI_TYPE_CREATE_STRUCT returned non-zero exit stats")
146+
end
147+
148+
flag2 = Ref{Cint}()
149+
150+
ccall(MPI_TYPE_COMMIT, Void, (Ptr{Cint}, Ptr{Cint}), newtype_ref, flag2)
151+
152+
if flag2[] != 0
153+
println(STDERR, "Warning: MPI_TYPE_COMMIT returned non-zero exit status")
154+
end
155+
156+
mpitype_dict[T] = newtype_ref[]
157+
158+
return nothing
159+
end
160+
161+
162+
163+
164+
123165
# Point-to-point communication
124166

125167
function Probe(src::Integer, tag::Integer, comm::Comm)

0 commit comments

Comments
 (0)