// test1.c check if openMP available compile gcc -fopenmp ... #include #include #include #include int main(int argc, char * argv[]) { int myid; int def_num_threads, num_threads, num_proc; double ttime; num_proc = omp_get_num_procs(); printf("test1.c check for openMP, num_proc=%d \n", num_proc); fflush(stdout); ttime = omp_get_wtime(); // wall time now, in seconds #pragma omp parallel // must be at least one "parallel", else no threads { #pragma omp master // only the master thread will run { to } { def_num_threads = omp_get_num_threads(); // must be in parallel omp_set_num_threads(6); num_threads = omp_get_num_threads(); printf("def_num_threads=%d, try 6, omp_set_num_threads =%d \n", def_num_threads, num_threads); fflush(stdout); // needed to get clean output } #pragma omp barrier // all threads must be doing nothing myid = omp_get_thread_num(); // master == 0 printf("test1.c in pragma omp parallel myid=%d \n", myid); fflush(stdout); } // total wall time is difference printf("test1.c ends, %f seconds \n", omp_get_wtime()-ttime); fflush(stdout); return 0; } // end test1.c