Learn R Programming

pbdMPI (version 0.1-4)

global any and all function: Global any and all for Distributed Vectors or Matrices

Description

These functions are global any and all applying on distributed data for all ranks.

Usage

comm.any(x, na.rm = FALSE, comm = .SPMD.CT$comm)
  comm.all(x, na.rm = FALSE, comm = .SPMD.CT$comm)

Arguments

x
a vector.
na.rm
if NA removed or not.
comm
a communicator number.

Value

  • The global check values (TRUE, FALSE, NA) are returned to all ranks.

Details

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.

References

Programming with Big Data in R Website: http://r-pbd.org/

Examples

Run this code
# Save code in a file "demo.r" and run with 2 processors by
# > mpiexec -np 2 Rscript demo.r

### Initial
library(pbdMPI, quiet = TRUE)
init()
if(comm.size() != 2){
  warning("2 processors is requried to run this demo.")
  finalize()
}

### Examples
if(comm.rank() == 0){
  a <- c(T, F, NA)
} else{
  a <- T
}

comm.print(comm.any(a))
comm.print(comm.all(a))
comm.print(comm.any(a, na.rm = TRUE))
comm.print(comm.all(a, na.rm = TRUE))

### Finish
finalize()

Run the code above in your browser using DataLab