gather-methods | R Documentation |
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)
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 |
|
rank.dest |
a rank of destination where all |
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 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/
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))
comm.print(y)
y <- gather(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.