k8s-hpc-demo/demos/sample_means/generate_plots.R

28 lines
537 B
R
Raw Permalink Normal View History

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-03 00:04:58 +00:00
number_of_plots = 10
2019-05-01 21:14:48 +00:00
nodes = mpi.universe.size()-1
2019-05-01 20:40:04 +00:00
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)) }
2019-05-03 00:04:58 +00:00
jpeg(paste('plots/plot', filename, '.jpg', sep=""))
2019-05-01 20:40:04 +00:00
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()