global which, which.max, and which.min {pbdMPI} | R Documentation |
These functions are global which, which.max and which.min applying on distributed data for all ranks.
comm.which(x, arr.ind = FALSE, useNames = TRUE, comm = .pbd_env$SPMD.CT$comm) comm.which.max(x, comm = .pbd_env$SPMD.CT$comm) comm.which.min(x, comm = .pbd_env$SPMD.CT$comm)
x |
a 'logical' vector or array as in |
arr.ind |
logical, as in |
useNames |
logical, as in |
comm |
a communicator number. |
These functions will apply which()
, which.max()
and
which.min()
locally, and apply allgather()
to get all local
results from other ranks.
The global values (which()
, which.max()
, or which.min()
)
are returned to all ranks.
comm.which()
returns with two columns, 'rank id' and 'index of
TRUE
'.
comm.which.max()
and comm.which.min()
return with three
values, 'the _smallest_ rank id', 'index of the _first_ maximum or minimum',
and 'max/min value of x
'.
Wei-Chen Chen wccsnow@gmail.com, George Ostrouchov, Drew Schmidt, Pragneshkumar Patel, and Hao Yu.
Programming with Big Data in R Website: http://r-pbd.org/
## Not run: ### Save code in a file "demo.r" and run with 2 processors by ### SHELL> mpiexec -np 2 Rscript demo.r ### Initial. suppressMessages(library(pbdMPI, quietly = TRUE)) init() if(comm.size() != 2){ comm.cat("2 processors are requried.\n", quiet = TRUE) finalize() } ### Examples. a <- 1:(comm.rank() + 1) b <- comm.which(a == 2) comm.print(b) b <- comm.which.max(a) comm.print(b) b <- comm.which.min(a) comm.print(b) ### Finish. finalize() ## End(Not run)