global balanc | R Documentation |
These functions are global balance methods for gbd data.frame
(or
matrix
) distributed in row blocks.
comm.balance.info(X.gbd, balance.method = .pbd_env$SPMD.IO$balance.method[1],
comm = .pbd_env$SPMD.CT$comm)
comm.load.balance(X.gbd, bal.info = NULL,
balance.method = .pbd_env$SPMD.IO$balance.method[1],
comm = .pbd_env$SPMD.CT$comm)
comm.unload.balance(new.X.gbd, bal.info, comm = .pbd_env$SPMD.CT$comm)
X.gbd |
a gbd |
balance.method |
a balance method. |
bal.info |
a balance information returned from
|
new.X.gbd |
a new gbd of |
comm |
a communicator number. |
A typical use is to balance an input dataset X.gbd
from
comm.read.table()
. Since by default, a two dimension
data.frame
is distributed in row blocks, but each processor (rank)
may not (or closely) have the same number of rows.
These functions redistribute the data.frame
(and maybe
matrix
) according to the specified way in bal.info
.
Currently, there are three balance methods are supported, block
(uniform distributed but favor higher ranks), block0
(as block
but favor lower ranks), and block.cyclic
(as block cyclic with one big block in one cycle).
comm.balance.info()
returns a list
containing
balance information based on the input X.gbd
and balance.method
.
comm.load.balance()
returns a new gbd data.frame
(or
matrix
).
comm.unload.balance()
also returns the new gbd data.frame
back
to the original X.gbd
.
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/
comm.read.table()
,
comm.write.table()
, and
comm.as.gbd()
.
## Not run:
### 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))
### Get two gbd row-block data.frame.
da.block <- iris[get.jid(nrow(iris), method = \"block\"),]
da.block0 <- iris[get.jid(nrow(iris), method = \"block0\"),]
### Load balance one and unload it.
bal.info <- comm.balance.info(da.block0)
da.new <- comm.load.balance(da.block0)
da.org <- comm.unload.balance(da.new, bal.info)
### Check if all are equal.
comm.print(c(sum(da.new != da.block), sum(da.org != da.block0)),
all.rank = TRUE)
### Finish.
finalize()
"
# execmpi(spmd.code, nranks = 2L)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.