-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathexample4.c
27 lines (24 loc) · 842 Bytes
/
example4.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
#include <omp.h>
#include <stdio.h>
int main() {
omp_set_num_threads(4);
int numt;
#pragma omp parallel default(shared)
{
int tid;
// more conventional way of work to be done by single thread
// when no wait is claused, one thread will execute single region and synchronization is removed.
// nowait is generally used to rmeove implicit barriers created by worksharing constructs.
#pragma omp single nowait
{
// single is implicit barrier whereas barrier is explicit one.
for(int j=0; j<100000000; j++);
numt = omp_get_num_threads();
}
tid = omp_get_thread_num();
// because using two parallel regions is simly a overhead, we use barrier.
// #pragma omp barrier
// removing barrier because single construct is used.
printf("Thread ID: %d of %d\n", tid, numt);
}
}