#pragma omp threadprivate(alpha)
程序员文章站
2022-04-12 20:15:34
#include
int alpha[10],beta[10],i;
#pragma omp threadprivate(alpha)...
#include <omp.h> int alpha[10],beta[10],i; #pragma omp threadprivate(alpha) main() { /* first parallel region */ #pragma omp parallel private(i,beta) { int id ; id = omp_get_thread_num(); for(i=0;i<10;i++) alpha[i] = beta[i] = id * i; } /* second parallel region */ #pragma omp parallel printf("I am thread %d :alpha[3] = %d and beta[3] = %d\n", omp_get_thread_num(),alpha[3],beta[3]); }
I am thread 0 :alpha[3] = 0 and beta[3] = 0 I am thread 3 :alpha[3] = 9 and beta[3] = 0 I am thread 2 :alpha[3] = 6 and beta[3] = 0 I am thread 1 :alpha[3] = 3 and beta[3] = 0