For a very simple test example when trying to fill Eigen::SparseMatrix
within OpenMP construct, application crashes.
SparseMatrix<double> A_mat( nCol, nRow );
//A_mat.reserve( VectorXi::Constant( nCol, nRow ) ); // When commented crashes
auto numThreads = omp_get_max_threads();
#pragma omp parallel for num_threads( numThreads )
for ( int j = 0; j < nCol; ++j )
{
for ( int i = 0; i < nRow; ++i )
{
if ( i >= j )
{
double val = i * nCol + j;
A_mat.insert( i, j ) = val;
}
}
}
This code runs how expected only when I use 1
thread. However, when run with multiple threads following errors are thrown:
double free or corruption (!prev)
double free or corruption (!prev)
double free or corruption (!prev)
double free or corruption (top)
double free or corruption (!prev)
double free or corruption (out)
When I uncomment the following line:
A_mat.reserve( VectorXi::Constant( nCol, nRow ) );
then above given block of code again produces expected results even when run with multiple threads.
Could someone explain to me why is this happening?