Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
habrok:examples:r [2023/03/22 13:28] – fokke | 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 46: | 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 81: | Line 81: | ||
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 126: | 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 142: | 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 167: | Line 168: | ||
Within this session, installing '' | Within this session, installing '' | ||
- | < | + | < |
library(devtools) | library(devtools) | ||
install_github(" | install_github(" | ||
Line 189: | 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 |