-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #56 from PetrKryslUCSD/develop
Develop
- Loading branch information
Showing
6 changed files
with
122 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# examples/03-reduce.jl | ||
# This example shows how to use custom datatypes and reduction operators | ||
# It computes the variance in parallel in a numerically stable way | ||
|
||
using MPI, Statistics | ||
|
||
MPI.Init() | ||
const comm = MPI.COMM_WORLD | ||
const root = 0 | ||
|
||
rank = MPI.Comm_rank(comm) | ||
|
||
X = fill(rank, 7) | ||
|
||
# Perform a sum reduction | ||
X = MPI.Allreduce(X, MPI.SUM, comm) | ||
|
||
if MPI.Comm_rank(comm) == root | ||
println("The sum of the arrays is: ", X) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
# examples/03-reduce.jl | ||
# This example shows how to use custom datatypes and reduction operators | ||
# It computes the variance in parallel in a numerically stable way | ||
|
||
using MPI, Statistics | ||
|
||
RBuffer = MPI.RBuffer | ||
Op = MPI.Op | ||
API = MPI.API | ||
MPI_Op = MPI.MPI_Op | ||
IN_PLACE = MPI.IN_PLACE | ||
Comm = MPI.Comm | ||
AbstractRequest = MPI.AbstractRequest | ||
Request = MPI.Request | ||
_doc_external = x -> "For more information, see the [MPI documentation]($x)." | ||
|
||
## Iallreduce | ||
|
||
# mutating | ||
""" | ||
Iallreduce!(sendbuf, recvbuf, op, comm::Comm, req::AbstractRequest=Request()) | ||
Iallreduce!(sendrecvbuf, op, comm::Comm, req::AbstractRequest=Request()) | ||
Performs elementwise reduction using the operator `op` on the buffer `sendbuf`, storing | ||
the result in the `recvbuf` of all processes in the group. | ||
If only one `sendrecvbuf` buffer is provided, then the operation is performed in-place. | ||
# See also | ||
- [`Iallreduce`](@ref), to handle allocation of the output buffer. | ||
- [`Op`](@ref) for details on reduction operators. | ||
# External links | ||
$(_doc_external("MPI_Iallreduce")) | ||
""" | ||
function Iallreduce!(rbuf::RBuffer, op::Union{Op,MPI_Op}, comm::Comm, req::AbstractRequest=Request()) | ||
# int MPI_Iallreduce(const void *sendbuf, void *recvbuf, int count, | ||
# MPI_Datatype datatype, MPI_Op op, MPI_Comm comm, | ||
# MPI_Request *request) | ||
API.MPI_Iallreduce(rbuf.senddata, rbuf.recvdata, rbuf.count, rbuf.datatype, op, comm, req) | ||
return req | ||
end | ||
Iallreduce!(rbuf::RBuffer, op, comm::Comm, req::AbstractRequest=Request()) = | ||
Iallreduce!(rbuf, Op(op, eltype(rbuf)), comm, req) | ||
Iallreduce!(sendbuf, recvbuf, op, comm::Comm, req::AbstractRequest=Request()) = | ||
Iallreduce!(RBuffer(sendbuf, recvbuf), op, comm, req) | ||
|
||
# inplace | ||
Iallreduce!(buf, op, comm::Comm, req::AbstractRequest=Request()) = Iallreduce!(IN_PLACE, buf, op, comm, req) | ||
|
||
|
||
MPI.Init() | ||
const comm = MPI.COMM_WORLD | ||
const root = 0 | ||
|
||
rank = MPI.Comm_rank(comm) | ||
|
||
X = fill(rank, 7) | ||
|
||
# Perform a sum reduction | ||
req = Iallreduce!(X, MPI.SUM, comm) | ||
sleep(rand()) | ||
MPI.Wait(req) | ||
|
||
if MPI.Comm_rank(comm) == root | ||
println("Rank $(MPI.Comm_rank(comm)): The array is: ", X) | ||
println("Rank $(MPI.Comm_rank(comm)): Should have gotten: ", sum(0:MPI.Comm_size(comm)-1)) | ||
end | ||
|
||
MPI.Finalize() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
222cc95
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JuliaRegistrator register
222cc95
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Registration pull request created: JuliaRegistries/General/119634
Tip: Release Notes
Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.
To add them here just re-invoke and the PR will be updated.
Tagging
After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.
This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via: