I can write some code that looks like this:
if (make_parallel)
{
#pragma omp parallel for
for (int i=0; i<n; i++)
{
//For loop stuff
}
}
else
{
//Identical for loop, minus the parallelisation
for (int i=0; i<n; i++)
{
//For loop stuff
}
}
Is there a tidier way of doing this, such that the for loop doesn't have to be duplicated?
[Edit] - So this solution works at the preprocessing level
#define USE_OPENMP
//...
#ifdef USE_OPENMP
#pragma omp parallel for
#endif
for(int i=0;i<n;i++)
But that isn't ideal. But the more I think about it, since defining the parallel region is also preprocessing it probably can't be made conditional in a tidy way?