Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
habrok:examples:r [2021/03/02 12:44] – external edit 127.0.0.1 | habrok:examples:r [2025/06/11 12:15] (current) – [Multiple CPUs] lint pedro | ||
---|---|---|---|
Line 7: | Line 7: | ||
In order to run a simple R script on one core, two files should be constructed. The first file is the R script (with the .R extension), here it is called '' | In order to run a simple R script on one core, two files should be constructed. The first file is the R script (with the .R extension), here it is called '' | ||
- | < | + | < |
# Simple t-test between two equally large groups. | # Simple t-test between two equally large groups. | ||
# Let us generate some data. | # Let us generate some data. | ||
- | apples <- rnorm(20, | + | apples <- rnorm(20, mean = 1.5, sd = .1) |
- | pears <- rnorm(20, | + | pears <- rnorm(20, mean = 1.6, sd = .1) |
- | print(t.test(pears, | + | print(t.test(pears, |
</ | </ | ||
Line 26: | Line 26: | ||
#SBATCH --mem=1000 | #SBATCH --mem=1000 | ||
- | ml R/3.4.4-foss-2018a-X11-20180131 | + | module purge |
+ | module load R/4.2.1-foss-2022a | ||
Rscript R_example1.R | Rscript R_example1.R | ||
</ | </ | ||
Line 45: | Line 46: | ||
The final output should look like: | The final output should look like: | ||
- | < | + | < |
Welch Two Sample t-test | Welch Two Sample t-test | ||
Line 72: | Line 73: | ||
#SBATCH --mem=10GB | #SBATCH --mem=10GB | ||
- | module load R/3.4.4-foss-2018a-X11-20180131 | + | module purge |
+ | module load R/4.2.1-foss-2022a | ||
Rscript parallel.R | Rscript parallel.R | ||
</ | </ | ||
- | The file containing the R code is named '' | + | The file containing the R code is named '' |
- | < | + | < |
library(" | library(" | ||
library(" | library(" | ||
cpu <- Sys.getenv(" | cpu <- Sys.getenv(" | ||
- | hosts <- rep(" | + | hosts <- rep(" |
cl <- makeCluster(hosts, | cl <- makeCluster(hosts, | ||
# Create random matrices. | # Create random matrices. | ||
n <- 5000 | n <- 5000 | ||
- | A <- matrix(rnorm(n^2), | + | A <- matrix(rnorm(n^2), |
- | B <- matrix(rnorm(n^2), | + | B <- matrix(rnorm(n^2), |
# Single core time of matrix multiplication of matrices | # Single core time of matrix multiplication of matrices | ||
Line 124: | Line 126: | ||
In order to use multiple nodes with R, you can make use of an MPI cluster in your R code. Due to the way our MPI libraries are installed, it's not possible to use the makeCluster or makeMPIcluster or makeCluster, | In order to use multiple nodes with R, you can make use of an MPI cluster in your R code. Due to the way our MPI libraries are installed, it's not possible to use the makeCluster or makeMPIcluster or makeCluster, | ||
- | < | + | < |
library(" | library(" | ||
library(" | library(" | ||
Line 140: | Line 142: | ||
#SBATCH --mem=10GB | #SBATCH --mem=10GB | ||
- | module load R/3.4.4-foss-2018a-X11-20180131 | + | module purge |
+ | module load R/4.2.1-foss-2022a | ||
srun ${EBROOTR}/ | srun ${EBROOTR}/ | ||
Line 147: | Line 150: | ||
==== GPU ==== | ==== GPU ==== | ||
- | In order to let R use the GPUs of the Peregrine | + | In order to let R use the GPUs of the Hábrók |
<code bash> | <code bash> | ||
srun --time=00: | srun --time=00: | ||
Line 165: | Line 168: | ||
Within this session, installing '' | Within this session, installing '' | ||
- | < | + | < |
library(devtools) | library(devtools) | ||
install_github(" | install_github(" | ||
Line 187: | Line 190: | ||
In this example we use a R script that does a simple GPU matrix multiplication and a normal CPU matrix multiplication. | In this example we use a R script that does a simple GPU matrix multiplication and a normal CPU matrix multiplication. | ||
- | < | + | < |
library(" | library(" | ||
ORDER = 10000 | ORDER = 10000 | ||
Line 205: | Line 208: | ||
Now we can submit the job using '' | Now we can submit the job using '' | ||
In this example the matrix multiplication is slower for the GPU when small matrices are used (100x100); however, as the matrix gets larger, the GPU speed will scale better as can be seen from the output. | In this example the matrix multiplication is slower for the GPU when small matrices are used (100x100); however, as the matrix gets larger, the GPU speed will scale better as can be seen from the output. | ||
+ | |||
+ | ===== Installing additional R libraries ===== | ||
+ | |||
+ | R provides the '' | ||
+ | |||
+ | * log in and load the R module that you would like to use, e.g.: '' | ||
+ | * launch R by running the command: '' | ||
+ | * run the appropriate '' | ||
+ | * quit using '' | ||
+ | |||
+ | Now the packages will be available for any job that you run. Note that you do have to do this again once you switch to a completely different R version. | ||
+ | |||
+ | ==== Login node limits ==== | ||
+ | |||
+ | Note that if you are trying to install something on the login node, you may run into certain limits that prevent you from using too much memory on the login node. See [[: | ||
===== Useful packages ===== | ===== Useful packages ===== | ||
- | One of our Peregrine | + | One of our users has developed an R package to send function calls as jobs on Slurm via SSH. You can find the documentation and installation instructions on [[https:// |