#include <stdio.h>#include <stdlib.h>#include <omp.h>void para_print(){//automatic vars in a routine called within an omp region is private implicitlyint i,tid;
/*if you need shared vars inside omp function call, use static vars;
* the side effect is static vars keeps its previous value
* if not reset a initial value during each call*/staticint j;
#pragma omp single{printf("tid: i,j/n");
j=10;
}#pragma omp for for(i=0;i<5;i++){
tid=omp_get_thread_num();
#pragma omp critical{
j++;
printf("%d: %d,%d/n",tid,i,j);
}}}int main(){int i;
#pragma omp parallel num_threads(5){
para_print(); //注意此时有内嵌omp for,所以不是线程重复执行,要把omp for放进去分析
para_print();
}return0;
}