pbdMPI (version 0.3-9)

allreduce-method: All Ranks Receive a Reduction of Objects from Every Rank

Description

This method lets all ranks receive a deduction of objects from every rank in the same communicator based on a given operation. The default return is an object like the input.

Usage

allreduce(x, x.buffer = NULL, op = .pbd_env$SPMD.CT$op,
          comm = .pbd_env$SPMD.CT$comm)

Arguments

x

an object to be gathered from all ranks.

x.buffer

a buffer to hold the return object which probably has x with the same type of x.

op

a reduction operation applied to combine all x.

comm

a communicator number.

Value

The reduced object of the same type as x is returned by default.

Methods

For calling spmd.allreduce.*:

signature(x = "ANY", x.buffer = "missing")

signature(x = "integer", x.buffer = "integer")

signature(x = "numeric", x.buffer = "numeric")

signature(x = "logical", x.buffer = "logical")

signature(x = "float32", x.buffer = "float32")

Details

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 one of integer, double, or raw specified correctly according to the type of x.

References

Programming with Big Data in R Website: http://r-pbd.org/

See Also

allgather(), gather(), reduce().

Examples

Run this code
# NOT RUN {
<!-- %\dontrun{ -->
# }
# NOT RUN {
### Save code in a file "demo.r" and run with 2 processors by
### SHELL> mpiexec -np 2 Rscript demo.r

spmd.code <- "
### Initial.
suppressMessages(library(pbdMPI, quietly = TRUE))
init()
.comm.size <- comm.size()
.comm.rank <- comm.rank()

### Examples.
N <- 5
x <- (1:N) + N * .comm.rank
y <- allreduce(matrix(x, nrow = 1), op = \"sum\")
comm.print(y)

y <- allreduce(x, double(N), op = \"prod\")
comm.print(y)

comm.set.seed(1234, diff = TRUE)
x <- as.logical(round(runif(N)))
y <- allreduce(x, logical(N), op = \"land\")
comm.print(y)

### Finish.
finalize()
"
pbdMPI::execmpi(spmd.code = spmd.code, nranks = 2L)
# }
# NOT RUN {
<!-- %} -->
# }

Run the code above in your browser using DataLab