我正在尝试使用带有OpenMP任务的C并行实现与Boyer-Moore算法的字符串匹配。问题是我有竞争条件,但我无法检测到它。
这部分代码是将基本文本拆分为块并获得结果:
int chunks = 8;
int sizeText = (int) sizeB;
int start = sizeText/(chunks + 1);
int end = sizeText%(chunks + 1);
int j;
// inicio=cp_Wtime();
#pragma omp parallel
#pragma omp single
for (i=0;i<(argc-2);i++) {
#pragma omp task firstprivate(i)
{
int patlen = (int) sizeS[i];
int delta1[ALPHABET_LEN];
int *delta2 = malloc(patlen * sizeof(int));
#pragma omp task
make_delta1(delta1, S[i], patlen);
#pragma omp task
make_delta2(delta2, S[i], patlen);
#pragma omp taskwait
results[i] = sizeText;
for(j = 0; j < chunks; j++) {
#pragma omp task firstprivate(j)
{
int result = boyer_moore(delta1, delta2, B+(start*j), (2 * start) + end, S[i], patlen);
if(result > -1 && result < results[i]) {
//printf(" %d %d %d \n", j, result, start);
#pragma omp critical
results[i] = result + start*j;
}
}
}
#pragma omp taskwait
if (results[i] == sizeText) results[i] = -1;
//results[i] = boyer_moore(delta1, delta2, B, (int) sizeB, S[i], patlen);
}
}