CIVL检测OpenMP程序中的数据竞争-是否正确?
我使用civlverify-input_omp_thread_max=2 file.c命令运行CIVL,它检测到程序中存在缺陷。警告是: 线程1无法执行$omp_write,因为线程0已写入同一变量且尚未刷新 但我不明白。我想这可能是因为全局变量和应该添加到flush中,但在我这样做之后,警告仍然存在。我对程序是否如警告所示存在缺陷感到困惑。谢谢你的帮助 OpenMP程序如下所示:CIVL检测OpenMP程序中的数据竞争-是否正确?,c,openmp,verification,C,Openmp,Verification,我使用civlverify-input_omp_thread_max=2 file.c命令运行CIVL,它检测到程序中存在缺陷。警告是: 线程1无法执行$omp_write,因为线程0已写入同一变量且尚未刷新 但我不明白。我想这可能是因为全局变量和应该添加到flush中,但在我这样做之后,警告仍然存在。我对程序是否如警告所示存在缺陷感到困惑。谢谢你的帮助 OpenMP程序如下所示: #define N 100 int main (int argc, char *argv[]) { doubl
#define N 100
int main (int argc, char *argv[]) {
double a[N], b[N];
double localsum, sum = 0.0;
int i, tid, nthreads;
#pragma omp parallel shared(a,b,sum) private(i, localsum)
{
/* Initialization */
#pragma omp for
for (i=0; i < N; i++)
a[i] = b[i] = (double)i;
localsum = 0.0;
/* Compute the local sums of all products */
#pragma omp for
for (i=0; i < N; i++)
localsum = localsum + (a[i] * b[i]);
#pragma omp critical //add flush(sum) is useless
sum = sum+localsum;
} /* End of parallel region */
printf(" Sum = %2.1f\n",sum);
assert(sum==328350);
exit(0);
}
你的代码是正确的。在临界区域的开始和结束处存在隐式刷新。CIVL似乎出错了,尽管我无法复制它 也就是说,在实践中——使用OpenMP提供的缩减,而不是重新设计