Created
March 5, 2016 15:32
-
-
Save jangedoo/21e5d99f91dc03ff9ca2 to your computer and use it in GitHub Desktop.
Dynamic Scheduling in OpenMP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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