User Tools

Site Tools


howto:r

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
howto:r [2013/03/04 11:09]
kevin
howto:r [2021/12/09 16:42] (current)
Line 1: Line 1:
 ====== Using R ====== ====== Using R ======
  
-**R** is installed in ''/opt/gridware/applications/R/R-2.15.2/'' and is compiled using Open-MPI with the GNU compilers so you will need to add +**R** has been installed in ''/apps/chpc/bio/R/?'' and is compiled using openmpi and the GNU compilers. R modules have been created so simply adding:
 <code> <code>
-module add openmpi/openmpi-1.6.1-gnu+module add chpc/R/3.2.3-gcc5.1.0
 </code> </code>
  
-to your **''.bashrc''**  file in your home directory.+to your scripts will set up the appropriate paths to R, the compilers (if you want to add your own R packages) and the mpi libraries. Note that there may be several versions of R installed and can be seen by running the: <code>module avail 2>&1 | grep "R"</code> command.
  
-==== Changes to .profile file ==== 
  
-On the CHPC clusters the ''.bashrc'' file is not automatically run for interactive logins, only the ''.profile'' file is.  To rectify this add the following lines to the **end** of your ''.profile'' file:+===== Parallel R =====
  
-<code bash> +The ''Rmpi'', ''doMPI'' and other packages are already installed to allow R to use MPI to distribute its work across multiple nodes of the cluster**Please submit a request to helpdesk should you need any other packages installed.**
-if [ -f ~/.bashrc ]; then +
-    ~/.bashrc +
-fi +
-</code>+
  
-Then make any changes to the ''PATH'variable in your ''.bashrc'' file.  It is vital that all paths are updated in the ''.bashrc'' file is because that file is run for non-interactive jobs, which all the jobs submitted to the Moab queues are.+Once you've created your R script file, called ''myScRipt.r'', you will need to create a job script file to submit to the PBSPro scheduler.
  
-==== Changes to .bashrc ====+Example job script file:
  
-Now you must add the R path to ''PATH'' in your ''.bashrc'' file by including the following line:+<file bash my_R_job.qsub> 
 +#!/bin/bash 
 +#PBS -l select=2:ncpus=24:mpiprocs=24 
 +#PBS -P SHORTNAME 
 +#PBS -q normal 
 +#PBS -l walltime=4:00:00 
 +#PBS -o /mnt/lustre/users/USERNAME/my_R_data/stdout.txt 
 +#PBS -e /mnt/lustre/users/USERNAME/my_R_data/stderr.txt 
 +#PBS -N RJob 
 +#PBS -M myemailaddress@someplace.com 
 +#PBS -m abe
  
-<code bash> +# Add R module (includes appropriate openMPI and gcc modules) 
-export PATH=/opt/gridware/applications/R/R-2.15.2/bin:$PATH +module add chpc/R/3.2.3-gcc5.1.0
-</code>+
  
-=====Parallel R=====+# explicitly calculate number of processes. 
 +nproc=`cat $PBS_NODEFILE | wc -l`
  
-The ''rMPI'' and ''doMPI'' packages are already installed to allow R to use MPI to distribute its work across multiple nodes of the cluster.+# make sure we're in the correct working directory. 
 +cd /mnt/lustre/users/USERNAME/my_R_data
  
-Once you've created your script file, called '''job-1.r''', you will need to create a job script file to submit to the Moab scheduler.+mpirun -np $nproc -machinefile $PBS_NODEFILE  R --slave -f myScRipt.r 
 +</file>
  
-Example job script file:+**Notes:** 
 +  * Replace ''USERNAME'' with **your** user name. 
 +  * Replace ''SHORTNAME'' with **your research programme's** short name. 
 +  * Replace ''myemailaddress@someplace.com'' with **your** email address. 
 +  * And replace ''my_R_data'' with your program's //working directory// (which **must** be under ''/mnt/lustre/users/USERNAME/''). 
 +  * And change ''myScRipt.r'' to be your //script file name//.
  
 +===Running the script===
 +
 +Submit to the scheduler
 <code> <code>
-#!/bin/bash +qsub my_R_job.qsub
-#MSUB -l nodes=2:ppn=8 +
-#MSUB -l walltime=1:00:00 +
-#MSUB -V +
-#MSUB -o /export/home/username/simulations/job-1.out +
-#MSUB -e /export/home/username/simulations/job-1.err +
-#MSUB -d /export/home/username/simulations +
-#MSUB -M be your_emall@address +
-#MSUB -q  +
-  +
-mpirun -np 16 /opt/gridware/applications/R/R-2.15.2/bin/R --slave -f /export/home/username/simulations/job-1.r+
 </code> </code>
  
-**Notes:** +Check the list of current jobs in the queue 
-  * Replace ''username'' with **your** user name+<code> 
-  * Replace ''your_emall@address'' with **your** email address+qstat -w 
-  * And replace ''simulations'' with your program'//working directory// (which should really be on ''scratch'' for speed)+</code> 
-  * And change ''job-1'' to be your //script file name//.+ 
 +==== R/bioconductor ==== 
 + 
 +Here is a more complete example 
 + 
 +=== pbdR example === 
 +== Job scripts == 
 +<file bash pbdtest.qsub> 
 +#PBS -l select=2:ncpus=24:mpiprocs=24:place=excl 
 +#PBS -l walltime=00:01:00 
 +#PBS -q normal 
 +#PBS -P SHORTNAME 
 +#PBS -M YOUREMAILADDRESS 
 +#PBS -m be 
 +#PBS -e /mnt/luster/users/USERNAME/pbdR_test/std_err.txt 
 +#PBS -o /mnt/lustre/users/USERNAME/pbdR_test/std_out.txt 
 +#PBS -N PBDR_TEST 
 +#PBS -mb 
 + 
 +module add chpc/R/3.2.3-gcc5.1.0 
 + 
 +NP=`cat ${PBS_NODEFILE} | wc -l` 
 + 
 +cd /mnt/lustre/users/USERNAME/pbdR_test/ 
 +mpirun -np ${NP} -machinefile ${PBS_NODEFILE} Rscript test_script.R 
 + 
 +</file
 +Note: __USERNAME__ should contain your actual user name
 + 
 +<file R test_script.R> 
 +library(pbdMPI, quiet=TRUE) 
 +init() 
 +my.rank <- comm.rank() 
 +comm.print(my.rank, all.rank=TRUE) 
 + 
 +finalize() 
 +</file> 
 + 
 +== Submit your job == 
 +Finally submit your job using:<code bash>user@login01:~ $ qsub pbdtest.qsub</code> 
/app/dokuwiki/data/attic/howto/r.1362388153.txt.gz · Last modified: 2021/12/09 16:42 (external edit)