R for HPC

For batch processing, you have to write R script and Job script. R script can be written in R studio and saved as a script file. But to submit a job one needs to avail of PuTTY & WinSCP. A brief description of different steps are provided below (click on R for HPC for details).

  1. Download and install PuTTY from http://www.putty.org/ following the instructions therein.
  2. Download and install WinSCP from http://winscp.net/eng/docs/guide_install following the instructions therein.
  3. Write R script file signal.r
#!/usr/bin/env Rscript
# signal.r R program to compute prop correct dimension.
seq(-10,10, by=0.1)->x
plot(x, cos(x), type="l") # for Plot.pdf file
postscript("/datastore/username/signal.eps", horizontal=FALSE, height=2.5, width=3) 
  par(mfrow=c(1,1), mar=c(2,2,2,2)+0.5)
  plot(x, cos(x),type="l", lty=1, cex.axis=0.75,ylim=c(-1.1, 1.1 ),xlab="m", ylab="", cex=0.8)
dev.off()
write.csv(x, file="/datastore/username/cosx.csv") # for excel output
  1. Write job script file signal.sh
#!/bin/bash
#PBS -l walltime=00:15:00,vmem=4GB
#PBS -l nodes=1:ppn=8
# set the temporary file location
export TMPDIR=$WORKDIR
# go to the job submission directory
cd $PBS_O_WORKDIR
# load the R module; change the version if needed
module load R/3.1.0
# run R
Rscript --vanilla signal.r

5. Submit job by using the command

qsub signal.sh

The above procedures can be used to submit scripts on the TORQUE. If you are using some other job scheduler like SLURM, it could be modified by using commands as in the following script boxes.

An example for Rscript file signal.r for SLURM submission

seq(-10,10, by=0.1)->x
plot(x, cos(x), type="l") # for Plot.pdf file
postscript("/datastore/username/signal.eps", horizontal=FALSE, height=2.5, width=3) # this produces signal.eps file
par(mfrow=c(1,1), mar=c(2,2,2,2)+0.5)
plot(x, cos(x),type="l", lty=1, cex.axis=0.75,ylim=c( -1.1, 1.1 ),xlab="m", ylab="", cex=0.8)
dev.off()
write.csv(x, file="/datastore/kha04m/cosx.csv") # for excel output

An example for SLURM job file signal.slurm for SLURM submission

#!/bin/bash
#SBATCH --job-name="signal"
#SBATCH --time=2:00:00
# set the temporary file location
export TMPDIR=$SUBMIT_DIR
# go to the job submission directory
cd $SLURM_SUBMIT_DIR
module load R
# run R
Rscript --vanilla signal.R

Use following commands for job submission

sbatch signal.slurm # to submit the job
squeue # to see the list of submitted files by all users
squeue -u atik01 # to see job submitted by the user "atik01"
squeue - u 1245 # to see the the job by its ID 1245
scancel 1245 # to delete the job with ID 1245
scontrol show job 1245 # shows details of job with ID 1245

 

 

One comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s