reduce(x, x.buffer = NULL, op = .SPMD.CT$op,
rank.dest = .SPMD.CT$rank.source, comm = .SPMD.CT$comm)
x
with the same type of x
.x
.x
reduce to.x
is returned by default..SPMD.CT$rank.source
,
i.e. rank 0L. All x
on all ranks are likely presumed to have the same size and type.
x.buffer
can be NULL
or unspecified. If specified, the type
should be either integer or double specified correctly according to the
type of x
.
allgather
, gather
, reduce
.# Save code in a file "demo.r" and run with 2 processors by
# > mpiexec -np 2 Rscript demo.r
### Initial
library(pbdMPI, quiet = TRUE)
init()
.comm.size <- comm.size()
.comm.rank <- comm.rank()
### Examples
N <- 5
x <- (1:N) + N * .comm.rank
y <- reduce(matrix(x, nrow = 1), op = "sum")
comm.print(y)
y <- reduce(x, double(N), op = "prod")
comm.print(y)
### Finish
finalize()
Run the code above in your browser using DataLab