| Title: | 'FlexiBLAS' API Interface |
|---|---|
| Description: | Provides functions to switch the 'BLAS'/'LAPACK' optimized backend and change the number of threads without leaving the R session, which needs to be linked against the 'FlexiBLAS' wrapper library <https://www.mpi-magdeburg.mpg.de/projects/flexiblas>. |
| Authors: | Iñaki Ucar [aut, cph, cre] (ORCID: <https://orcid.org/0000-0001-6403-5550>), Martin Koehler [aut, cph] (ORCID: <https://orcid.org/0000-0003-2338-9904>) |
| Maintainer: | Iñaki Ucar <[email protected]> |
| License: | LGPL (>= 3) |
| Version: | 3.4.0.2 |
| Built: | 2026-05-31 08:03:04 UTC |
| Source: | https://github.com/Enchufa2/r-flexiblas |
Provides functions to switch the BLAS/LAPACK optimized backend and change the number of threads without leaving the R session, which needs to be linked against the FlexiBLAS wrapper library.
Martin Koehler, Iñaki Ucar
Koehler M., Saak J. (2020). "FlexiBLAS - A BLAS and LAPACK wrapper library with runtime exchangeable backends." doi:10.5281/zenodo.3909214.
Check whether FlexiBLAS is available.
flexiblas_avail()flexiblas_avail()
A boolean.
flexiblas_version, flexiblas-backends, flexiblas-threads
Get current version of FlexiBLAS.
flexiblas_version()flexiblas_version()
A package_version object.
flexiblas_avail, flexiblas-backends, flexiblas-threads
Get current backend, list available ones, load and switch between backends.
flexiblas_current_backend() flexiblas_list() flexiblas_list_loaded() flexiblas_load_backend(name) flexiblas_switch(n)flexiblas_current_backend() flexiblas_list() flexiblas_list_loaded() flexiblas_load_backend(name) flexiblas_switch(n)
name |
character vector of backend names or paths (case insensitive). |
n |
loaded backend index. |
flexiblas_current_backend and flexiblas_list* return a character
vector of backend names or paths.
flexiblas_load_backend and flexiblas_switch return the indices of
the loaded backends if the operation was successful, or fail otherwise.
flexiblas_avail, flexiblas_version, flexiblas-threads
n <- 2000 runs <- 10 ignore <- "__FALLBACK__" A <- matrix(runif(n*n), nrow=n) B <- matrix(runif(n*n), nrow=n) # load backends backends <- setdiff(flexiblas_list(), ignore) idx <- flexiblas_load_backend(backends) # benchmark timings <- sapply(idx, function(i) { flexiblas_switch(i) # warm-up C <- A[1:100, 1:100] %*% B[1:100, 1:100] unname(system.time({ for (j in seq_len(runs)) C <- A %*% B })[3]) }) if (length(timings)) { results <- data.frame( backend = backends, `timing [s]` = timings, `performance [GFlops]` = (2 * (n / 1000)^3) / timings, check.names = FALSE) results[order(results$performance),] }n <- 2000 runs <- 10 ignore <- "__FALLBACK__" A <- matrix(runif(n*n), nrow=n) B <- matrix(runif(n*n), nrow=n) # load backends backends <- setdiff(flexiblas_list(), ignore) idx <- flexiblas_load_backend(backends) # benchmark timings <- sapply(idx, function(i) { flexiblas_switch(i) # warm-up C <- A[1:100, 1:100] %*% B[1:100, 1:100] unname(system.time({ for (j in seq_len(runs)) C <- A %*% B })[3]) }) if (length(timings)) { results <- data.frame( backend = backends, `timing [s]` = timings, `performance [GFlops]` = (2 * (n / 1000)^3) / timings, check.names = FALSE) results[order(results$performance),] }
Get or set the number of threads for the BLAS backend.
flexiblas_get_num_threads() flexiblas_set_num_threads(n)flexiblas_get_num_threads() flexiblas_set_num_threads(n)
n |
number of threads. |
flexiblas_get_num_threads returns the number of threads.
flexiblas_set_num_threads returns nothing.
flexiblas_avail, flexiblas_version, flexiblas-backends
max_threads <- 4 n <- 2000 runs <- 10 A <- matrix(runif(n*n), nrow=n) B <- matrix(runif(n*n), nrow=n) for (i in seq_len(max_threads)) { message("Set number of threads to: ", i) flexiblas_set_num_threads(i) print(system.time({ for (j in seq_len(runs)) C <- A %*% B })) }max_threads <- 4 n <- 2000 runs <- 10 A <- matrix(runif(n*n), nrow=n) B <- matrix(runif(n*n), nrow=n) for (i in seq_len(max_threads)) { message("Set number of threads to: ", i) flexiblas_set_num_threads(i) print(system.time({ for (j in seq_len(runs)) C <- A %*% B })) }