当我运行此方法时,程序在访问M_k
的返回值或程序完成时崩溃。当我只使用rowmajor存储时,类似的代码确实有效。如果我注释掉行*M_k = temps;
它也可以,但我当然想要returnvalue
typedef Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic, Eigen::ColMajor> Matrix_CM_t;
typedef Eigen::SparseMatrix<double, Eigen::RowMajor> ESMatrix_t;
typedef Eigen::SparseMatrix<double, Eigen::ColMajor> ESMatrix_CM_t;
typedef Eigen::Matrix<double, Eigen::Dynamic, 1> Vector_t;
/* M_k = M(I(1:k),:) */
void fill_matrix_from_first_rows_from_list(ESMatrix_t *M, Vector_t *I, int64_t k, ESMatrix_CM_t *M_k) {
int64_t i;
Matrix_CM_t temp = Matrix_CM_t(k, M->cols());
ESMatrix_CM_t temps;
#pragma omp parallel shared(M,M_k,I,k) private(i,row_vec)
{
#pragma omp for
for (i = 0; i<k; i++) {
temp.row(i) = M->row(I->coeffRef(i, 1));
}
}
temps = temp.sparseView();
temps.makeCompressed();
*M_k = temps;
}
在执行方法之前, M_k
已正确初始化
有人能帮助我吗?
调用我用于测试的方法的代码
int main(int argc, char* argv[])
{
Matrix_t temp;
Vector_t *a, tempv;
ESMatrix_t *AS, temp3;
ESMatrix_CM_t *CS;
tempv = Vector_t(3);
tempv << 2,0,1;
a = &tempv;
b = &Vector_t();
temp = Matrix_t(3, 3);
temp << 0, 0, 2, 3, 0, 0, 0, 1, 0;
temp3 = ESMatrix_t(3, 3);
temp3 = temp.sparseView();
temp3.makeCompressed();
AS = &temp3;
CS = &ESMatrix_CM_t();
cout << "A before " << endl << *AS << endl;
fill_matrix_from_first_rows_from_list(AS, b);
cout << "Here is the matrix A:\n" << *CS << endl;
}