28 lines
537 B
R
28 lines
537 B
R
if ( !is.loaded("mpi_initialize") ){
|
|
library(Rmpi)
|
|
}
|
|
|
|
number_of_plots = 10
|
|
nodes = mpi.universe.size()-1
|
|
mpi.spawn.Rslaves(nslaves=nodes)
|
|
|
|
generate_plot <- function(filename){
|
|
print(mpi.comm.rank())
|
|
samples = rep(NA, 100000)
|
|
for ( i in 1:100000 ){ samples[i] = mean(rexp(40, 0.2)) }
|
|
|
|
jpeg(paste('plots/plot', filename, '.jpg', sep=""))
|
|
|
|
hist(samples, main="", prob=T)
|
|
lines(density(samples), col="darkblue", lwd=3)
|
|
|
|
dev.off()
|
|
}
|
|
|
|
samples = 1:number_of_plots
|
|
|
|
mpi.applyLB(samples, generate_plot)
|
|
|
|
mpi.close.Rslaves()
|
|
mpi.quit()
|