Solving (dense) linear system Ax=b using boost - c++

I have a dense system of equations of type Ax=b to solve in my C++ program, and I was hoping to implement the solution using UBLAS in boost. In some other questions I found that people were using the extension LAPACK, but unfortunately it doesn't seem to be part of my standard boost installation (in Debian at least) and I am not allowed to add more dependencies.
Could someone paste a solution that doesn't use LAPACK or any other libraries?

Unfortunately, you're solving a linear system which either requires LAPACK or writing your own code. If you don't want LAPACK, your only other option is to write your own solver. Such a solver can use uBLAS of course.
If you need the code to do it, you can look at numerical recipes for an example. But, solving dense linear systems is a very rich subject, so it's probably beyond the scope here to address all aspects of it.

Related

C++ AMP suitable matrix library for inversion, QR decomposition

I require a matrix library for C++ AMP that is able to perform basic operations as well as matrix inversion for arbitrarily sized matrices and QR decomposition.
I initially found that there is a BLAS AMP implementation, however I could not find anywhere that stated whether or not BLAS can perform matrix inversion, can anyone enlighten me about its capabilities and/or suggest a more suitable parallel matrix library for AMP? Thanks!
edit: I found a LAPACK AMP library which is capable of matrix inversion (I think), however it's still in development :(
As far as I know, your best bet is the LAPACK library that you already linked to. C++ AMP is still fairly new and doesn't seem to have a large uptake in scientific computing so far.
There are also some other C++ AMP libraries in development that may be of interest to you.
Algorithms
BLAS
FFT
Random Number Generation
Generic Kernels
I have not been able to find any LAPACK libraries for C++ AMP. However, there are some available for OpenCL.
Specifically clMAGMA from the University of Tennessee.
http://icl.cs.utk.edu/magma/software/view.html?id=152
You will need the AMD OpenCL BLAS library to sit under the LAPACK from here:
http://developer.amd.com/tools-and-sdks/heterogeneous-computing/amd-accelerated-parallel-processing-math-libraries/
I think this is your only bet at inverting a matrix with open source libraries on your GPU. Being openCL, this will be platform agnostic (like C++ AMP), unlike CUDA.
-Matt Musto
www.mustotechnologies.com

Libraries for parallel distributed cholesky decomposition in c/c++ in mpi environment?

What libraries are available for parallel distributed cholesky decomposition of dense matrices in C/C++ in mpi environment?
I've found the ScaLAPACK library, and this might be the solution I'm looking for. It seems that it's a bit fiddly to call though, lots of Fortran <-> C conversions to do, which makes me think that maybe it is not widely used, and therefore maybe there are some other libraries that are used instead?
Alternatively, are there some wrappers for ScaLAPACK that make it relatively not too painful to use in a C or C++ environment, when one is already using MPI, and MPI has already been initialized in the program?
Are these dense or sparse matrices?
Trilinos is a huge library for parallel scientific computation. The sub-package Amesos can link to Scalapack for parallel, direct solution of dense systems and to UMFPACK, SuperLU or MUMPS for sparse systems. Trilinos is mostly in C++, but there are Python bindings if that's your taste. It might be overkill, but it'll get the job done.
Intel MKL might also be a choice, since it calls ScaLAPACK on the inside. Note that Intel supports student use of this library, but in this case you have to use an open source MPI version. Also the Intel forum is very helpful.
Elemental is also an option, written in C++, which is surely a big advantage when you want to integrate with your C/C++ application and the project leader, Jack Poulson is a very friendly and helps a lot.
OpenBLAS, SuperLU and PETSc are also interesting and you may want to read more in my answer.

gmp compatible alternative to gsl

Up to now I've used the GSL Routines to calculate Eigenvalues/vectors and solve ordinary differential equations (ODEs) in C++.
Now I must use the GNU multiple precision library (GMP), but GSL does not support other datatypes than double.
Does anyone know good alternatives for calculating eigenvalues and solving ODEs which are compatible with the GMP Data Type (mpf_class)?
At the moment I'm thinking about to use the routines provided in the Numerical Recipes. Does anyone know if this is a good idea for my tasks?
Best regards
Dominik
Although clearly not the answer you were hoping for, I would think you could take the hard work of modifying the GSL library to make it compatible with the GMP library. Both are open source, so at least for the license there would be no problem and incidentally I think many would be very grateful. Since the problem is only with the type of data, it would be enough to make a sweep through all the code of the GSL library and to replace the routines one by one. It would not be a fast job but it would be a simple job.

is there a c++ library for ordinary differential equation (ODE) solvers?

More specifically, i'm interested in 8th order Dormand-Prince embedded method, it's based on Runge-Kutta, and stiff equations.
I use Numerical Recipes 3 but i often have trouble compiling their libraries. I'd like to know of alternatives.
You can also try odeint. It has the classical Runge-Kutta solvers, Rosenbrock4 for stiff systems and some multi-step method. It is header-only, but you need the boost libraries.
The GNU Scientific Library has several differential equation solvers. They have one that uses Prince-Dormand. It's written in C so you shouldn't have trouble compiling it.

Where to get free math libraries for C/C++

Are there free C/C++ libraries taht do the types of functions that matlab does - something complicated i mean, like discrete laplacian, etc? Is the best option to create some kind of interface in matlab and build my own library?
Thanks
Have you looked at Boost.Math?
http://www.boost.org/doc/libs/1_46_1/libs/math/doc/html/index.html
If you are on windows, there is a very easy to use installer by BoostPro:
http://www.boostpro.com/download/
If you want something that was a matlab clone but free, you could use Octave http://www.gnu.org/software/octave/
I haven't used it in a C++ program, but it apparently has a C++ API:
http://octave.sourceforge.net/doxygen/html/index.html
Depending on what you want to do there are various packages available.
Arbitrary Precision
mostly integers: GMP, MPIR (similar codebases, MPIR has VC builds)
floats: MPFR
complex: MPC
Specialist:
Number Theory: Flint
Linear Algebra: Boost Numeric uBLAS
PDEs: libMesh
Computational Fluid Dynamics: OpenFoam
Graph Theory: Boost Graph
General:
TNT (was LAPACK++ (TNT=do everything, LAPACK++=Linear Alg.)
SciMath (Commercial)
GNU Scientific Library
and that's just a few. I haven't repeated ones others have listed like libpari.
Just in case you're wondering, Maple, Mathematica, Matlab etc all use the GNU MP for their arbitrary precision calculations.
PARI could be a good choice, although I am not familiar with using it:
Official Site for PARI
PARI is a C library, and if you want an independent software, they have PARI-GP there.
Below is the description of PARI on the website above:
PARI/GP is a widely used computer
algebra system designed for fast
computations in number theory
(factorizations, algebraic number
theory, elliptic curves...), but also
contains a large number of other
useful functions to compute with
mathematical entities such as
matrices, polynomials, power series,
algebraic numbers etc., and a lot of
transcendental functions. PARI is also
available as a C library to allow for
faster computations.
Hope this could be useful!
P.S. It is said that Octave functions could be called from C++, and that could be an excellent substitution for MATLAB.
Have a look at armadillo for simplifying your handling of matrices. Then for solving PDEs you'll have to do the job yourself, ie. construct explicitly your Laplacian matrix, and solve it the way you want.
There is Intel MKL too (not free though) which adds some value: iterative solvers (GMRES, BCG) and some black-boxes for solving the Laplacian / Poisson equation on simple domains (cubes and spheres).
I use OpenCV for a lot of image processing and matrix manipulation, which is generally what I use matlab for.
http://opencv.willowgarage.com/wiki/
May be overkill depending on what kind of math your trying to do, but it's great for computer vision.
The GNU Scientific Library is a free numerical library for C and C++ programmers.
With the Coder toolbox (requires MATLAB R2011a), you can also turn your MATLAB code into C or C++.
you can use octave runtime:
http://en.wikipedia.org/wiki/GNU_Octave#C.2B.2B_Integration