-
Notifications
You must be signed in to change notification settings - Fork 0
/
openmp_schedule.c
48 lines (34 loc) · 867 Bytes
/
openmp_schedule.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include <omp.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
int main(void)
{
int i = 0;
int N = 4;
omp_set_num_threads(N);
int count[N];
memset(count, 0, sizeof(int) * N);
printf("**** Static Schedule **** \n \n" );
#pragma omp parallel for schedule(static, 2)
for( i = 0; i < 13; i++) {
#pragma atomic
count[omp_get_thread_num()]++;
sleep(1);
}
for(i = 0; i < N ; i++) {
printf("Loop indexes handled by thread %d = %d \n", i, count[i]);
}
memset(count, 0, sizeof(int) * N);
printf("**** Dynamic Schedule **** \n \n" );
#pragma omp parallel for schedule(dynamic, 2)
for( i = 0; i < 13; i++) {
#pragma atomic
count[omp_get_thread_num()]++;
sleep(1);
}
for(i = 0; i < N ; i++) {
printf("Loop indexes handled by thread %d = %d \n", i, count[i]);
}
return 0;
}