-
Notifications
You must be signed in to change notification settings - Fork 1
/
sectionsOpenMP.cpp
32 lines (26 loc) · 994 Bytes
/
sectionsOpenMP.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
#include <iostream>
#include <omp.h>
using namespace std;
// compile with: g++ -fopenmp sectionsOpenMP.cpp -o sectionsOpenMP
int main(){
#pragma omp parallel // starts a new team of threads
{
int myID = omp_get_thread_num();
cout << "I'm the 0th chunk on thread " << myID << "." << endl; // should get run by each thread
#pragma omp barrier // if we include this, all the 0th reports should happen first
#pragma omp sections // divides the team into sections
{
// everything herein is run only by a single thread
#pragma omp section
{ cout << "I'm the 1st chunk on thread " << myID << "." << endl; }
#pragma omp section
{
cout << "I'm the 2nd chunk on thread " << myID << "." << endl;
cout << "I'm the 3rd chunk on thread " << myID << "." << endl;
}
#pragma omp section
{ cout << "I'm the 4th chunk on thread " << myID << "." << endl; }
} // implied barrier
}
return 0;
}