R-Teaching: Difference between revisions

From Research Computing Center Wiki
Jump to navigation Jump to search
No edit summary
 
(One intermediate revision by one other user not shown)
Line 5: Line 5:
Teaching
Teaching
=== Version ===
=== Version ===
4.0.0
3.6.2, 4.1.2, 4.2.1, 4.3.1, 4.3.2
===Author / Distributor===
===Author / Distributor===
See http://www.r-project.org/
See http://www.r-project.org/
Line 16: Line 16:




'''R version 4.0.0'''
'''R version 4.3.1'''


R version 4.0.0 is installed in /apps/eb/R/4.0.0-foss-2019b and add-on packages are installed in /apps/eb/R/4.0.0-foss-2019b/lib64/R/library
R version 4.3.1 is installed in /apps/eb/R/4.3.1-foss-2022a and add-on packages are installed in /apps/eb/R/4.3.1-foss-2022a/lib64/R/library. You can list all files in this dir to see the packages installed with this version of R.


To use this version of R, please first load the module with
To use this version of R, please first load the module with
<pre class="gscript">
<pre class="gscript">
module load R/4.0.0-foss-2019b
module load R/4.3.1-foss-2022a
</pre>
 
 
'''R version 4.2.1'''
 
R version 4.2.1 is installed in /apps/eb/R/4.2.1-foss-2022a and add-on packages are installed in /apps/eb/R/4.2.1-foss-2022a/lib64/R/library. You can list all files in this dir to see the packages installed with this version of R.
 
To use this version of R, please first load the module with
<pre class="gscript">
module load R/4.2.1-foss-2022a
</pre>
 
 
'''R version 4.1.2'''
 
R version 4.1.2 is installed in /apps/eb/R/4.1.2-foss-2021b and add-on packages are installed in /apps/eb/R/4.1.2-foss-2021b/lib64/R/library. You can list all files in this dir to see the packages installed with this version of R.
 
To use this version of R, please first load the module with
<pre class="gscript">
module load R/4.1.2-foss-2021b
</pre>  
</pre>  
Please note that when you load this R module, many other modules will be loaded as R depends on those other libraries and packages.
Please note that when you load this R module, many other modules will be loaded as R depends on those other libraries and packages.




Here is an example of a shell script, sub.sh, to run on the batch queue:  
A number of R packages are provided by other module files. For example, many packages that depend on the JAGS library, such as rjags, are provided by the rjags/4-12-foss-2022a-R-4.3.1 module, which can be loaded with
<pre class="gscript">
module load rjags/4-12-foss-2022a-R-4.3.1
</pre>
 
 
 
'''How to run R programs with multithreads'''
 
Some functions in the R packages are written with OpenMP and can run in parallel using multithreads. The R module files set the variable OMP_NUM_THREADS=1, to specify using only one thread. If you are using a function in an R package that is enabled to run with multithreads, please set the OMP_NUM_THREADS variable to the number of threads you want to use and request the same number of cores for your job. Note that you would need to set this variable '''after''' you load the R module, for it to have effect. For example, to use 6 threads, request 6 cores on the same node with
<pre class="gscript">
#SBATCH --ntasks=1
#SBATCH --cpus-per-task=6
</pre>
and set
<pre class="gscript">
export OMP_NUM_THREADS=6
</pre>
 
You can set OMP_NUM_THREADS to automatically correspond to the number of cores per task requested for the job, by setting it to $SLURM_CPUS_PER_TASK, with
<pre class="gscript">
export OMP_NUM_THREADS=$SLURM_CPUS_PER_TASK
</pre>
A sample job submission to run a multithread job is provided below.
 
 
'''Sample Job Submission Scripts'''
Here is an example of a shell script, sub.sh, to run a serial R script on the batch queue:  


<div class="gscript2">
<pre class="gscript">
<nowiki>#</nowiki>!/bin/bash<br>
#!/bin/bash
<nowiki>#</nowiki>SBATCH --job-name=j_R<br>
#SBATCH --job-name=testRjob
<nowiki>#</nowiki>SBATCH --partition=batch<br>        
#SBATCH --partition=batch         
<nowiki>#</nowiki>SBATCH --mail-type=ALL<br>
#SBATCH --ntasks=1
<nowiki>#</nowiki>SBATCH --mail-user=<u>username@uga.edu</u><br> 
#SBATCH --mem=10gb  
<nowiki>#</nowiki>SBATCH --ntasks=<u>1</u><br> 
#SBATCH --time=08:00:00   
<nowiki>#</nowiki>SBATCH --mem=<u>10gb</u><br>   
#SBATCH --output=%x.%j.out
<nowiki>#</nowiki>SBATCH --time=<u>08:00:00</u><br>    
#SBATCH --error=%x.%j.err
<nowiki>#</nowiki>SBATCH --output=R.%j.out<br>
<nowiki>#</nowiki>SBATCH --error=R.%j.err<br>
   
   
cd $SLURM_SUBMIT_DIR<br>
cd $SLURM_SUBMIT_DIR
ml R/4.0.0-foss-2019b<br>   
 
R CMD BATCH <u>program.R</u><br>    
module load R/4.3.1-foss-2022a 
</div>
 
In the real submission script, at least all the above underlined values need to be reviewed or to be replaced by the proper values.
R CMD BATCH program.R   
</pre>
where program.R is just a sample program name and needs to be replaced by the name of the program you wish to run. The settings in the header lines, such as the job name, the email address, the number of cores, memory and walltime limit, need to be changed appropriately as well.


Please refer to [[Running_Jobs_on_the_teaching_cluster]], [[Running_Jobs_on_the_teaching_cluster#Running_an_X-windows_application | Run X window Jobs]] and [[Running_Jobs_on_the_teaching_cluster#How_to_open_an_interactive_session | Run interactive Jobs]] for more details of running jobs at Teaching cluster.
 
Here is an example of a shell script, sub.sh, to run a multithread R script on the batch queue:
 
<pre class="gscript">
#!/bin/bash
#SBATCH --job-name=testRjob
#SBATCH --partition=batch       
#SBATCH --ntasks=1
#SBATCH --cpus-per-task=6
#SBATCH --mem=10gb 
#SBATCH --time=08:00:00 
#SBATCH --output=%x.%j.out
#SBATCH --error=%x.%j.err
cd $SLURM_SUBMIT_DIR
 
module load R/4.3.1-foss-2022a 
 
export OMP_NUM_THREADS=$SLURM_CPUS_PER_TASK
 
R CMD BATCH program.R 
</pre>
where program.R is just a sample program name and needs to be replaced by the name of the program you wish to run. The settings in the header lines, such as the job name, the email address, the number of cores, memory and walltime limit, need to be changed appropriately as well.




Line 54: Line 124:
sbatch ./sub.sh  
sbatch ./sub.sh  
</pre>
</pre>


=== Documentation ===
=== Documentation ===
Please see http://www.r-project.org/
Please see http://www.r-project.org/
=== Installation ===
=== Installation ===
* Version 4.0.0 is installed in /apps/eb/R/4.0.0-foss-2019b/ and add-on packages are installed in /apps/eb/R/4.0.0-foss-2019b/lib64/R/library
Source code downloaded from https://www.r-project.org/
 


=== System ===
=== System ===
64-bit Linux
64-bit Linux

Latest revision as of 07:36, 14 May 2024

Category

Statistics

Program On

Teaching

Version

3.6.2, 4.1.2, 4.2.1, 4.3.1, 4.3.2

Author / Distributor

See http://www.r-project.org/

Description

R is a language and environment for statistical computing and graphics. It provides a wide variety of statistical (linear and nonlinear modeling, classical statistical tests, time-series analysis, classification, clustering, ...) and graphical techniques.

Running Program

Also refer to Running Jobs on the teaching cluster


R version 4.3.1

R version 4.3.1 is installed in /apps/eb/R/4.3.1-foss-2022a and add-on packages are installed in /apps/eb/R/4.3.1-foss-2022a/lib64/R/library. You can list all files in this dir to see the packages installed with this version of R.

To use this version of R, please first load the module with

module load R/4.3.1-foss-2022a


R version 4.2.1

R version 4.2.1 is installed in /apps/eb/R/4.2.1-foss-2022a and add-on packages are installed in /apps/eb/R/4.2.1-foss-2022a/lib64/R/library. You can list all files in this dir to see the packages installed with this version of R.

To use this version of R, please first load the module with

module load R/4.2.1-foss-2022a


R version 4.1.2

R version 4.1.2 is installed in /apps/eb/R/4.1.2-foss-2021b and add-on packages are installed in /apps/eb/R/4.1.2-foss-2021b/lib64/R/library. You can list all files in this dir to see the packages installed with this version of R.

To use this version of R, please first load the module with

module load R/4.1.2-foss-2021b

Please note that when you load this R module, many other modules will be loaded as R depends on those other libraries and packages.


A number of R packages are provided by other module files. For example, many packages that depend on the JAGS library, such as rjags, are provided by the rjags/4-12-foss-2022a-R-4.3.1 module, which can be loaded with

module load rjags/4-12-foss-2022a-R-4.3.1


How to run R programs with multithreads

Some functions in the R packages are written with OpenMP and can run in parallel using multithreads. The R module files set the variable OMP_NUM_THREADS=1, to specify using only one thread. If you are using a function in an R package that is enabled to run with multithreads, please set the OMP_NUM_THREADS variable to the number of threads you want to use and request the same number of cores for your job. Note that you would need to set this variable after you load the R module, for it to have effect. For example, to use 6 threads, request 6 cores on the same node with

#SBATCH --ntasks=1
#SBATCH --cpus-per-task=6

and set

export OMP_NUM_THREADS=6

You can set OMP_NUM_THREADS to automatically correspond to the number of cores per task requested for the job, by setting it to $SLURM_CPUS_PER_TASK, with

export OMP_NUM_THREADS=$SLURM_CPUS_PER_TASK

A sample job submission to run a multithread job is provided below.


Sample Job Submission Scripts

Here is an example of a shell script, sub.sh, to run a serial R script on the batch queue:

#!/bin/bash
#SBATCH --job-name=testRjob
#SBATCH --partition=batch        
#SBATCH --ntasks=1
#SBATCH --mem=10gb   
#SBATCH --time=08:00:00   
#SBATCH --output=%x.%j.out
#SBATCH --error=%x.%j.err
 
cd $SLURM_SUBMIT_DIR

module load R/4.3.1-foss-2022a   

R CMD BATCH program.R   

where program.R is just a sample program name and needs to be replaced by the name of the program you wish to run. The settings in the header lines, such as the job name, the email address, the number of cores, memory and walltime limit, need to be changed appropriately as well.


Here is an example of a shell script, sub.sh, to run a multithread R script on the batch queue:

#!/bin/bash
#SBATCH --job-name=testRjob
#SBATCH --partition=batch        
#SBATCH --ntasks=1
#SBATCH --cpus-per-task=6
#SBATCH --mem=10gb   
#SBATCH --time=08:00:00   
#SBATCH --output=%x.%j.out
#SBATCH --error=%x.%j.err
 
cd $SLURM_SUBMIT_DIR

module load R/4.3.1-foss-2022a  

export OMP_NUM_THREADS=$SLURM_CPUS_PER_TASK

R CMD BATCH program.R   

where program.R is just a sample program name and needs to be replaced by the name of the program you wish to run. The settings in the header lines, such as the job name, the email address, the number of cores, memory and walltime limit, need to be changed appropriately as well.


Here is an example of job submission command:

sbatch ./sub.sh 

Documentation

Please see http://www.r-project.org/

Installation

Source code downloaded from https://www.r-project.org/

System

64-bit Linux