library(Rmpi) mpi.spawn.Rslaves(needlog = FALSE) mpi.bcast.cmd( id <- mpi.comm.rank() ) mpi.bcast.cmd( np <- mpi.comm.size() ) mpi.bcast.cmd( host <- mpi.get.processor.name() ) result <- mpi.remote.exec(paste("I am", id, "of", np, "running on", host)) print(unlist(result)) # Sample one normal observation on the master and each slave x <- rnorm(1) mpi.bcast.cmd(x <- rnorm(1)) # Gather the entire x vector (by default to process 0, the master) mpi.bcast.cmd(mpi.gather.Robj(x)) y <- mpi.gather.Robj(x) print(unlist(y)) # Sum the x vector together, storing the result on process 0 by default mpi.bcast.cmd(mpi.reduce(x, op = "sum")) z <- mpi.reduce(x, op = "sum") print(z) mpi.close.Rslaves(dellog = FALSE) mpi.exit()