You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

28 lines
532 B

if ( !is.loaded("mpi_initialize") ){
library(Rmpi)
}
number_of_plots = 5
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/', 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()