Visual Studio C++ 2015 and openMP

891 views Asked by At

I want to know the behaviour of the VC++ compiler with /openmp. I'm using a third party library (OpenMVG) that comes with the cmakefilelist. So I generated the Visual Studio solution to compile it. CMake recognizes the openmp capability of the compiler and in VS everithing compiles fine. But when it comes to execution, I get different results everythime I run the program. And if I run 2 instances of the program at the same time, the results are even worse. So I looked a little bit inside the source code and I found out that openmp is used with list and map iterators

#pragma omp parallel
for (Views::const_iterator iter = sfm_data.GetViews().begin(); iter != sfm_data.GetViews().end() && bContinue; ++iter)
{
  pragma omp single nowait
  { 
    ... process ... 
  }
}

I searched on the web and it seems that Visual Studio only supports openMP 2.0. So does it support list iterators? Can this be the problem? How does openMP 2.0 behave with list iterators?

Thanks in advance fo any answer

1

There are 1 answers

7
MSalters On

The code doesn't do what you probably think it does. It creates a set of threads, each of which executes that same loop.

Note that OpenMP in Visual Studio doesn't really support C++, it treats it as a C dialect. In particular, /openmp doesn't support iterators, since that's C++ only. It only supports (some) C loops.

Also note that OpenMP is an old standard, predating even C++98. Since C++11, C++ has native threading capabilities.