omp_schedule.cpp (1049B)
1 #include <iostream> 2 #include <omp.h> 3 4 int main(void) 5 { 6 #pragma omp parallel 7 { 8 const int tid = omp_get_thread_num(); 9 10 omp_sched_t sched; 11 int chunk; 12 13 #pragma omp single 14 { 15 // check the default before we change: 16 omp_get_schedule(&sched, &chunk); 17 std::cout << "Default: sched=" << sched << "; chunk=" << chunk 18 << " (tid=" << tid << ")\n"; 19 20 // DISCLAIMER: this will only set the schedule for the calling 21 // thread! 22 // If the second arg is < 1: OpenMP uses the default chunk_size for 23 // the chosen scheduling policy, for omp_sched_auto the second arg 24 // is irrelevant: 25 omp_set_schedule(omp_sched_guided, 8); 26 } 27 28 // see what you get with all threads 29 omp_get_schedule(&sched, &chunk); 30 31 #pragma omp critical 32 { 33 std::cout << "Thread " << tid << ":\tsched=" << sched 34 << "; chunk=" << chunk << '\n'; 35 } 36 } 37 return 0; 38 }