0
나는 순진한 indexOf 함수를 작성하려고합니다. 현재 작동하고 올바른 위치를 얻습니다. 그러나 비교 횟수를 계산할 때 오버플로됩니다. 나는 긴 long ints로 그것들을 모두 변환하려고 시도했지만 어떤 차이를 만드는 것 같지 않습니다. 이 문제를 해결하려면 어떻게해야합니까?OpenMP에서 int의 오버플로
int hostMatch(long long int *comparisons)
{
long int i,j,k, lastI;
i=0;
j=0;
k=0;
lastI = textLength-patternLength;
*comparisons=0;
int lastIi = lastI+1;
int position = -1;
int numberThreads = 1;
int totalCom = 0;
#pragma omp parallel for default(none) num_threads(numberThreads) \
shared(totalCom, position) \
private(i,j,k) \
firstprivate(lastIi,patternLength, textData, patternData)
for (i=0;i<lastIi;i++)
{
if (position != -1)
{
// found
}
else
{
k=i;
long long int count = 0L;
for (j=0;j<patternLength;j++)
{
count++;
if (textData[k] == patternData[j])
{
if (j == patternLength - 1)
{
// found
position = i;
}
}
else
{
break;
}
k++;
}
#pragma omp critical (totalLock)
{
totalCom += count;
}
}
}
/* END OF PARALLEL SECTION*/
printf("Total Comparisons = %i\n", totalCom);
(*comparisons) = totalCom;
return position;
}
'totalCom'은'int'입니다; 범람하는 변수가 아니라고 확신합니까? 또한,'totalCom'을 업데이트하기 위해'#pragma omp critical '을 필요로하지 않습니다; 대신'reduce (+ : totalCom)'을'parallel for' 헤더에 추가하십시오. –
고마워요, 그 문제가 해결되었지만 지금은 경감 조건이 잘못되어 있습니다. – Kurru
위치에 대한 경쟁 조건이 있지만 totalCom으로 감소를 사용하면 문제가 없습니다. – ejd