Parallel primitives
Gather
PartitionedArrays.gather
— Functiongather(snd;destination=MAIN)
Return an array whose first entry contains a copy of the elements of array snd
collected in a vector. Another component different from the first one can be used to store the result by setting the optional key-word argument destination
. Setting destination=:all
, will store the result in all entries of rcv
resulting in a "gather all" operation.
Examples
julia> using PartitionedArrays
julia> snd = collect(1:3)
3-element Vector{Int64}:
1
2
3
julia> gather(snd,destination=3)
3-element Vector{Vector{Int64}}:
[]
[]
[1, 2, 3]
julia> gather(snd,destination=:all)
3-element Vector{Vector{Int64}}:
[1, 2, 3]
[1, 2, 3]
[1, 2, 3]
PartitionedArrays.gather!
— Functiongather!(rcv,snd;destination=MAIN)
In-place version of gather
. It returns rcv
. The result array rcv
can be allocated with the helper function allocate_gather
.
PartitionedArrays.allocate_gather
— Functionallocate_gather(snd;destination=MAIN)
Allocate an array to be used in the first argument of gather!
.
Scatter
PartitionedArrays.scatter
— Functionscatter(snd;source=MAIN)
Copy the items in the collection snd[source]
into an array of the same size and container type as snd
. This function requires length(snd[source]) == length(snd)
.
Examples
julia> using PartitionedArrays
julia> a = [Int[],[1,2,3],Int[]]
3-element Vector{Vector{Int64}}:
[]
[1, 2, 3]
[]
julia> scatter(a,source=2)
3-element Vector{Int64}:
1
2
3
PartitionedArrays.scatter!
— Functionscatter!(rcv,snd;source=1)
In-place version of scatter
. The destination array rcv
can be generated with the helper function allocate_scatter
. It returns rcv
.
PartitionedArrays.allocate_scatter
— Functionallocate_scatter(snd;source=1)
Allocate an array to be used in the first argument of scatter!
.
Multicast
PartitionedArrays.multicast
— Functionmulticast(snd;source=MAIN)
Copy snd[source]
into a new array of the same size and type as snd
.
Examples
julia> using PartitionedArrays
julia> a = [0,0,2,0]
4-element Vector{Int64}:
0
0
2
0
julia> multicast(a,source=3)
4-element Vector{Int64}:
2
2
2
2
PartitionedArrays.multicast!
— Functionmulticast!(rcv,snd;source=1)
In-place version of multicast
. The destination array rcv
can be generated with the helper function allocate_multicast
. It returns rcv
.
PartitionedArrays.allocate_multicast
— Functionallocate_multicast(snd;source=1)
Allocate an array to be used in the first argument of multicast!
.
Scan
PartitionedArrays.scan
— Functionscan(op,a;init,type)
Return the scan of the values in a
for the operation op
. Use type=:inclusive
or type=:exclusive
to use an inclusive or exclusive scan. init
will be added to all items in the result. Additionally, for exclusive scans, the first item in the result will be set to init
.
Examples
julia> using PartitionedArrays
julia> a = [2,4,1,3]
4-element Vector{Int64}:
2
4
1
3
julia> scan(+,a,type=:inclusive,init=0)
4-element Vector{Int64}:
2
6
7
10
julia> scan(+,a,type=:exclusive,init=1)
4-element Vector{Int64}:
1
3
7
8
Reduction
PartitionedArrays.reduction
— Functionreduction(op, a; destination=MAIN [,init])
Reduce the values in array a
according with operation op
and the initial value init
and store the result in a new array of the same size as a
at index destination
.
Examples
julia> using PartitionedArrays
julia> a = [1,3,2,4]
4-element Vector{Int64}:
1
3
2
4
julia> reduction(+,a;init=0,destination=2)
4-element Vector{Int64}:
0
10
0
0
Exchange
PartitionedArrays.ExchangeGraph
— Typestruct ExchangeGraph{A}
Type representing a directed graph to be used in exchanges, see function exchange
and exchange!
.
Properties
snd::A
rcv::A
snd[i]
contains a list of the outgoing neighbors of node i
. rcv[i]
contains a list of the incomming neighbors of node i
. A
is a vector-like container type.
Supertype hierarchy
ExchangeGraph <: Any
PartitionedArrays.ExchangeGraph
— MethodExchangeGraph(snd,rcv)
Create an instance of ExchangeGraph
from the underlying fields.
PartitionedArrays.ExchangeGraph
— MethodExchangeGraph(snd; symmetric=false [rcv, neighbors,find_rcv_ids])
Create an ExchangeGraph
object only from the lists of outgoing neighbors in snd
. In case the list of incoming neighbors is known, it can be passed as key-word argument by setting rcv
and the rest of key-word arguments are ignored. If symmetric==true
, then the incoming neighbors are set to snd
. Otherwise, either the optional neighbors
or find_rcv_ids
are considered, in that order. neighbors
is also an ExchangeGraph
that contains a super set of the outgoing and incoming neighbors associated with snd
. It is used to find the incoming neighbors rcv
efficiently. If neighbors
are not provided, then find_rcv_ids
is used (either the user-provided or a default one). find_rcv_ids
is a function that implements an algorithm to find the rcv side of the exchange graph out of the snd side information.
PartitionedArrays.exchange
— Functionexchange(snd,graph::ExchangeGraph) -> Task
Send the data in snd
according the directed graph graph
. This function returns immediately and returns a task that produces the result, allowing for latency hiding. Use fetch
to wait and get the result. The object snd
and rcv=fetch(exchange(snd,graph))
are array of vectors. The value snd[i][j]
is sent to node graph.snd[i][j]
. The value rcv[i][j]
is the one received from node graph.rcv[i][j]
.
Examples
julia> using PartitionedArrays
julia> snd_ids = [[3,4],[1,3],[1,4],[2]]
4-element Vector{Vector{Int64}}:
[3, 4]
[1, 3]
[1, 4]
[2]
julia> graph = ExchangeGraph(snd_ids)
ExchangeGraph{Vector{Vector{Int64}}} with 4 nodes
julia> snd = [[10,10],[20,20],[30,30],[40]]
4-element Vector{Vector{Int64}}:
[10, 10]
[20, 20]
[30, 30]
[40]
julia> t = exchange(snd,graph);
julia> rcv = fetch(t)
4-element Vector{Vector{Int64}}:
[20, 30]
[40]
[10, 20]
[10, 30]
PartitionedArrays.exchange!
— Functionexchange!(rcv,snd,graph::ExchangeGraph) -> Task
In-place and fakeasynchronous version of exchange
. This function returns immediately and returns a task that produces rcv
with the updated values. Use fetch
to get the updated version of rcv
. The input rcv
can be allocated with [`allocateexchange`](@ref).
PartitionedArrays.allocate_exchange
— Functionallocate_exchange(snd,graph::ExchangeGraph)
Allocate the result to be used in the first argument of exchange!
.