Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/61.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
CIVL检测OpenMP程序中的数据竞争-是否正确?_C_Openmp_Verification - Fatal编程技术网

CIVL检测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

我使用civlverify-input_omp_thread_max=2 file.c命令运行CIVL,它检测到程序中存在缺陷。警告是:

线程1无法执行$omp_write,因为线程0已写入同一变量且尚未刷新

但我不明白。我想这可能是因为全局变量和应该添加到flush中,但在我这样做之后,警告仍然存在。我对程序是否如警告所示存在缺陷感到困惑。谢谢你的帮助

OpenMP程序如下所示:

#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提供的缩减,而不是重新设计