k8s-hpc-demo/demos/sample_means/generate_plots.R
2019-05-01 15:40:04 -05:00

27 lines
504 B
R

if ( !is.loaded("mpi_initialize") ){
library(Rmpi)
}
number_of_plots = 5
nodes = mpi.universe.size()
mpi.spawn.Rslaves(nslaves=nodes)
generate_plot <- function(filename){
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()
}
samples = 1:number_of_plots
mpi.apply(samples, generate_plot)
mpi.close.Rslaves()
mpi.quit()