Created
July 22, 2018 21:49
-
-
Save alinush/80876151f45cd7b91ccec76d39ea9ebd to your computer and use it in GitHub Desktop.
Checking some OpenMP code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Compile with: g++ -fopenmp /tmp/lol.cpp && ./a.out | |
// Set number of threads: export OMP_NUM_THREADS=16 | |
// Expected behaviour: should print a = 1, b = 2 and only two different threads should launch | |
#include <iostream> | |
#include <omp.h> | |
using namespace std; | |
int main() { | |
int a = 0, b = 0; | |
#pragma omp parallel sections | |
{ | |
#pragma omp section | |
{ | |
cout << "1st section TID: " << omp_get_thread_num() << endl; | |
a = 1; | |
} | |
#pragma omp section | |
{ | |
cout << "2nd section TID: " << omp_get_thread_num() << endl; | |
b = 2; | |
} | |
} | |
cout << "a = " << a << ", b = " << b << endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment