// // reduction // #include #include const int n=100; int main() { int nthreads=0, tid=0; int i, mysum=0; #pragma omp parallel reduction(+:mysum) private(i,tid) // private(i,tid,nthreads) { nthreads = omp_get_num_threads(); tid = omp_get_thread_num(); for (i=tid+1; i<=n; i=i+nthreads) { mysum = mysum + i; } } printf("\noutside:\n"); printf("nthreads=%d, mysum=%d\n", nthreads, mysum); return 0; }