This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
hpc-cluster:r [2014/05/18 20:51] sluedtke [dompi] |
— (current) | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | The popular statistics software [[http:// | ||
- | the HPC and eases: | ||
- | |||
- | * running jobs that take a long time | ||
- | * running jobs that require a lot of memory | ||
- | * and of course, running jobs in parallel | ||
- | |||
- | At the moment, two different libraries are available on the cluster for parallization: | ||
- | |||
- | -[[http:// | ||
- | MPI (Message-Passing Interface) | ||
- | |||
- | -[[http:// | ||
- | [[http:// | ||
- | for the Rmpi package | ||
- | |||
- | NOTES: | ||
- | |||
- | * **Rmpi** (which is required by both libraries) was compiled using **openmpi**, | ||
- | sure the modules are available | ||
- | * the R-script must be executable (`` chmod 766 r-script-name ``) | ||
- | * add the path to the R-script executable at the top line as a // | ||
- | |||
- | |||
- | ===== Rmpi ===== | ||
- | Using the package **Rmpi** requires a sound scripting in order to distribute the work | ||
- | and handle the communication. In addition, a script is necessary the make the workers | ||
- | available to **R** at the beginning. This part is usually shipped with an **.Rprofile**, | ||
- | located either in the working or in the HOME directory. | ||
- | |||
- | There are multiple ways to ensure that: | ||
- | |||
- | * copy the **.Rprofile** | ||
- | ~/ | ||
- | |||
- | * **.Rprofile** located in HOME | ||
- | |||
- | * set the environment variable | ||
- | | ||
- | file | ||
- | |||
- | ===== dompi ===== | ||
- | Using the package **doMPI** enables parallization with //foreach// loops in **R**. See the | ||
- | package documentation for details. | ||
- | |||
- | **In order to starts the jobs properly, there must not be a .Rprofile available within the | ||
- | current environment.** | ||
- | |||
- | An example for **doMPI** and a corresponding job script. | ||
- | |||
- | <file bash start_par_R.sh> | ||
- | |||
- | # | ||
- | # show commands being executed, per debug | ||
- | set -x | ||
- | |||
- | # Set job parameters | ||
- | ###################################################################### | ||
- | ## check what MPI implementation is loaded before setting the parameter | ||
- | ## module list ?? | ||
- | #BSUB -a openmpi | ||
- | |||
- | # Set number of CPUs | ||
- | #BSUB -n 16 | ||
- | |||
- | # name of the output file | ||
- | #BSUB -o 16_cpus.out | ||
- | |||
- | |||
- | # Start R MPI job | ||
- | mpirun.lsf ./ | ||
- | |||
- | </ | ||
- | |||
- | And the R-script that is called. | ||
- | |||
- | <file R dompi_example.sh> | ||
- | |||
- | ################################################################################################ | ||
- | ################################################################################################ | ||
- | |||
- | ################################################################################################ | ||
- | |||
- | rm(list=ls()) | ||
- | |||
- | ################################################################################################ | ||
- | library(reshape) # | ||
- | |||
- | library(cluster) # | ||
- | library(fpc) # | ||
- | |||
- | library(doMPI) # | ||
- | library(foreach) # | ||
- | |||
- | ################################################################################################ | ||
- | |||
- | |||
- | # create some random data in a matrix, make them reproducible | ||
- | |||
- | set.seed(1) | ||
- | data=matrix(c(runif(300, | ||
- | |||
- | |||
- | # create distance matrix the cluster algorithm requires | ||
- | dist_mat=dist(data, | ||
- | |||
- | |||
- | #compute the cluster Dendrogramm for the data | ||
- | cluster_fit=hclust(dist_mat, | ||
- | |||
- | # | ||
- | # | ||
- | # | ||
- | # | ||
- | |||
- | # That bit runs distributed over multiple nodes specified in the | ||
- | # jobscript compute cluster validation indices for each cluster | ||
- | # class, we only check classes 2 to nrow(data)/ | ||
- | |||
- | cl = startMPIcluster() # | ||
- | # get- managed by the startup script | ||
- | |||
- | registerDoMPI(cl) # register cl for the foreach framework | ||
- | |||
- | |||
- | cluster_groups=foreach(i=c(2: | ||
- | .packages=c(" | ||
- | { | ||
- | cluster.stats(dist_mat, | ||
- | } | ||
- | |||
- | closeCluster(cl) | ||
- | |||
- | # | ||
- | # | ||
- | # | ||
- | # | ||
- | |||
- | #extract indices of interest, that is a list of names as returned by the function | ||
- | # " | ||
- | |||
- | indices=c(" | ||
- | |||
- | cluster_performance=as.data.frame(t(cluster_groups[which(row.names(cluster_groups) | ||
- | %in% indices==TRUE), | ||
- | |||
- | row.names(cluster_performance)=NULL | ||
- | |||
- | |||
- | ## save the R workspace as " | ||
- | save.image() | ||
- | ############################################################################################### | ||
- | ################################################################################################ | ||
- | |||
- | < | ||
- | |||
- | ===== Attention ===== | ||
- | |||
- | **doMPI** provides a simple framework that allows running parallel applications almost no | ||
- | extra effort. However, this does not make sense at all time. Is the single iteration | ||
- | pretty fast, a serial implementation makes more sense because the communication overhead | ||
- | will slow down the entire process. | ||
- | |||
- | A more flexible framework is provided by the **Rmpi** implementation, | ||
- | the implement. A popular example can be found at at this | ||
- | [[http:// | ||
- | |||