Skip to content

Commit

Permalink
support create_hvector
Browse files Browse the repository at this point in the history
  • Loading branch information
t-bltg committed Sep 21, 2022
1 parent 4cd7118 commit 3aa6ba1
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/src/reference/advanced.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ MPI.to_type
MPI.Types.extent
MPI.Types.create_contiguous
MPI.Types.create_vector
MPI.Types.create_hvector
MPI.Types.create_subarray
MPI.Types.create_struct
MPI.Types.create_resized
Expand Down
31 changes: 31 additions & 0 deletions src/datatypes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,37 @@ function create_vector!(newtype::Datatype, count::Integer, blocklength::Integer,
return newtype
end

"""
MPI.Types.create_hvector(count::Integer, blocklength::Integer, stride::Integer, oldtype::MPI.Datatype)
Create a derived [`Datatype`](@ref) that replicates `oldtype` into locations that
consist of equally spaced (bytes) blocks.
Note that [`MPI.Types.commit!`](@ref) must be used before the datatype can be used for
communication.
# Example
```julia
datatype = MPI.Types.create_hvector(3, 2, 5, MPI.Datatype(Int64))
MPI.Types.commit!(datatype)
```
# External links
$(_doc_external("MPI_Type_hvector"))
"""
function create_hvector(count::Integer, blocklength::Integer, stride::Integer, oldtype::Datatype)
finalizer(free, create_hvector!(Datatype(), count, blocklength, stride, oldtype))
end
function create_hvector!(newtype::Datatype, count::Integer, blocklength::Integer, stride::Integer, oldtype::Datatype)
# int MPI_Type_hvector(int count, int blocklength, MPI_Aint stride,
# MPI_Datatype oldtype, MPI_Datatype *newtype)
@mpichk ccall((:MPI_Type_hvector, libmpi), Cint,
(Cint, Cint, Cint, MPI_Datatype, Ptr{MPI_Datatype}),
count, blocklength, MPI_Aint(stride), oldtype, newtype)
return newtype
end

"""
MPI.Types.create_subarray(sizes, subsizes, offset, oldtype::Datatype;
rowmajor=false)
Expand Down
5 changes: 4 additions & 1 deletion test/test_datatype.jl
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,10 @@ end
RowType = MPI.Types.create_vector(8, 1, 8, MPI.DOUBLE)
@test typeof(RowType) == MPI.Datatype

# create_hvector
DType = MPI.Types.create_hvector(8, 1, 8, MPI.DOUBLE)
@test typeof(DType) == MPI.Datatype

# create_subarray
SubMatrixType = MPI.Types.create_subarray((8, 8), (4, 4), (0, 0), MPI.INT64_T)
@test typeof(SubMatrixType) == MPI.Datatype
Expand All @@ -176,7 +180,6 @@ end
@test typeof(ParticleMPI) == MPI.Datatype
end


MPI.Barrier(MPI.COMM_WORLD)
MPI.Finalize()
@test MPI.Finalized()

0 comments on commit 3aa6ba1

Please sign in to comment.