views:

46

answers:

1

The program below crashes when I build it in Release x64 (all other configurations run fine).

Am I doing it wrong or is it an OpenMP issue? Well-grounded workarounds are highly appreciated.

To reproduce build a project (console application) with the code below. Build with /openmp and /GL and (/O1 or /O2 or /Ox) options in Release x64 configuration. That is OpenMP support and C++ optimization must be turned on. The resulting program should (should not) crash.

#include <omp.h>
#include <vector>

class EmptyClass
  {
  public:
    EmptyClass() {}
  };

class SuperEdge
  {
  public:
    SuperEdge() {mp_points[0] = NULL; mp_points[1] = NULL;}

  private:
    const int* mp_points[2];
  };

EmptyClass CreateEmptyClass(SuperEdge s)
  {
  return EmptyClass();
  }

int main(int argc, wchar_t* argv[], wchar_t* envp[])
  {
  std::vector<int> v;
  long count = 1000000;

  SuperEdge edge;
  #pragma omp parallel for 
  for(long i = 0; i < count; ++i)
    {
    EmptyClass p = CreateEmptyClass(edge);
    #pragma omp critical
       {
       v.push_back(0);
       }
    }

  return 0;
  }
A: 

I think it is a bug. Looking at the ASM output with /O2 on the push_back call has been optimized away and there are just a couple of reserve calls and what looks like direct accesses instead. The reserve calls however don't appear to be in the critical section and you end up with Heap corruption. Doing a release x64 with /openmp /GL /Od you will see that there is a call to push_back in the asm, and it is between the _vcomp_enter_critsect calls, and doesn't crash. I'd report it to MS. (tested with VS 2010)

jcopenha
Thank you, I did report it: https://connect.microsoft.com/VisualStudio/feedback/details/606013/openmp-release-x64-crash-in-critical-section
Antonio