Skip to content

Commit d6a4eed

Browse files
committed
Reduction using a binary tree across connecting all workers. Reduction happens at all nodes that have children.
1 parent 9c58f6e commit d6a4eed

File tree

4 files changed

+854
-259
lines changed

4 files changed

+854
-259
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "ParallelUtilities"
22
uuid = "fad6cfc8-4f83-11e9-06cc-151124046ad0"
33
authors = ["Jishnu Bhattacharya <[email protected]>"]
4-
version = "0.3.1"
4+
version = "0.3.2"
55

66
[deps]
77
Distributed = "8ba89e20-285c-5b6f-9357-94700520ee1b"

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ julia> pmap(x->x^2,1:3)
8989
There is also a function `pmapbatch` that deals with batches of parameters that are passed to each processor, and `pmap_elementwise` calls this function under the hood to process the parameters one by one. We may use this directly as well if we need the entire batch for some reason (eg. reading values off a disk, which needs to be done once for the entire set and not for every parameter). As an example we demonstrate how to obtain the same result as above using `pmapbatch`:
9090

9191
```julia
92-
julia> p = pmapbatch(x->[f(i) for i in x],(xrange,yrange,zrange));
92+
julia> p = pmapbatch(x->[f(i...) for i in x],(xrange,yrange,zrange));
9393

9494
julia> Tuple(p)
9595
(6, 7, 8, 7, 8, 9, 8, 9, 10, 7, 8, 9, 8, 9, 10, 9, 10, 11, 8, 9, 10, 9, 10, 11, 10, 11, 12, 9, 10, 11, 10, 11, 12, 11, 12, 13)
@@ -112,7 +112,7 @@ julia> pmapsum_elementwise(x->x^2,1:1000)
112112
333833500
113113
```
114114

115-
We may choose an arbitrary reduction operator in the function `pmapreduce` and `pmapreduce_commutative`, and the elementwise function `pmapreduce_commutative_elementwise`. The reductions are performed locally on each node before the results are subsequently collected and reduced on the calling host.
115+
We may choose an arbitrary reduction operator in the function `pmapreduce` and `pmapreduce_commutative`, and the elementwise function `pmapreduce_commutative_elementwise`. The reductions are carried out as a binary tree across all workers.
116116

117117
```julia
118118
# Compute 1^2 * 2^2 * 3^2 in parallel
@@ -135,7 +135,7 @@ julia> pmapreduce(x->ones(2).*myid(),x->hcat(x...),1:nworkers())
135135
2.0 3.0
136136
```
137137

138-
The functions `pmapreduce` produces the same result as `pmapreduce_commutative` if the reduction operator is commutative (ie. the order of results received from the children workers does not matter). The function `pmapreduce_commutative` might be faster as it avoids an intermediate collection and sorting. This is what is used by the function `pmapsum` that chooses the reduction operator to be a sum.
138+
The functions `pmapreduce` produces the same result as `pmapreduce_commutative` if the reduction operator is commutative (ie. the order of results received from the children workers does not matter). The function `pmapreduce_commutative` might be faster as it does not sort the results received from the workers before reduction. This is what is used by the function `pmapsum` that chooses the reduction operator to be a sum.
139139

140140
```julia
141141
julia> sum(workers())

0 commit comments

Comments
 (0)