global which, which.max, and which.min | 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: https://pbdr.org/
comm.read.table()
## 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))
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()
"
# 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.