Loading 2026-01-28_R-on-bwUC3/Rcode/OpenBLAS-multithreading.R 0 → 100644 +40 −0 Original line number Diff line number Diff line #OpenBLAS-multithreading.R # This example illustrates the benefit of multi-threading in the context # matrix operations (OpenBLAS). library(RhpcBLASctl) ## controls number of threads from within R set.seed(2026) X <- matrix(rnorm(5000^2), 5000) # No multi-threading blas_set_num_threads(1) cat("Compute time for single-threaded OpenBLAS\n") stime <- system.time({ Xinv <- solve(X) })[3] print(stime) # Two threads blas_set_num_threads(2) cat("Compute time for OpenBLAS with two threads\n") system.time({ Xinv <- solve(X) })[3] # Four threads blas_set_num_threads(4) cat("Compute time for OpenBLAS with four threads\n") ptime <- system.time({ Xinv <- solve(X) })[3] print(ptime) cat(sprintf('Speed up for %d threads: %f\n', blas_get_num_procs(), round(stime / ptime, digits=2))) 2026-01-28_R-on-bwUC3/Rcode/OpenBLAS-multithreading.slurm 0 → 100644 +19 −0 Original line number Diff line number Diff line #!/bin/bash # #SBATCH --job-name=r-openblas-multithreading #SBATCH --comment="Multi-threading with OpenBLAS." #SBATCH --partition=dev_cpu #SBATCH --nodes=1 #SBATCH --tasks-per-node=4 #SBATCH --mem-per-cpu=1G #SBATCH --time=00:05:00 # Make sure to specify the version module purge module load math/R/4.5.1 # Change to submission directory of this job (not needed) cd "$SLURM_SUBMIT_DIR" # Start program R CMD BATCH --no-save --no-restore --slave OpenBLAS-multithreading.R Loading
2026-01-28_R-on-bwUC3/Rcode/OpenBLAS-multithreading.R 0 → 100644 +40 −0 Original line number Diff line number Diff line #OpenBLAS-multithreading.R # This example illustrates the benefit of multi-threading in the context # matrix operations (OpenBLAS). library(RhpcBLASctl) ## controls number of threads from within R set.seed(2026) X <- matrix(rnorm(5000^2), 5000) # No multi-threading blas_set_num_threads(1) cat("Compute time for single-threaded OpenBLAS\n") stime <- system.time({ Xinv <- solve(X) })[3] print(stime) # Two threads blas_set_num_threads(2) cat("Compute time for OpenBLAS with two threads\n") system.time({ Xinv <- solve(X) })[3] # Four threads blas_set_num_threads(4) cat("Compute time for OpenBLAS with four threads\n") ptime <- system.time({ Xinv <- solve(X) })[3] print(ptime) cat(sprintf('Speed up for %d threads: %f\n', blas_get_num_procs(), round(stime / ptime, digits=2)))
2026-01-28_R-on-bwUC3/Rcode/OpenBLAS-multithreading.slurm 0 → 100644 +19 −0 Original line number Diff line number Diff line #!/bin/bash # #SBATCH --job-name=r-openblas-multithreading #SBATCH --comment="Multi-threading with OpenBLAS." #SBATCH --partition=dev_cpu #SBATCH --nodes=1 #SBATCH --tasks-per-node=4 #SBATCH --mem-per-cpu=1G #SBATCH --time=00:05:00 # Make sure to specify the version module purge module load math/R/4.5.1 # Change to submission directory of this job (not needed) cd "$SLURM_SUBMIT_DIR" # Start program R CMD BATCH --no-save --no-restore --slave OpenBLAS-multithreading.R