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
for(int i=0; i<HUGE_NUMBER; ++i) deadHardCalculation(i);
we can make this run on multi threaded by simply adding some pragmas
#pragma omp parallel num_threads(4)
{
#pragma omp for
for(int i=0; i<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