ITS/High Performance Computing Cluster/help on GSL

Contents

[edit] GSL on the ITS HPC Cluster

The GNU Scientific Library (GSL) is a numerical library for C and C++ programmers. It is free software under the GNU General Public License. The library provides a wide range of mathematical routines such as random number generators, special functions and least-squares fitting. There are over 1000 functions in total. Version GSL-1.10, released on 15 September 2007, is available on the ITS HPC cluster. GSL functions are available in the following areas:

Complex Numbers Roots of Polynomials Special Functions
Vectors and Matrices Permutations Sorting
BLAS Support Linear Algebra Eigensystems
Fast Fourier Transforms Quadrature Random Numbers
Quasi-Random Sequences Random Distributions Statistics
Histograms N-Tuples Monte Carlo Integration
Simulated Annealing Differential Equations Interpolation
Numerical Differentiation Chebyshev Approximation Series Acceleration
Discrete Hankel Transforms Root-Finding Minimization
Least-Squares Fitting Physical Constants IEEE Floating-Point
Discrete Wavelet Transforms

Unlike the licenses of proprietary numerical libraries the license of GSL does not restrict scientific cooperation. It allows you to share your programs freely with others.

[edit] Sample Program

The following short program demonstrates the use of the library by computing the value of the Bessel function J_0(x) for x=5,

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

int main(void)
{
  double x = 5.0;
  double y = gsl_sf_bessel_J0 (x);

  printf ("J0(%g) = %.18e\n", x, y);
  return 0;
}

The output is shown below, and should be correct to double-precision accuracy,

J0(5) = -1.775967713143382920e-01

The header files for GSL are installed in their own 'gsl' directory. You should consult the GSL documentation to determine the required header file to use with each GSL function, and then write any preprocessor include statements with a 'gsl/' directory prefix thus:

#include <gsl/gsl_math.h>

[edit] Compiling and Linking

A typical compilation command for a source file 'example.c' with the GNU C compiler gcc is

$ gcc -Wall -c example.c

This produces an object file 'example.o'.

[edit] Linking Programs With The Library

The library is installed in '/usr/local/lib' as a single file, 'libgsl.a', and a shared version of the library, 'libgsl.so', is also installed. To link against the library you need to specify both the main library and a supporting CBLAS library, which provides standard basic linear algebra subroutines. A suitable CBLAS implementation is provided in the library 'libgslcblas.a' if your system does not provide one. The following example shows how to link an application with the library:

$ gcc example.o -lgsl -lgslcblas -lm

[edit] Linking With An Alternative BLAS Library

The following command line shows how you would link the same application with an alternative CBLAS library called 'libcblas':

$ gcc example.o -lgsl -lcblas -lm

For the best performance, an optimized platform-specific CBLAS library should be used for -lcblas. The library must conform to the CBLAS standard. The ATLAS package provides a portable high-performance BLAS library with a CBLAS interface. It is free software and may be installed for any work requiring fast vector and matrix operations. The following command line will link with the ATLAS library and its CBLAS interface,

$ gcc example.o -lgsl -lcblas -latlas -lm

[edit] Shared Libraries

To run a program linked with the shared version of the library the operating system must be able to locate the corresponding '.so' file at runtime. If the library cannot be found, the following error will occur:

$ ./a.out 
./a.out: error while loading shared libraries: 
libgsl.so.0: cannot open shared object file: No such 
file or directory

To avoid this error, define the shell variable LD_LIBRARY_PATH to include the directory where the library is installed.

For example, in the Bourne shell (/bin/sh or /bin/bash), the library search path can be set with the following commands:

$ LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH 
$ export LD_LIBRARY_PATH
$ ./example

In the C-shell (/bin/csh or /bin/tcsh) the equivalent command is,

% setenv LD_LIBRARY_PATH /usr/local/lib:$LD_LIBRARY_PATH

The standard prompt for the C-shell in the example above is the percent character '%', and should not be typed as part of the command.

To save retyping these commands each session they may be placed in an individual or system-wide login file.

To compile a statically linked version of the program, use the -static flag in gcc,

$ gcc -static example.o -lgsl -lgslcblas -lm


This article is a stub. You can help by adding to it.

ITS High Performance Cluster Articles
This article is part of the ITS Cluster series of articles
FAQ | Intel compilers | GNU compilers | Portland Group compilers
Intel Math Kernel Library | MINPACK | ScaLAPACK | GSL | FFTW3 | MPICH | NAG
R | Mathematica | NAMD | GROMACS | Amber | MATLAB
FLUENT | GAMESS | Gaussian | MOLCAS | LAMMPS | APBS

Case Referrers

Other Sites
This page has been accessed 6,030 times.
This page was last modified 17:30, January 30, 2008 by Roger Bielefeld.
About | Disclaimers