【发布时间】:2015-06-13 11:33:17
【问题描述】:
我不明白为什么在这段代码中只有线程 0 有 n = 1 而其他线程有 n = 0 且 shared n:
int main()
{
int n, tid;
#pragma omp parallel shared(n) private(tid)
{
tid = omp_get_thread_num();
n = 0;
if (tid == 0)
{
n++;
}
printf("I'am %d, this is my n: %d\n", tid, n);
}
return 0;
}
输出:
I'am 5, this is my n: 0
I'am 7, this is my n: 0
I'am 0, this is my n: 1
I'am 2, this is my n: 0
I'am 4, this is my n: 0
I'am 3, this is my n: 0
I'am 6, this is my n: 0
I'am 1, this is my n: 0
我是 OMP 库的新手。我在一个有 8 个节点的集群上通过 ssh 工作,这可能是问题吗?
谢谢。
【问题讨论】:
标签: c parallel-processing openmp