dimanche 4 septembre 2022

Valgrind error: Conditional jump/uninitialised value(s) using Eigen in C++

Usually, I am fairly comfortable with Valgrind error messages when using C++ arrays and not with Eigen matrices. This error means to be something is not initialized, even though I cannot see how is that the case. Seems like valgrind shows the place where the unitialised value ends up being used, but not the origin of the uninitialised value. I am using the flag:

valgrind --track-origins=yes

which usually helps identifying the lines, but for some reason this isn't working with Eigen. The full error messages: Error1:

 Conditional jump or move depends on uninitialised value(s)
==7674==    at 0x13BCFD: Eigen::internal::triangular_solve_vector<std::complex<double>, std::complex<double>, long, 1, 2, false, 0>::run(long, std::complex<double> const*, long, std::complex<double>*) (in /mnt/c/Users/J/Desktop/Data/test.out)
==7674==    by 0x13C831: Eigen::internal::triangular_solver_selector<Eigen::Block<Eigen::Matrix<std::complex<double>, -1, -1, 0, -1, -1> const, -1, -1, false> const, Eigen::Block<Eigen::Matrix<std::complex<double>, -1, 1, 0, -1, 1>, -1, 1, false>, 1, 2, 0, 1>::run(Eigen::Block<Eigen::Matrix<std::complex<double>, -1, -1, 0, -1, -1> const, -1, -1, false> const&, Eigen::Block<Eigen::Matrix<std::complex<double>, -1, 1, 0, -1, 1>, -1, 1, false>&) 

Error 2:

  by 0x13CB4C: void Eigen::ColPivHouseholderQR<Eigen::Matrix<std::complex<double>, -1, -1, 0, -1, -1> >::_solve_impl<Eigen::Block<Eigen::Matrix<std::complex<double>, -1, -1, 0, -1, -1>, -1, 1, true>, Eigen::Block<Eigen::Matrix<std::complex<double>, -1, -1, 0, -1, -1>, -1, 1, true> >(Eigen::Block<Eigen::Matrix<std::complex<double>, -1, -1, 0, -1, -1>, -1, 1, true> const&, Eigen::Block<Eigen::Matrix<std::complex<double>, -1, -1, 0, -1, -1>, -1, 1, true>&) const (in /mnt/c/Users/J/Desktop/Data/test.out)
==7674==    by 0x12F80F: potentialk(Eigen::Ref<Eigen::Matrix<std::complex<double>, -1, -1, 0, -1, -1> const, 0, Eigen::OuterStride<-1> > const&, Eigen::Ref<Eigen::Matrix<std::complex<double>, -1, -1, 0, -1, -1> const, 0, Eigen::OuterStride<-1> > const&, Eigen::Ref<Eigen::Matrix<std::complex<double>, -1, -1, 0, -1, -1> const, 0, Eigen::OuterStride<-1> > const&, Eigen::Ref<Eigen::Matrix<std::complex<double>, -1, -1, 0, -1, -1>, 0, Eigen::OuterStride<-1> >, Eigen::Ref<Eigen::Matrix<std::complex<double>, -1, -1, 0, -1, -1> const, 0, Eigen::OuterStride<-1> > const&, Eigen::Ref<Eigen::Matrix<double, -1, 1, 0, -1, 1>, 0, Eigen::InnerStride<1> >, Eigen::Ref<Eigen::Matrix<double, -1, 1, 0, -1, 1>, 0, Eigen::InnerStride<1> >, Eigen::Ref<Eigen::Matrix<double, -1, -1, 0, -1, -1> const, 0, Eigen::OuterStride<-1> > const&, double, int)

Error 3:

==7674==    by 0x12F80F: potentialk(Eigen::Ref<Eigen::Matrix<std::complex<double>, -1, -1, 0, -1, -1> const, 0, Eigen::OuterStride<-1> > const&, Eigen::Ref<Eigen::Matrix<std::complex<double>, -1, -1, 0, -1, -1> const, 0, Eigen::OuterStride<-1> > const&, Eigen::Ref<Eigen::Matrix<std::complex<double>, -1, -1, 0, -1, -1> const, 0, Eigen::OuterStride<-1> > const&, Eigen::Ref<Eigen::Matrix<std::complex<double>, -1, -1, 0, -1, -1>, 0, Eigen::OuterStride<-1> >, Eigen::Ref<Eigen::Matrix<std::complex<double>, -1, -1, 0, -1, -1> const, 0, Eigen::OuterStride<-1> > const&, Eigen::Ref<Eigen::Matrix<double, -1, 1, 0, -1, 1>, 0, Eigen::InnerStride<1> >, Eigen::Ref<Eigen::Matrix<double, -1, 1, 0, -1, 1>, 0, Eigen::InnerStride<1> >, Eigen::Ref<Eigen::Matrix<double, -1, -1, 0, -1, -1> const, 0, Eigen::OuterStride<-1> > const&, double, int)

These errors sort of just repeat, so the first one doesn't make sense to me. But, the second and third I can guess what line of code they're referring to but I don't see where things are uninitialized??

The error points first at the function definitions:

int potentialk(const Eigen::Ref<const Eigen::MatrixXcd>& invnk, const Eigen::Ref<const Eigen::MatrixXcd>& dndxk, const Eigen::Ref<const Eigen::MatrixXcd>& dndyk, Ref<MatrixXcd> phik, const Eigen::Ref<const Eigen::MatrixXcd>& potSourcek, Ref<VectorXd> kx,Ref<VectorXd> ninvksqu,const Eigen::Ref<const Eigen::MatrixXd>& D, double err_max, int max_iter){

Then inside in a while loop:

//Initializations
Eigen::MatrixXcd L((ny+1),(ny+1));
L.setZero();

Eigen::SparseMatrix<double> Igl((ny+1),(ny+1)); 
Igl.setIdentity();
    
Eigen::SparseMatrix<double> div_x_act_on_grad_x((ny+1),(ny+1)); 
div_x_act_on_grad_x.setIdentity();
div_x_act_on_grad_x = -Igl;

Eigen::MatrixXd div_y_act_on_grad_y((ny+1),(ny+1));
div_y_act_on_grad_y.setZero(); 

Eigen::MatrixXcd Stilde((ny+1),nx);
Stilde.setZero();
do{
//some calculations
for (int l = 0; l < kx.size(); l++){
   L = div_x_act_on_grad_x * std::pow(ninvksqu(l),2.0) + div_y_act_on_grad_y; 
  unewh(all,l) = L.cast<std::complex<double>>().colPivHouseholderQr().solve(Stilde(all,l));//ERROR
}

}while(); //convergence condition

Is it possible this error refers to the way some variables are defined or passed in the function?

Aucun commentaire:

Enregistrer un commentaire