aa_gather-method: A Rank Gathers Objects from Every Rank

gather-methodsR Documentation

A Rank Gathers Objects from Every Rank


This method lets one rank gather objects from every rank in the same communicator. The default return is a list of length equal to comm size.


gather(x, x.buffer = NULL, x.count = NULL, displs = NULL,
       rank.dest = .pbd_env$SPMD.CT$rank.root,
       comm = .pbd_env$SPMD.CT$comm,
       unlist = .pbd_env$SPMD.CT$unlist)



an object to be gathered from all ranks.


a buffer to hold the return object which probably has 'size of x' times 'comm.size(comm)' with the same type of x.


a vector of length 'comm.size(comm)' containing all object lengths.


c(0L, cumsum(x.count)) by default.


a rank of destination where all x gather to.


a communicator number.


apply unlist function to the gathered list before return.


The arguments x.buffer, x.count, and displs can be left unspecified or NULL and are computed for you.

If x.buffer is specified, its type should be one of integer, double, or raw according to the type of x. Serialization and unserialization is avoided for atomic vectors if they are all the same size and x.buffer is specified, or if different sizes and both x.buffer and x.count are specified. A single vector instead of a list is returned in these cases.

Class array objects are gathered without serialization.

Complex objects can be gathered as serialization and unserialization is used on objects that are not of class "array" or atomic vectors.

The gather is efficient due to the underlying MPI parallel communication and recursive doubling gathering algorithm that results in a sublinear (log2(comm.size(comm))) number of communication steps. Also, serialization is applied only locally and in parallel.

See methods{"gather"} for S4 dispatch cases and the source code for further details.


Only rank.dest (by default rank 0) receives the gathered object. All other ranks receive NULL. See allgather() for a description of the gathered object.


Wei-Chen Chen wccsnow@gmail.com, George Ostrouchov, Drew Schmidt, Pragneshkumar Patel, and Hao Yu.


Programming with Big Data in R Website: https://pbdr.org/

See Also

allgather(), allreduce(), reduce().


### Save code in a file "demo.r" and run with 2 processors by
### SHELL> mpiexec -np 2 Rscript demo.r

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

### Examples.
N <- 5
x <- (1:N) + N * .comm.rank
y <- gather(matrix(x, nrow = 1))

y <- gather(x, double(N * .comm.size))

### Finish.
pbdMPI::execmpi(spmd.code, nranks = 2L)

pbdMPI documentation built on May 29, 2024, 11:38 a.m.