OpenMP - yszheda/wiki GitHub Wiki

version

Ranged for

#pragma omp parallel
{
   #pragma omp single
   {
      for (auto x : stl_container)
      {
         #pragma omp task
         {
            // Do something with x, e.g.
            compute(x);
         }
      }
   }
}

cancel

reduction

#include <iostream>
#include <cmath>

int main(){
    double sum_i = 0, max_i = -1;
    #pragma omp parallel for reduction(+:sum_i) reduction(max:max_i)
    for (int i=0; i<5000; i++){
        sum_i += i;
        if (i > max_i)
            max_i = i;
    }
    std::cout << "Sum = " << sum_i << std::endl;
    std::cout << "Max = " << max_i << std::endl;
    return 0;
}

custom reduction

nested loop

CMake

_OPENMP

#if defined(_OPENMP)
   #pragma omp ...
#endif
diff <(cpp -dM -fopenmp </dev/null) <(cpp -dM </dev/null)

Thread Pool

Profile

Environment Variables

OMP_NUM_THREADS

OMP_THREAD_LIMIT

Trouble-shooting

-lgomp

⚠️ **GitHub.com Fallback** ⚠️