使用 OpenMP 的程序崩溃,仅限 x64 [英] Crash in program using OpenMP, x64 only

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

问题描述

当我在 Release 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天全站免登陆