Skip to content

OpenBLAS

OpenBLAS

OpenBLAS is an optimized Basic Linear Algebra Subprograms (BLAS) library based on GotoBLAS2 1.13 BSD version.

Usage

OpenBLAS module

OpenBLAS has to be loaded using Lmod prior to running it.

$ module load OpenBLAS
You can also search the module with spider
$ module spider OpenBLAS

------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  OpenBLAS:
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    Description:
      OpenBLAS is an optimized BLAS library based on GotoBLAS2 1.13 BSD version.

     Versions:
        OpenBLAS/0.3.15-GCC-10.3.0
        OpenBLAS/0.3.18-GCC-11.2.0
        OpenBLAS/0.3.20-GCC-11.3.0
        OpenBLAS/0.3.21-GCC-12.2.0
        OpenBLAS/0.3.23-GCC-12.3.0

------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  For detailed information about a specific "OpenBLAS" package (including how to load the modules) use the module's full name.
  Note that names that have a trailing (E) are extensions provided by other modules.
  For example:

     $ module spider OpenBLAS/0.3.23-GCC-12.3.0
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Software version

Here you can check the available versions for OpenBLAS in the different clusters

OpenBLAS/0.2.18-GCC-5.4.0-2.26-LAPACK-3.6.1
OpenBLAS/0.2.19-GCC-6.3.0-2.27-LAPACK-3.7.0
OpenBLAS/0.2.20-GCC-6.4.0-2.28
OpenBLAS/0.3.1-GCC-7.3.0-2.30-INTERFACE64
OpenBLAS/0.3.1-GCC-7.3.0-2.30
OpenBLAS/0.3.7-GCC-8.3.0
OpenBLAS/0.3.9-GCC-9.3.0
OpenBLAS/0.3.12-GCC-10.2.0
OpenBLAS/0.3.15-GCC-10.3.0
OpenBLAS/0.3.18-GCC-11.2.0
OpenBLAS/0.3.20-GCC-11.3.0
OpenBLAS/0.3.21-GCC-12.2.0
OpenBLAS/0.3.7-GCC-8.3.0
OpenBLAS/0.3.9-GCC-9.3.0
OpenBLAS/0.3.12-GCC-10.2.0
OpenBLAS/0.3.15-GCC-10.3.0
OpenBLAS/0.3.18-GCC-11.2.0
OpenBLAS/0.3.20-GCC-11.3.0
OpenBLAS/0.3.21-GCC-12.2.0
OpenBLAS/0.3.23-GCC-12.3.0
OpenBLAS/0.3.15-GCC-10.3.0
OpenBLAS/0.3.18-GCC-11.2.0
OpenBLAS/0.3.20-GCC-11.3.0
OpenBLAS/0.3.21-GCC-12.2.0
OpenBLAS/0.3.23-GCC-12.3.0

How to use OpenBLAS

In order to use it, you will need to compile your code against the library.

Let's see how to use it with an example, using the following code:

Example code using OpenBLAS
#include <stdio.h>
#include <stdlib.h>
#include <cblas.h>

void print_matrix(const char* desc, int m, int n, double* a, int lda) {
    int i, j;
    printf("\n %s\n", desc);
    for (i = 0; i < m; i++) {
        for (j = 0; j < n; j++) {
            printf(" %6.2f", a[i*lda+j]);
        }
        printf("\n");
    }
}

int main() {
    int m = 2, n = 3, k = 2;
    double A[4] = {1.0, 2.0, 3.0, 4.0}; // 2x2 matrix
    double B[6] = {5.0, 6.0, 7.0, 8.0, 9.0, 10.0}; // 2x3 matrix
    double C[6] = {0}; // 2x3 result matrix

    // Perform matrix multiplication C = A * B
    cblas_dgemm(CblasRowMajor, CblasNoTrans, CblasNoTrans, m, n, k, 1.0, A, k, B, n, 0.0, C, n);

    print_matrix("Matrix A", m, k, A, k);
    print_matrix("Matrix B", k, n, B, n);
    print_matrix("Resulting Matrix C", m, n, C, n);

    return 0;
}

First, we load the module:

$ module load OpenBLAS/0.3.23-GCC-12.3.0

To compile our code, we will use the following line:

$ gcc -o example example.c -lopenblas

Once compiled, we can execute it using the following submission script:

Batch script for a execution using OpenBLAS
#!/bin/bash
#SBATCH --qos=regular
#SBATCH --job-name=OpenBLAS_JOB
#SBATCH --mem=20gb
#SBATCH --cpus-per-task=1
#SBATCH --nodes=1
#SBATCH --ntasks-per-node=1
#SBATCH --output=%x-%j.out
#SBATCH --error=%x-%j.err

module load OpenBLAS/0.3.23-GCC-12.3.0
srun ./example