Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
export R_LIBS=/scratch/$USER/rlibs
> R
R version 4.1.1 (2021-08-10) -- "Kick Things"
Copyright (C) 2021 The R Foundation for Statistical Computing
Platform: x86_64-suse-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
> library(readxl)
> readxl 
readxl_example   readxl_progress  readxl::         
> readxl_example()
 [1] "clippy.xls"    "clippy.xlsx"   "datasets.xls"  "datasets.xlsx"
 [5] "deaths.xls"    "deaths.xlsx"   "geometry.xls"  "geometry.xlsx"
 [9] "type-me.xls"   "type-me.xlsx" 
> readxl_example('clippy.xlsx')
[1] "/lustre/scratch/shaima0d/rlibs/readxl/extdata/clippy.xlsx"

You can achieve the same goal using the command line invocation of the R installer:

R batch job on compute node

To run a batch job using R script, simple prepare the script and simply prepare the script are use Rscript in your SLURM jobscript to launch it. The following jobscript demonstrates a hello world example run as a batch job:

Code Block
simulation = function(long){
  c = rep(0,long)
  numberIn = 0
  for(i in 1:long){
    x = runif(2,-1,1)
    if(sqrt(x[1]*x[1] + x[2]*x[2]) <= 1){
      numberIn = numberIn + 1
    }
    prop = numberIn / i
    piHat = prop *4
    c[i] = piHat
  }
  return(c)
}

size = 1000
res = simulation(size)
sprintf('calculated Pi value= %f',res[size])

The SLURM jobscript to execute the above script will look as follows:

Code Block
#!/bin/bash
#SBATCH -n 1 
#SBATCH -c 32
#SBATCH --hint=nomultithread
#SBATCH -t 00:10:00


module load cray-R
srun -n 1 --hint=nomultithread Rscript pi.R