int COPYIN_A = 100;
#pragma omp threadprivate(COPYIN_A)
void TestCopyin2()
{
omp_set_num_threads(4);
#pragma omp parallel
{
printf("No.%d - Initial COPYIN_A = %d\n", omp_get_thread_num(), COPYIN_A);
COPYIN_A = omp_get_thread_num();
printf("get threadNo COPYIN_A: %d\n", COPYIN_A);
}
printf("Global COPYIN_A: %d\n\n", COPYIN_A);
#pragma omp parallel copyin(COPYIN_A) // copyin
{
printf("No.%d - Initial COPYIN_A = %d\n", omp_get_thread_num(), COPYIN_A);
COPYIN_A = omp_get_thread_num();
printf("get threadNo COPYIN_A: %d\n", COPYIN_A);
}
printf("Global COPYIN_A: %d\n\n", COPYIN_A);
#pragma omp parallel // Will not copy, to check the result.
{
printf("No.%d - Initial COPYIN_A = %d\n", omp_get_thread_num(), COPYIN_A);
COPYIN_A = omp_get_thread_num();
printf("get threadNo COPYIN_A: %d\n", COPYIN_A);
}
printf("Global COPYIN_A: %d\n", COPYIN_A);
}
为什么每一段的Global COPYIN_A的值永远等于0?为什么第三段COPYIN_A的赋值在输出之后,但输出的COPYIN_A值与后面的赋值之后的COPYIN_A值一致?