This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Vector of Sparse LU solver

Tags: None
(comma "," separated)
shantanu1
Registered Member
Posts
2
Karma
0

Vector of Sparse LU solver

Mon Aug 26, 2019 1:43 pm
I am using the Eigen library for solving sparse linear equations: Ax=b where, A is a square sparse matrix and b is a rectangular sparse matrix. I have multiple instances of the A matrices and each one has multiple right hand sides b. Hence, I want to factorize all the A matrices once and store them followed by solution for each A with each b.

I tried to use the C++ vector for storing all the solvers. This is a sample code I have written:
Code: Select all
vector<Eigen::SparseMatrix<double>> A;
//fill in all A matrices

vector<Eigen::SparseLU<Eigen::SparseMatrix<double>>> solver_A;

Eigen::SparseLU<Eigen::SparseMatrix<double>> solver;

for (int i=0;i<A.size();i++){
    solver.analyzePattern(A[i]);
    solver.factorize(A[i]);     
    solver_A.push_back(solver);
}

//Later, solver_A entries are to be used to solve for various right hand sides


I am using 3.3.7 version of Eigen and compiling in linux with gcc compiler and c++17 standard. I am getting the following compilation error due to the "solver_A.push_back(solver)" line:

In file included from /usr/include/x86_64-linux-gnu/c++/7/bits/c++allocator.h:33:0,
from /usr/include/c++/7/bits/allocator.h:46,
from /usr/include/c++/7/string:41,
from /usr/include/c++/7/stdexcept:39,
from header_files/coefficient_computations.hpp:11,
from header_files/coefficient_computations.cpp:2:
/usr/include/c++/7/ext/new_allocator.h: In instantiation of ‘void __gnu_cxx::new_allocator<_Tp>::construct(_Up*, _Args&& ...) [with _Up = Eigen::SparseLU<Eigen::SparseMatrix<double> >; _Args = {const Eigen::SparseLU<Eigen::SparseMatrix<double, 0, int>, Eigen::COLAMDOrdering<int> >&}; _Tp = Eigen::SparseLU<Eigen::SparseMatrix<double> >]’:
/usr/include/c++/7/bits/alloc_traits.h:475:4: required from ‘static void std::allocator_traits<std::allocator<_CharT> >::construct(std::allocator_traits<std::allocator<_CharT> >::allocator_type&, _Up*, _Args&& ...) [with _Up = Eigen::SparseLU<Eigen::SparseMatrix<double> >; _Args = {const Eigen::SparseLU<Eigen::SparseMatrix<double, 0, int>, Eigen::COLAMDOrdering<int> >&}; _Tp = Eigen::SparseLU<Eigen::SparseMatrix<double> >; std::allocator_traits<std::allocator<_CharT> >::allocator_type = std::allocator<Eigen::SparseLU<Eigen::SparseMatrix<double> > >]’
/usr/include/c++/7/bits/stl_vector.h:943:30: required from ‘void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = Eigen::SparseLU<Eigen::SparseMatrix<double> >; _Alloc = std::allocator<Eigen::SparseLU<Eigen::SparseMatrix<double> > >; std::vector<_Tp, _Alloc>::value_type = Eigen::SparseLU<Eigen::SparseMatrix<double> >]’
header_files/coefficient_computations.cpp:476:51: required from here
/usr/include/c++/7/ext/new_allocator.h:136:4: error: ‘Eigen::SparseLU<_MatrixType, _OrderingType>::SparseLU(const Eigen::SparseLU<_MatrixType, _OrderingType>&) [with _MatrixType = Eigen::SparseMatrix<double>; _OrderingType = Eigen::COLAMDOrdering<int>]’ is private within this context
{ ::new((void *)__p) _Up(std::forward<_Args>(__args)...); }
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from ../Eigen_3_3_7/unsupported/Eigen/../../Eigen/SparseLU:44:0,
from ../Eigen_3_3_7/unsupported/Eigen/../../Eigen/Sparse:31,
from ../Eigen_3_3_7/unsupported/Eigen/SparseExtra:13,
from header_files/general_functions.hpp:17,
from header_files/coefficient_computations.hpp:17,
from header_files/coefficient_computations.cpp:2:
../Eigen_3_3_7/unsupported/Eigen/../../Eigen/src/SparseLU/SparseLU.h:393:5: note: declared private here
SparseLU (const SparseLU& );
^~~~~~~~
In file included from /usr/include/c++/7/vector:62:0,
from header_files/coefficient_computations.hpp:13,
from header_files/coefficient_computations.cpp:2:
/usr/include/c++/7/bits/stl_construct.h: In instantiation of ‘void std::_Construct(_T1*, _Args&& ...) [with _T1 = Eigen::SparseLU<Eigen::SparseMatrix<double> >; _Args = {Eigen::SparseLU<Eigen::SparseMatrix<double, 0, int>, Eigen::COLAMDOrdering<int> >}]’:
/usr/include/c++/7/bits/stl_uninitialized.h:83:18: required from ‘static _ForwardIterator std::__uninitialized_copy<_TrivialValueTypes>::__uninit_copy(_InputIterator, _InputIterator, _ForwardIterator) [with _InputIterator = std::move_iterator<Eigen::SparseLU<Eigen::SparseMatrix<double> >*>; _ForwardIterator = Eigen::SparseLU<Eigen::SparseMatrix<double> >*; bool _TrivialValueTypes = false]’
/usr/include/c++/7/bits/stl_uninitialized.h:134:15: required from ‘_ForwardIterator std::uninitialized_copy(_InputIterator, _InputIterator, _ForwardIterator) [with _InputIterator = std::move_iterator<Eigen::SparseLU<Eigen::SparseMatrix<double> >*>; _ForwardIterator = Eigen::SparseLU<Eigen::SparseMatrix<double> >*]’
/usr/include/c++/7/bits/stl_uninitialized.h:289:37: required from ‘_ForwardIterator std::__uninitialized_copy_a(_InputIterator, _InputIterator, _ForwardIterator, std::allocator<_Tp>&) [with _InputIterator = std::move_iterator<Eigen::SparseLU<Eigen::SparseMatrix<double> >*>; _ForwardIterator = Eigen::SparseLU<Eigen::SparseMatrix<double> >*; _Tp = Eigen::SparseLU<Eigen::SparseMatrix<double> >]’
/usr/include/c++/7/bits/stl_uninitialized.h:311:2: required from ‘_ForwardIterator std::__uninitialized_move_if_noexcept_a(_InputIterator, _InputIterator, _ForwardIterator, _Allocator&) [with _InputIterator = Eigen::SparseLU<Eigen::SparseMatrix<double> >*; _ForwardIterator = Eigen::SparseLU<Eigen::SparseMatrix<double> >*; _Allocator = std::allocator<Eigen::SparseLU<Eigen::SparseMatrix<double> > >]’
/usr/include/c++/7/bits/vector.tcc:426:6: required from ‘void std::vector<_Tp, _Alloc>::_M_realloc_insert(std::vector<_Tp, _Alloc>::iterator, _Args&& ...) [with _Args = {const Eigen::SparseLU<Eigen::SparseMatrix<double, 0, int>, Eigen::COLAMDOrdering<int> >&}; _Tp = Eigen::SparseLU<Eigen::SparseMatrix<double> >; _Alloc = std::allocator<Eigen::SparseLU<Eigen::SparseMatrix<double> > >; std::vector<_Tp, _Alloc>::iterator = __gnu_cxx::__normal_iterator<Eigen::SparseLU<Eigen::SparseMatrix<double> >*, std::vector<Eigen::SparseLU<Eigen::SparseMatrix<double> > > >; typename std::_Vector_base<_Tp, _Alloc>::pointer = Eigen::SparseLU<Eigen::SparseMatrix<double> >*]’
/usr/include/c++/7/bits/stl_vector.h:948:21: required from ‘void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = Eigen::SparseLU<Eigen::SparseMatrix<double> >; _Alloc = std::allocator<Eigen::SparseLU<Eigen::SparseMatrix<double> > >; std::vector<_Tp, _Alloc>::value_type = Eigen::SparseLU<Eigen::SparseMatrix<double> >]’
header_files/coefficient_computations.cpp:476:51: required from here
/usr/include/c++/7/bits/stl_construct.h:75:7: error: ‘Eigen::SparseLU<_MatrixType, _OrderingType>::SparseLU(const Eigen::SparseLU<_MatrixType, _OrderingType>&) [with _MatrixType = Eigen::SparseMatrix<double>; _OrderingType = Eigen::COLAMDOrdering<int>]’ is private within this context
{ ::new(static_cast<void*>(__p)) _T1(std::forward<_Args>(__args)...); }
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from ../Eigen_3_3_7/unsupported/Eigen/../../Eigen/SparseLU:44:0,
from ../Eigen_3_3_7/unsupported/Eigen/../../Eigen/Sparse:31,
from ../Eigen_3_3_7/unsupported/Eigen/SparseExtra:13,
from header_files/general_functions.hpp:17,
from header_files/coefficient_computations.hpp:17,
from header_files/coefficient_computations.cpp:2:
../Eigen_3_3_7/unsupported/Eigen/../../Eigen/src/SparseLU/SparseLU.h:393:5: note: declared private here
SparseLU (const SparseLU& );
^~~~~~~~


The compilation is successful if the line "solver_A.push_back(solver)" is commented. Any help is appreciated either to fix this issue or with alternate solution.


Bookmarks



Who is online

Registered users: Bing [Bot], Evergrowing, Google [Bot], rblackwell