allgather-methods | R Documentation |
This method lets all ranks gather objects from every rank in the same
communicator. The default return is a list of length equal to
comm.size(comm)
.
allgather(x, x.buffer = NULL, x.count = NULL, displs = NULL,
comm = .pbd_env$SPMD.CT$comm,
unlist = .pbd_env$SPMD.CT$unlist)
x |
an object to be gathered from all ranks. |
x.buffer |
a buffer to hold the return object which probably has
'size of |
x.count |
a vector of length ' |
displs |
|
comm |
a communicator number. |
unlist |
apply |
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 allgather
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{"allgather"}
for S4 dispatch cases and the source code for
further details.
A list of length comm.size(comm)
, containing the gathered objects from
each rank, is returned to all ranks by default. An exception is for atomic
vectors, when
x.buffer
is specified, where a list is never formed and a single
vector is returned. In other cases, the unlist = TRUE
parameter
simply applies the unlist()
function to this list before returning.
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/
gather()
, 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 <- allgather(matrix(x, nrow = 1))
comm.print(y)
y <- allgather(x, double(N * .comm.size))
comm.print(y)
### Finish
finalize()
"
pbdMPI::execmpi(spmd.code, nranks = 2L)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.