小编vaz*_*xqi的帖子

通过Openmp任务访问实例变量(隐式firstprivate)时出现分段错误

此问题特定于OpenMP 3.0中的任务构造及其对C++的隐式firstprivate的使用.我正在寻找问题的解释以及可能的解决方案.

我正在处理的程序有一些分段错误; 我设法将问题减少到以下测试用例.

出现此问题是因为我正在访问a中的实例变量(对象A) #pragma omp task

#include <iostream>
#include <omp.h>

using namespace std;

class A {
private:
  int someInstanceVariable;

public:
    // This is never called
  A(int _someInstanceVariable) {
    someInstanceVariable = _someInstanceVariable;
  }

  A(const A& _A) {
    cout << "Copy constructor called" << endl;
    someInstanceVariable = _A.someInstanceVariable;
  }

  void simpleTask() {
    // This task makes a reference to someInstanceVariable in the current object
    #pragma omp task
    { 
      // For access to stdout
      #pragma omp critical
      {
        // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
        // …
Run Code Online (Sandbox Code Playgroud)

c++ parallel-processing task openmp segmentation-fault

6
推荐指数
1
解决办法
1649
查看次数