각 행이 점을 나타내고 각 열이이 점과 데이터의 다른 모든 점 사이의 거리이고 거리가 매우 먼 거리 행렬을 구축하고 있습니다. 알고리즘은 순차적으로 매우 잘 작동합니다. 그러나 병렬화하려고하면 세분화 오류 오류가 발생합니다. 다음은 내 데이터가 모두 포함 된지도 인 parallel에 대한 코드입니다. 여기에 어떤 도움을 주시면 감사하겠습니다. 그것은 당신의 코드 유일한 문제이지만, 표준 컨테이너 (예 : std::map
와 같은) 당신이 그들에 기록 적어도 경우 스레드가되지 않은 경우segmentation fault openmp error
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
최소한 코드를 게시하기 전에 들여 쓰기를하십시오. –