if (FALSE) {
### 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))
.comm.size <- comm.size()
.comm.rank <- comm.rank()
### Examples.
N <- 5
x <- (1:N) + N * .comm.rank
if(.comm.rank == 0){
y <- send(matrix(x, nrow = 1))
} else if(.comm.rank == 1){
y <- irecv()
}
comm.print(y, rank.print = 1)
### Finish.
finalize()
"
# execmpi(spmd.code, nranks = 2L)
}
Run the code above in your browser using DataLab