-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfor_ordered.c
More file actions
39 lines (34 loc) · 796 Bytes
/
for_ordered.c
File metadata and controls
39 lines (34 loc) · 796 Bytes
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
#include <omp.h>
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
void orderInsensitivePart1(int item)
{
// printf("%s", "hii");
// printf("%d", item);
}
void orderInsensitivePart2(int item)
{
// printf("%s", "bye");
// printf("%d", item);
}
void doThisInOrder(int item)
{
printf("%d", item);
}
int main(int argc, char *argv[])
{
int n = 5;
int N = 20;
int k = 0;
#pragma omp parallel num_threads(n)
#pragma omp for ordered
for (int item = 0; item < N; item++)
{
orderInsensitivePart1(item); // Concurrent with other iterations
#pragma omp ordered
doThisInOrder(item); // Called with item = 0 to N-1, in that order
orderInsensitivePart2(item); // Concurrent with other iterations
}
printf("%d", k);
}