### 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))
### Examples.
x <- matrix(1:5, nrow = 1)
y <- bcast(x)
comm.print(y)
### Finish.
finalize()
"
pbdMPI::execmpi(spmd.code, nranks = 2L)
Run the code above in your browser using DataLab