#include #include #include using namespace std; int main() { int a[4], b , c, d; b = 1234; c = 5678; d = 91011; #pragma omp parallel for num_threads(4) shared(a) private(b) firstprivate(c) lastprivate(d) for (int i=0; i<4; ++i) { #pragma omp critical { a[i] = (i + 1) * 5; b += a[ i ]; c += a[ i ]; d += a[ i ]; cout << "execute thread " << omp_get_thread_num() << endl; cout << "b=" << b << endl; cout << "c=" << c << endl; cout << "d=" << d << endl; } } cout << "after parallel section :" << endl; for (int i=0; i<4; ++i) { cout << "a[" << i << "]=" << a[i] << endl; } cout << "b=" << b << endl; cout << "c=" << c << endl; cout << "d=" << d << endl; return EXIT_SUCCESS; }