2
我OpenMP
程序是这样的:为什么OpenMP的禁止使用“的#pragma OMP并行” LASTPRIVATE?
#include <stdio.h>
#include <omp.h>
int main (void)
{
int i = 10;
#pragma omp parallel lastprivate(i)
{
printf("thread %d: i = %d\n", omp_get_thread_num(), i);
i = 1000 + omp_get_thread_num();
}
printf("i = %d\n", i);
return 0;
}
使用gcc
编译它,并生成以下错误:
# gcc -fopenmp test.c
test.c: In function 'main':
test.c:8:26: error: 'lastprivate' is not valid for '#pragma omp parallel'
#pragma omp parallel lastprivate(i)
^~~~~~~~~~~
为什么OpenMP
禁止在#pragma omp parallel
使用lastprivate
?
[在OpenMP中如何firstprivate和lastprivate不同于private子句?](http://stackoverflow.com/questions/15304760/how-are-firstprivate-and-lastprivate-different-than-private-clauses -in-的OpenMP) – LPs