global any and all | R Documentation |
These functions are global any and all applying on distributed data for all ranks.
comm.any(x, na.rm = FALSE, comm = .pbd_env$SPMD.CT$comm)
comm.all(x, na.rm = FALSE, comm = .pbd_env$SPMD.CT$comm)
comm.allcommon(x, comm = .pbd_env$SPMD.CT$comm,
lazy.check = .pbd_env$SPMD.CT$lazy.check)
x |
a vector. |
na.rm |
if |
comm |
a communicator number. |
lazy.check |
if TRUE, then |
These functions will apply any()
and all()
locally, and
apply allgather()
to get all local results from other ranks, then
apply any()
and all()
on all local results.
comm.allcommon()
is to check if x
is exactly the same
across all ranks. This is a vectorized operation on x
where the
input and output have the same length of vector, while comm.any()
and comm.all()
return a scaler.
Note that lazy.check = TRUE
is faster as
number of cores is large, but it may cause some inconsistence in some
cases. lazy.check = FALSE
is much slower, but it provides more
accurate checking.
The global check values (TRUE, FALSE, NA) are returned to all ranks.
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/
## 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))
### Examples.
if(comm.rank() == 0){
a <- c(T, F, NA)
} else{
a <- T
}
comm.any(a)
comm.all(a)
comm.any(a, na.rm = TRUE)
comm.all(a, na.rm = TRUE)
comm.allcommon(1:3)
if(comm.rank() == 0){
a <- 1:3
} else{
a <- 3:1
}
comm.allcommon.integer(a)
### 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.