使用OpenMP(仅x64)在程序中崩溃 [英] Crash in program using OpenMP, x64 only

查看:158
本文介绍了使用OpenMP(仅x64)在程序中崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在x64发行版中构建该程序时,以下程序崩溃(所有其他配置都可以正常运行)。

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

我做错了还是OpenMP问题?
非常感谢有充分基础的解决方法。

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

使用以下代码重现构建项目(控制台应用程序)。
在Release x64配置中使用/ openmp和/ GL以及(/ O1或/ O2或/ Ox)选项进行构建。
这是OpenMP支持,必须打开C ++优化。产生的程序应该(不应)崩溃。

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;
  }


推荐答案

我认为这是一个错误。在push_back调用中使用/ O2查看ASM输出已被优化,只有几个保留调用,而看起来像直接访问。但是,备用电话似乎不在关键部分,最终导致堆损坏。使用/ openmp / GL / Od发行x64版本,您会看到在asm中有一个push_back调用,它在_vcomp_enter_critsect调用之间,并且不会崩溃。我会报告给MS。 (已在VS 2010中进行了测试)

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)

这篇关于使用OpenMP(仅x64)在程序中崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆