-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsection.cpp
39 lines (37 loc) · 1.25 KB
/
section.cpp
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 <iostream>
#include <omp.h>
int main(int argc,char* argv[])
{
int thread_count = atoi(argv[1]);
#pragma omp parallel num_threads(thread_count)
{
#pragma omp sections
{
#pragma omp section
{
int my_rank = omp_get_thread_num();
int thread_count = omp_get_num_threads();
printf("hello from thread %d of %d in section 1.\n",my_rank,thread_count);
}
#pragma omp section
{
int my_rank = omp_get_thread_num();
int thread_count = omp_get_num_threads();
printf("hello from thread %d of %d in section 2.\n",my_rank,thread_count);
}
#pragma omp section
{
int my_rank = omp_get_thread_num();
int thread_count = omp_get_num_threads();
printf("hello from thread %d of %d in section 3.\n",my_rank,thread_count);
}
#pragma omp section
{
int my_rank = omp_get_thread_num();
int thread_count = omp_get_num_threads();
printf("hello from thread %d of %d in section 4.\n",my_rank,thread_count);
}
}
}
return 0;
}