我正在构建一个距离矩阵,每行代表一个点,每列是该点与数据中所有其他点之间的距离,我的算法在顺序中工作得很好。然而,当我尝试并行化它时,我得到了段错误错误。以下是我的并行代码,其中dat是包含我所有数据的映射。任何帮助在这里将不胜感激。段错误openmp错误
map< int,string >::iterator datIt;
map< int,string >::iterator datIt2;
map <int, map< int, double> > dist;
int mycont=0;
datIt=dat.begin();
int size=dat.size();
#pragma omp parallel //construct the distance matrix
{
#pragma omp for
for(int i=0;i<size;i++)
{
datIt2=dat.find((*datIt).first);
datIt2++;
while(datIt2!=dat.end())
{
double ecl=0;
int c=count((*datIt).second.begin(),(*datIt).second.end(),delm)+1;
string line1=(*datIt).second;
string line2=(*datIt2).second;
for (int i=0;i<c;i++)
{
double num1=atof(line1.substr(0,line1.find_first_of(delm)).c_str());
line1=line1.substr(line1.find_first_of(delm)+1).c_str();
double num2=atof(line2.substr(0,line2.find_first_of(delm)).c_str());
line2=line2.substr(line2.find_first_of(delm)+1).c_str();
ecl += (num1-num2)*(num1-num2);
}
ecl=sqrt(ecl);
dist[(*datIt).first][(*datIt2).first]=ecl;
dist[(*datIt2).first][(*datIt).first]=ecl;
datIt2++;
}
datIt++;
}
}
如果您希望我们调试该代码,您至少可以在崩溃时提供堆栈跟踪。 – NPE 2012-01-17 14:27:01
请在发布之前至少缩进您的代码。 – 2012-01-17 14:27:06