# Save code in a file "demo.r" and run in 4 processors by
# > mpirun -np 4 Rscript demo.r
### Setup mpi environment.
library(Rmpi)
library(pmclust)
invisible(mpi.comm.dup(0, 1))
### Generate an example data.
N.allspmds <- rep(5000, mpi.comm.size())
N.spmd <- 5000
N.K.spmd <- c(2000, 3000)
N <- 5000 * mpi.comm.size()
p <- 2
K <- 2
seed <- 123 + mpi.comm.rank()
data.spmd <- generate.basic.spmd(N.allspmds, N.spmd, N.K.spmd,
N, p, K, seed)
X.spmd <- data.spmd$X.spmd
### Run clustering.
PARAM.org <- set.global(K = K)
# PARAM.org <- initial.em.spmd(PARAM.org)
PARAM.org <- initial.RandEM.spmd(PARAM.org)
PARAM.new <- em.step.spmd(PARAM.org)
em.update.class.spmd()
mb.print(PARAM.new, CHECK)
### Get results.
N.CLASS <- get.N.CLASS(K)
catmpi("# of class:", N.CLASS, "\n")
### Quit Rmpi.
mpi.quit()Run the code above in your browser using DataLab