Skip to content

Instantly share code, notes, and snippets.

@alinush
Created July 22, 2018 21:49
Show Gist options
  • Save alinush/80876151f45cd7b91ccec76d39ea9ebd to your computer and use it in GitHub Desktop.
Save alinush/80876151f45cd7b91ccec76d39ea9ebd to your computer and use it in GitHub Desktop.
Checking some OpenMP code
// 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