Reductions
Reduction over PencilArray
s using Julia functions such as minimum
, maximum
, sum
, any
or all
are performed on the global data. This involves first a local reduction over each process, followed by a global reduction of a scalar quantity using MPI.Allreduce
.
For example:
using MPI
using PencilArrays
MPI.Init()
comm = MPI.COMM_WORLD
nprocs = MPI.Comm_size(comm)
rank = MPI.Comm_rank(comm)
id = rank + 1
pen = Pencil((16, 32, 14), comm)
u = PencilArray{Int}(undef, pen)
fill!(u, 2 * id)
minimum(u) # = 2
maximum(u) # = 2 * nprocs
minimum(abs2, u) # = 4
maximum(abs2, u) # = (2 * nprocs)^2
all(>(0), u) # true
all(==(2), u) # false if nprocs > 1
any(==(2), u) # true
Associative reduction operations like foldl
, foldr
, mapfoldl
and mapfoldr
are also defined for consistency, but these operations are not guaranteed to strictly respect left or right associativity. In fact, associativity is only respected on each local process, before results are reduced among all processes.