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