Reputation: 123
I am using Visual Studio Community 2015 and I'm trying to use the Eigen library in c++ to solve large sparse linear systems. I have everything wrapped in my class Domain2D with defined stiffness matrix and load vector with load vector being my own long double type:
typedef Eigen::Matrix<long double, Eigen::Dynamic, 1> VectorXld; // somewhere way up in the code
class Domain2D {
private:
...
Eigen::SparseMatrix<long double, Eigen::ColMajor> constant_stiffness;
Eigen::SparseMatrix<long double, Eigen::ColMajor> convection_stiffness;
...
VectorXld load;
...
public:
...
void load_constant_stiffness() {
...
resize, reserve, fill up with elements
}
...
void load_convection_stiffness() {
...
}
void load_RHS() {
...
}
}
Finally, somewhere in the class I have the following routine:
void advance_step(const int &step) {
...
Eigen::SparseLU<Eigen::SparseMatrix<long double, Eigen::ColMajor>, Eigen::COLAMDOrdering<int>> solver;
Eigen::SparseMatrix<long double, Eigen::ColMajor> M;
VectorXld res, res_new;
res.resize(2 * N + n);
...
while (d > 1e-5) {
d = 0;
load_convection_stiffness();
load_RHS();
M = constant_stiffness + convection_stiffness;
M.makeCompressed();
solver.analyzePattern(M);
solver.factorize(M);
res_new = solver.solve(load);
...
}
Save("output\\results\\", step);
t += dt;
}
The program fails on the last mentioned line: res_new = solver.solve(M);
It shows me a file called "SparseLU_SupermodalMatrix.h", the routine it fails in is void MappedSuperNodalMatrix<Scalar,Index_>::solveInPlace( MatrixBase<Dest>&X) const
and the line is Index fsupc = supToCol()[k];
and the error it shows is
Unhandled exception thrown: read access violation.
this->m_sup_to_col was 0x111011101110112.
If there is a handler for this exception, the program may be safely continued.
I was searching a bit and I found that if I use eigen objects in my class, I should add line EIGEN_MAKE_ALIGNED_OPERATOR_NEW;
in the public section, which I did, to no avail. All matrices are of a proper size, as well as the vector of long doubles. I have been solving these systems for some time and it worked, but suddenly, this happens. What could be the cause?
P.S.: I loaded the matrix and load vector to mathematica and even with the standard precision, I get a solution which looks absolutely fine, so it's not like the system is ill-conditioned.
Upvotes: 0
Views: 1406
Reputation: 29205
Some tips:
solver.info()==Eigen::Success
after the call to factorize()
.NDEBUG
defined (aka. debug mode in visual) to see whether Eigen triggers some insightful assertions.double
instead of long double
might help to isolate the issue. To this end, you can cast locally M
and load
with .cast<double>()
. M
with Eigen's team to let them (i.e., myself ;) ) reproduce the issue.Upvotes: 3