Search code examples
sparse-matrixarmadilloeigenvalue

Armadillo: eigs_gen can not successfully give answer


I'm using armadillo's eigs_gen to find the smallest algebraic eigenvalue of a sparse matrix, but eigs_gen can not give an answer. I test the eigs_gen for eye matrix 6*6, it also can not give the answer. The code is:

#include <iostream>
#include <armadillo>
using namespace arma;
using namespace std;
int main(int argc, char** argv)
{
    cout << "Armadillo version: " << arma_version::as_string() << endl;
    sp_mat A = speye<sp_mat>(6, 6);
    A.print("A:");

    cx_vec eigval;
    cx_mat eigvec;

    eigs_gen(eigval, eigvec, A, 1, "sm", 1);  // find 1 eigenvalues/eigenvectors
    eigval.print("eigval:");
    return 0;
}   

The answer is:

Armadillo version: 6.100.0 (Midnight Blue)
A:
[matrix size: 6x6; n_nonzero: 6; density: 16.67%]

     (0, 0)         1.0000
     (1, 1)         1.0000
     (2, 2)         1.0000
     (3, 3)         1.0000
     (4, 4)         1.0000
     (5, 5)         1.0000

*** Error in `./test': double free or corruption (out): 0x00007fff38dd6910 ***
Aborted (core dumped)

However, an correct answer could be achieved, when the eye matrix is 5*5.
The code is:

#include <iostream>
#include <armadillo>
using namespace arma;
using namespace std;
int main(int argc, char** argv)
{
    cout << "Armadillo version: " << arma_version::as_string() << endl;
    sp_mat A = speye<sp_mat>(5, 5);
    A.print("A:");

    cx_vec eigval;
    cx_mat eigvec;

    eigs_gen(eigval, eigvec, A, 1, "sm", 1);  // find 1 eigenvalues/eigenvectors
    eigval.print("eigval:");
    return 0;
}  

the answer is:

Armadillo version: 6.100.0 (Midnight Blue)
A:
[matrix size: 5x5; n_nonzero: 5; density: 20.00%]

     (0, 0)         1.0000
     (1, 1)         1.0000
     (2, 2)         1.0000
     (3, 3)         1.000
     (4, 4)         1.0000

eigval:
    (+1.000e+00,+0.000e+00)

My compile command is:

g++ test.cpp -o test -O2 -I/usr/local/include/armadillo -L/usr/local/lib -DARMA_DONT_USE_WRAPPER -larpack -llapack -lblas -lf2c -lgfortran

I'm working on ubuntu 14.04LTS.


Solution

  • I have find the solution to this problem. The reason is that libopenblas, liblapack, libarpack were compiled by myself and all were Packaged as a static library. When they were used together, this problem was happened. The solution is that install these packages through commands listed below. sudo apt-get install libopenblas-dev sudo apt-get install liblapack-dev sudo apt-get install libarpack2-dev