inst/examples/test_parallel/02_parMM_spmd.r

### This example is analog to "parMM_par.r", and one can run it by the command
### SHELL> mpiexec -np 2 Rscript --vanilla 02_parMM_spmd.r

suppressMessages(library(pbdMPI, quietly = TRUE))

set.seed(123)
x <- matrix(rnorm(1e6), 1e3)

parMM.spmd <- function(x, y){
  id <- get.jid(nrow(x))
  do.call(rbind, allgather(x[id,] %*% y))
}
time.proc <- system.time(replicate(10, parMM.spmd(x, x)))
comm.print(time.proc)

finalize()
RBigData/pbdMPI documentation built on Jan. 31, 2024, 10:34 p.m.