User Tools

Site Tools


Table of Contents

Using R

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:

module add chpc/R/3.2.3-gcc5.1.0

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:

module avail 2>&1 | grep "R"


Parallel R

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.

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.

Example job script file:

#PBS -l select=10:ncpus=24:mpiprocs=24:nodetype=haswell_reg
#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 abe
# Add R module (includes appropriate openMPI and gcc modules)
module add chpc/R/3.2.3-gcc5.1.0
# explicitly calculate number of processes.
nproc=`cat $PBS_NODEFILE | wc -l`
# make sure we're in the correct working directory.
cd /mnt/lustre/users/USERNAME/my_R_data
mpirun -np $nproc -machinefile $PBS_NODEFILE  R --slave -f myScRipt.r


  • Replace USERNAME with your user name.
  • Replace SHORTNAME with your research programme's short name.
  • Replace 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

qsub my_R_job.qsub

Check the list of current jobs in the queue

qstat -w


Here is a more complete example

pbdR example

Job scripts
#PBS -l select=2:ncpus=24:mpiprocs=24:nodetype=haswell_reg,place=excl
#PBS -l walltime=00:01:00
#PBS -q normal
#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 -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

Note: USERNAME should contain your actual user name!

library(pbdMPI, quiet=TRUE)
my.rank <- comm.rank()
comm.print(my.rank, all.rank=TRUE)
Submit your job

Finally submit your job using:

user@login01:~ $ qsub pbdtest.qsub
/var/www/wiki/data/pages/howto/r.txt · Last modified: 2016/06/17 09:30 by dane