brain of mat kelcey...


openmp = easy multi threading

October 13, 2008 at 11:30 AM | categories: Uncategorized

openmp is a compiler library, available in gcc since v4.2, for giving hints to a compiler about where code can be parallelized.

say we have some code

1
2
for(int i=0; i<HUGE_NUMBER; ++i)
  deadHardCalculation(i)

we can make this run on multi threaded by simply adding some pragmas

1
2
3
4
5
6
#pragma omp parallel num_threads(4)
{
  #pragma omp for
  for(int i=0; i&lt;HUGE_NUMBER; ++i)
    deadHardCalculation(i);
}

compiling with -fopenmp will generate an app that splits the work of the for loop across 4 threads.

there’s support for dynamic / static scheduling, accumulators, all sorts

this tute is awesome.

it increased the speed of my shingling code by 350% on a quad core box with just the above two lines