欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

#pragma omp threadprivate(alpha)

程序员文章站 2022-07-05 23:37:59
#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