Skip to content

GSL - GNU Scientific Library

GSL is an open-source numerical library, primarily for C and C++ use

The GSL library is available as a module on Apocrita. The library contains a wide variety of numerical routines including statistical, root finding, random numbers and sorting routines.

Using GSL

Compiling using GSL

GSL provides library objects and header files, along with a utility program to show the configuration of the installed library. On Apocrita GSL is provided both with and without an included CBLAS implementation.

To use a GSL routine in a C program it is necessary to use the appropriate header file when compiling and to link against the library. The header file will be named like gsl/gsl_category.h where category is the topic of the required functions. For example, to use the function gsl_sf_zeta_int to calculate the Riemann zeta function:

#include <stdio.h>
#include "gsl/gsl_sf_zeta.h"
int main (int argc, char *argv[]) {
  printf("zeta for n=2: %17.16f\n", gsl_sf_zeta_int(2));
  return 0;
}

The required header file is given in the documentation for the function.

GSL installations on Apocrita support using pkg-config and gsl-config to indicate the compile and link options to pass to the compiler when building code against GSL. For example, the output may look like:

$ module load gsl
$ gsl-config --cflags
-I<gsl_path>/include
$ gsl-config --libs
-L<gsl_path>/lib -lgsl -lgslcblas -lm
$ gsl-config --libs-without-cblas
-L<gsl_path>/lib -lgsl -lm

We recommend using gsl-config to ensure that all library dependencies and compilation flags are captured.

To put these values on the compilation command line one can use command substitution:

gcc my_gsl_using_program.c $(gsl-config --cflags --libs)

Using GSL with other programming languages

Although GSL is provided with a C programming interface compatible with C++, it is possible to use the library from other programming languages. Repositories for languages such as Python and R often include packages with interfaces for GSL and in Fortran the C API may be used either directly using the standard C interoperability features or indirectly using third-party libraries.

Interfacing libraries and packages are not currently installed system-wide on Apocrita.

Documentation

Reference