此问题特定于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)