Difference between revisions of "GNU Scientific Library (GSL)"

From bwHPC Wiki
Jump to: navigation, search
Line 39: Line 39:
 
Create source code file 'intro.c':
 
Create source code file 'intro.c':
   
{| style="width: 100%; border:1px solid #d0cfcc; background:#f2f7ff;border-spacing: 2px;"
 
| style="width:280px; text-align:center; white-space:nowrap; color:#000;" |
 
 
<source lang="c">
 
<source lang="c">
 
#include <stdio.h>
 
#include <stdio.h>
Line 53: Line 51:
 
}
 
}
 
</source>
 
</source>
|}
 
   
 
Load the gsl module for the Intel compiler, compile, link and run the program:
 
Load the gsl module for the Intel compiler, compile, link and run the program:

Revision as of 19:49, 2 September 2015

The GNU Scientific Library (or GSL) is a software library for numerical computations in applied mathematics and science. The GSL is written in the C programming language, but bindings exist for other languages as well.

Online-Documentation: http://www.gnu.org/software/gsl/

Local-Documentation:

See 'info gsl', 'man gsl' and 'man gsl-config'.

Tips for compiling and linking:

Load the gsl module. After having loaded the gsl environment module, you can use several environment variables to compile and link your application with the gsl library.

Your source code should contain preprocessor include statements with a gsl/ prefix, such as

 #include <gsl/gsl_math.h>

A typical compilation command for a source file example.c with the Intel C compiler icc is

 $ icc -Wall -I$GSL_INC_DIR  -c example.c 

The $GSL_INC_DIR environment variable points to location of the include path for the gsl header files.

The following command can be used to link the application with the gsl libraries,

 $ icc -L$GSL_LIB_DIR -o example example.o -lgsl -lgslcblas -lm 

The $GSL_LIB_DIR environment variable points to the location of the gsl libraries.

Also make sure to have the gsl module loaded before running applications build with this library.

Example

Create source code file 'intro.c':

#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;
}

Load the gsl module for the Intel compiler, compile, link and run the program:

$ module load numlib/gsl/1.16-intel-13.1
Loading module dependency 'compiler/intel/13.1'.
$ icc -Wall -I$GSL_INC_DIR  -c intro.c
$ icc -L$GSL_LIB_DIR -o intro intro.o -lgsl -lgslcblas -lm
$ ./intro
J0(5) = -1.775967713143382642e-01