Skip to content

Instantly share code, notes, and snippets.

@AbhiAgarwal
Created June 20, 2014 06:50
Show Gist options
  • Save AbhiAgarwal/262351f1e68d051fab6f to your computer and use it in GitHub Desktop.
Save AbhiAgarwal/262351f1e68d051fab6f to your computer and use it in GitHub Desktop.
// run using g++-mp-4.7 -fopenmp -std=c++11 openmp_example.cpp -o openmp_example
// on my mac. Not sure about everyone elses, but my g++ version doesn't have openp
// so I have to use that one
#include <iostream>
using namespace std;
#include <omp.h>
int main(int argc, char *argv[])
{
int th_id, nthreads;
#pragma omp parallel private(th_id) shared(nthreads)
{
th_id = omp_get_thread_num();
#pragma omp critical
{
cout << "Hello World from thread " << th_id << '\n';
}
#pragma omp barrier
#pragma omp master
{
nthreads = omp_get_num_threads();
cout << "There are " << nthreads << " threads" << '\n';
}
}
return 0;
}
@AbhiAgarwal
Copy link
Author

stupid program - got stuck at g++ for so long

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment