GNU Scientific Library (GSL)

General Information

Home page Versions Module dependencies
Compiler
www.gnu.org/software/gsl 2.1 GCC/4.9.3-2.25
2.3 GCC/5.4.0-2.26
2.3 GCC/6.3.0-2.27

The GNU Scientific Library (GSL) is a free numerical software package for C and C++ covering a range of subject areas including:

  • BLAS (level 1, 2, and 3) and linear algebra routines
  • Fast Fourier transform (FFT) functions
  • Numerical integration
  • Random number generation function

Usage on Idun

Load one of the GSL and the corresponding GCC modules to use the GSL library on Idun, e.g.:

$ module load GCC/5.4.0-2.26 GSL/2.3

The library header files are installed in a subdirectory gsl of the main installation directory that must prefix preprocessing include statements, see e.g. the example program blas_test.c below. The header files define functions to have extern "C" linkage when included in C++ programs allowing functions to be called directly from C++. The GSL library is available in both shared and static versions.

Example program

blas_test.c

/*  blas_test.c : Example using BLAS matrix multiply code sgemm */

#include <stdio.h>
#include <gsl/gsl_cblas.h>

int main(void)
{
  const int lda=3, ldb=3, ldc=3;
  int m, n, k;
  float alpha, beta;

  float a[] = { 0.11, 0.21, 0.12,
                0.15, 0.13, 0.17,
                0.22, 0.13, 0.23 };

  float b[] = { 1011, 1021, 1018,
                1031, 1012, 1021,
                1022, 1032, 1015 };

  float c[] = { 0.00, 0.00, 0,00,
                0.00, 0.00, 0,00,
                0.00, 0.00, 0,00 };

  m = 3; n = 3; k = 3;

  alpha = 1.0; beta = 0.0;

  cblas_sgemm (CblasColMajor, CblasNoTrans, CblasNoTrans,
                m, n, k, alpha, a, lda, b, ldb, beta, c, ldc);

  printf ("[ %g, %g, %g\n", c[0], c[1], c[2]);
  printf ("  %g, %g, %g\n", c[3], c[4], c[5]);
  printf ("  %g, %g, %g ]\n", c[6], c[7], c[8]);

  return 0;
}

Compile and link the program using the GCC compiler, adding:

$ gcc blas_test.c -lgsl -lgslcblas

Further Information

  • GSL Reference Manual (HTML / PDF)
Scroll to Top