/* example3: Shows a parallel for construct: a loop that initializes an array is executed in parallel. Note that the array is not initialized in order from 0 to 100, it depends on how threads are interleaved. */ #include #include #include int main(int argc, char** argv) { int thread_id; const int N=100; int a[N]; #pragma omp parallel for private(thread_id) //note: i is declared inside the loop and is private to each thread for (int i=0; i< N; i++) { a[i] = 2*i; thread_id = omp_get_thread_num(); printf("thread %d assigning a[%d]=%d\n", thread_id, i, 2*i); } for (int i=0; i< 100; i++) { printf("a[%d]=%d\n", i, a[i]); } return 0; }