Install GSL: Difference between revisions
| (30 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
(guide written by Alfredo Correa) |
|||
The installation of the [http://www.gnu.org/software/gsl/ GNU Scientific Library] is very simple and it worth using it for solving many simple numerical problems. The [http://www.gnu.org/software/gsl/manual/html_node/ manual] is very complete and easy to understand. It can also be useful to learn about the methods. |
The installation of the [http://www.gnu.org/software/gsl/ GNU Scientific Library] is very simple and it worth using it for solving many simple numerical problems. The [http://www.gnu.org/software/gsl/manual/html_node/ manual] is very complete and easy to understand. It can also be useful to learn about the methods. |
||
| Line 9: | Line 11: | ||
VERSION=1.15 |
VERSION=1.15 |
||
wget |
wget http://ftp.gnu.org/gnu/gsl/gsl-$VERSION.tar.gz |
||
tar -zxvf gsl-$VERSION.tar.gz |
tar -zxvf gsl-$VERSION.tar.gz |
||
cd gsl-$VERSION |
cd gsl-$VERSION |
||
| Line 15: | Line 17: | ||
=== Version Control === |
=== Version Control === |
||
| ⚫ | |||
(no working) |
|||
| ⚫ | |||
(it is important to have texinfo otherwise the installation can fail and leave it not complete) |
|||
| ⚫ | |||
| ⚫ | |||
then |
then |
||
mkdir -p ~/soft |
|||
cd ~/soft |
|||
| ⚫ | |||
cd |
cd gsl.bzr |
||
| ⚫ | |||
autoreconf -i -f -v |
|||
cd trunk |
|||
grep PACKAGE_VERSION= configure |
|||
./autogen.sh |
|||
grep GSL_VERSION gsl_version.h |
|||
=== Compile === |
=== Compile === |
||
./configure --prefix=$HOME/usr CFLAGS="-fexceptions" --enable-maintainer-mode |
./configure --prefix=$HOME/usr --exec-prefix=$HOME/usr`uname -m` CFLAGS="-fexceptions" --enable-maintainer-mode |
||
time make --jobs 1 |
time make --jobs 1 |
||
make check |
|||
make install |
|||
(3 minutes) |
|||
to remove: |
to remove: |
||
| Line 87: | Line 91: | ||
This library overlaps with [http://www.gnu.org/software/gsl/manual/html_node/Multidimensional-Minimization.html GSL Multidimensional Minimization], although it provides more optimization options (including global search methods), such as equality and inequality constrains of arbitrary forms and several algorithms. |
This library overlaps with [http://www.gnu.org/software/gsl/manual/html_node/Multidimensional-Minimization.html GSL Multidimensional Minimization], although it provides more optimization options (including global search methods), such as equality and inequality constrains of arbitrary forms and several algorithms. |
||
VERSION=2.4.1 # last version can be found [http://ab-initio.mit.edu/wiki/index.php/NLopt#Download_and_installation here] |
|||
| ⚫ | |||
mkdir -p ~/soft |
mkdir -p ~/soft |
||
cd ~/soft |
cd ~/soft |
||
wget http://ab-initio.mit.edu/nlopt/nlopt-$VERSION.tar.gz |
wget -S -N http://ab-initio.mit.edu/nlopt/nlopt-$VERSION.tar.gz |
||
tar -zxvf nlopt-$VERSION.tar.gz |
tar -zxvf nlopt-$VERSION.tar.gz |
||
cd nlopt-$VERSION |
cd nlopt-$VERSION |
||
./configure --prefix=$HOME/usr |
./configure --prefix=$HOME/usr --with-cxx --enable-shared --without-octave --without-guile |
||
time make install |
time make install |
||
| Line 99: | Line 103: | ||
To remove NLOpt: |
To remove NLOpt: |
||
rm -rf ~/usr/include/nlop.* ~/usr/lib |
rm -rf ~/usr/include/nlop.* ~/usr`uname -m`/lib/libnlopt* |
||
= Install gnuplot = |
|||
The interface can benefit from having readline installed in the system, for example |
|||
sudo apt-get install libreadline-dev |
|||
then |
|||
| ⚫ | |||
wget http://downloads.sourceforge.net/project/gnuplot/gnuplot/$VERSION/gnuplot-$VERSION.tar.gz |
|||
tar -zxvf gnuplot-$VERSION |
|||
./configure --prefix=$HOME/usr --exec-prefix=$HOME/usr`uname -m` --with-readline=gnu |
|||
make |
|||
make check |
|||
make install |
|||
(1 minute) |
|||
to remove gnuplot |
|||
rm -rf ~/usr/share/gnuplot ~/usr`uname -m`/bin/gnuplot |
|||
Latest revision as of 18:53, 3 February 2014
(guide written by Alfredo Correa)
The installation of the GNU Scientific Library is very simple and it worth using it for solving many simple numerical problems. The manual is very complete and easy to understand. It can also be useful to learn about the methods.
Installation
mkdir ~/soft cd ~/soft
Direct Download
VERSION=1.15 wget http://ftp.gnu.org/gnu/gsl/gsl-$VERSION.tar.gz tar -zxvf gsl-$VERSION.tar.gz cd gsl-$VERSION
Version Control
GSL development team uses Bazaar as version control system. First check that you have GNU Autotools and other building blocks installed; for example
sudo apt-get install autoconf automake libtool texinfo bzr
(it is important to have texinfo otherwise the installation can fail and leave it not complete)
then
mkdir -p ~/soft cd ~/soft bzr branch http://bzr.savannah.gnu.org/r/gsl/trunk gsl.bzr cd gsl.bzr autoreconf -i -f -v grep PACKAGE_VERSION= configure
Compile
./configure --prefix=$HOME/usr --exec-prefix=$HOME/usr`uname -m` CFLAGS="-fexceptions" --enable-maintainer-mode time make --jobs 1 make check make install
(3 minutes)
to remove:
rm -rf ~/usr/include/gsl rm -rf ~/usr/lib/libgsl*
C++ Exceptions
The only subtle point on the compilation step is that we need to activate "-fexceptions" if we want to use C++ exceptions with GSL. GSL is written in and for plain C, without C++ exceptions in mind. Although it can be used from C++ natively. By default, most error reports are done by returning an status value or function pointer error handlers and not by exceptions. If -fexceptions flag not active during compilation any error function called from GSL that throws exceptions won't be catched in a try/catch block.
Once -fexceptions is active in GSL binaries, C++ code can convert usual abort/errors into nice C++ exceptions:
#include<gsl/gsl_errno.h>
#include<string>
#include<boost/lexical_cast.hpp>
#include<stdexcept>
#include<cassert>
namespace gsl{namespace error{
struct exception : std::runtime_error{
int const code_;
exception(std::string const& c, int gsl_errno) : std::runtime_error(c), code_(gsl_errno){}
int code() const{return code_;}
};
void handler(const char * reason, const char * file, int line, int gsl_errno){
throw exception(
std::string(reason)
+ " at " + std::string(file) + ":"+boost::lexical_cast<std::string>(line)
+ " error code "+boost::lexical_cast<std::string>(gsl_errno) + ": "
+ std::string(gsl_strerror(gsl_errno)),
gsl_errno
);
}
gsl_error_handler_t* set_handler(void (*a)(const char*, const char*, int, int)){
return gsl_set_error_handler(a);
}
static gsl_error_handler_t* const native = set_handler(&handler);
}}
The rest of the code can be unchanged, the difference being that now abort errors can be handled by catching.
Non GSL
There are several C libraries that follow the design, quality and spirit of GSL. For example
- GLPK - GNU Linear Programming Kit
- FFTW - Large-scale Fast Fourier Transforms
- NLopt - Nonlinear optimization with unconstrained, bound-constrained, and general nonlinear inequality constraints
- Cubature - Multi-dimensional integration
NLopt install
This library overlaps with GSL Multidimensional Minimization, although it provides more optimization options (including global search methods), such as equality and inequality constrains of arbitrary forms and several algorithms.
VERSION=2.4.1 # last version can be found here mkdir -p ~/soft cd ~/soft wget -S -N http://ab-initio.mit.edu/nlopt/nlopt-$VERSION.tar.gz tar -zxvf nlopt-$VERSION.tar.gz cd nlopt-$VERSION ./configure --prefix=$HOME/usr --with-cxx --enable-shared --without-octave --without-guile time make install
(1 min). Notably the library includes a Matlab interface as described in the manual. The manual is located here; the Matlab reference is located here
To remove NLOpt:
rm -rf ~/usr/include/nlop.* ~/usr`uname -m`/lib/libnlopt*
Install gnuplot
The interface can benefit from having readline installed in the system, for example
sudo apt-get install libreadline-dev
then
VERSION=4.4.3 wget http://downloads.sourceforge.net/project/gnuplot/gnuplot/$VERSION/gnuplot-$VERSION.tar.gz tar -zxvf gnuplot-$VERSION ./configure --prefix=$HOME/usr --exec-prefix=$HOME/usr`uname -m` --with-readline=gnu make make check make install
(1 minute)
to remove gnuplot
rm -rf ~/usr/share/gnuplot ~/usr`uname -m`/bin/gnuplot