# 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()
.comm.size <- comm.size()
.comm.rank <- comm.rank()
### Examples
N <- 5
x <- (1:N) + N * .comm.rank
if(.comm.rank == 0){
isend(list(x))
}
if(.comm.rank == 1){
y <- irecv(list(x))
}
wait()
comm.print(y, rank.print = 1L)
### Finish
finalize()
Run the code above in your browser using DataLab