Skip to content

Instantly share code, notes, and snippets.

@jangedoo
Created March 5, 2016 15:32
Show Gist options
  • Save jangedoo/21e5d99f91dc03ff9ca2 to your computer and use it in GitHub Desktop.
Save jangedoo/21e5d99f91dc03ff9ca2 to your computer and use it in GitHub Desktop.
Dynamic Scheduling in OpenMP
void dynamic_scheduling(){
printf("Dynamic Scheduling demo...\n");
int N = 16;
int i;
printf("Using static scheduling\n");
auto t1 = Clock::now();
#pragma omp parallel for num_threads(4) schedule(static, 2)
for (i = 0; i < N; i++){
printf("Thread no = %d, i = %d\n", omp_get_thread_num(), i);
if (i == 0 || i == 9){
Sleep(2000);
}
}
auto t2 = Clock::now();
printTime("Static Scheduling ", t1, t2);
printf("Using with dynamic scheduling\n");
t1 = Clock::now();
#pragma omp parallel for num_threads(4) schedule(dynamic, 2)
for (i = 0; i < N; i++){
printf("Thread no = %d, i = %d\n", omp_get_thread_num(), i);
if (i == 0 || i == 9){
Sleep(2000);
}
}
t2 = Clock::now();
printTime("Dynamic Scheduling ", t1, t2);
printf("Dynamic Scheduling demo END...\n");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment