Parallel primitives

Gather

PartitionedArrays.gatherFunction
gather(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]
source

Scatter

PartitionedArrays.scatterFunction
scatter(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
source

Multicast

PartitionedArrays.multicastFunction
multicast(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
source

Scan

PartitionedArrays.scanFunction
scan(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
source

Reduction

PartitionedArrays.reductionFunction
reduction(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
source

Exchange

PartitionedArrays.ExchangeGraphType
struct 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
source
PartitionedArrays.ExchangeGraphMethod
ExchangeGraph(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.

source
PartitionedArrays.exchangeFunction
exchange(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]
source
PartitionedArrays.exchange!Function
exchange!(rcv,snd,graph::ExchangeGraph) -> Task

In-place and asynchronous 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 allocate_exchange.

source