简体   繁体   中英

Visual Studio C++ 2015 and openMP

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM