// Compile with: // // gcc -fopenmp hello.c #include #include int main(int argc, char *argv[]) { int nthreads, myid; /* make the values of nthreads and myid private to each thread */ #pragma omp parallel private (nthreads, myid) { /* ------------------------------ Every thread does this ------------------------------ */ myid = omp_get_thread_num(); printf("Hello I am thread %d\n", myid); /* ------------------------------ Only thread 0 does this ------------------------------ */ if (myid == 0) { nthreads = omp_get_num_threads(); printf("Number of threads = %d\n", nthreads); } } return 0; }