我正在使用 pthreads 和 eigen 库编写一个并行程序。我的程序看起来像这样:
#include <Eigen/...>
#include <pthread.h>
...
typedef Eigen::SparseMatrix<long double> matrizLD;
matrizLD mat;
typedef Eigen::Matrix<long double, Dynamic, 1> VectorLD;
VectorLD v1;
VectorLD v2;
void *power_method(int rank){
...
int from = from_array[rank]
int length = length_array[rank]
v1.segment(from,length) = mat.block(from,0,length,size)*v2; //something like this
}
int main(...){
size = ...; //an input parameter
matrizLD mat(size,size) = ...;
VectorLD v1(size) = ...;
VectorLD v2(size) = ...;
...
pthread_create(..., power_method, ...);
...
}
我基本上需要向量和矩阵作为全局变量才能在函数中访问它们。该程序编译但当我执行它时,我收到以下错误:
断言失败:(startRow >= 0 && blockRows >= 0 && startRow <= xpr.rows() - blockRows && startCol >= 0 && blockCols >= 0 && startCol <= xpr.cols() - blockCols),功能块,文件 ...
起初我以为我试图访问向量的非法部分,但后来我将“power_method”函数更改为:
void *power_method(int rank){
v1(0); // I can do this from main with no problem
}
我仍然遇到同样的错误。我的猜测是我定义向量和矩阵的方式不正确,但我找不到任何说明什么是正确方式的内容。
你有两个v1
变量:
VectorLD v1; //global
void *power_method(int rank){
v1.segment(from,length) = mat.block(from,0,length,size)*v2; //something like this
}
int main(...){
size = ...; //an input parameter
VectorLD v1(size) = ...; //oops another one
}
您主要需要初始化全局变量。我想像
int main(...){
size = ...; //an input parameter
v1 = VectorLD(size);// global one
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句