OpenMP循环中的数据成员 [英] data members in an OpenMP loop

查看:165
本文介绍了OpenMP循环中的数据成员的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下课程:

Class L{
    public:
    bool foo(vector<bool> & data);
    private:
    C** cArray;
}

,并希望在创建L对象并初始化cArray中的所有元素之后并行化名为somtime的函数foo中的for循环.

and would like to parallelize the for loop in the function foo which is called somtime after an object of L is created and all the elements in cArray are initialized.

bool L::foo(vector<int> & data){
int row, col;
#pragma omp parallel shared(SIZE, cArray, data) private(row, col)
    for (row=0, row<SIZE; ++row)
    {
        for (col=0; col<SIZE; ++col)
        {
            cArray[row][col].computeScore(data);
        }
    }
}    

但是这给出了一个错误: 错误C3028:"L :: cArray":数据共享子句中只能使用变量或静态数据成员.

But this gives an error: error C3028: 'L::cArray' : only a variable or static data member can be used in a data-sharing clause.

假设我不想使cArray静态化,有什么可以做的吗?

Is there anything that can be done about this assuming I don't want to make cArray static?

推荐答案

这个问题之前已经提出过好几次了.问题在于,类数据成员可能无法在编译时实例化.如果它们是共享的,那么就没有问题,因为变量在OpenMP中是默认共享的(除非您将默认值更改为private-在C中是不能做到的-否则就没有).但是,如果将它们定义为私有,则编译器需要知道如何制作私有副本,并且此信息在编译时并不总是可用.

This question has come up several times before. The problem is, that class data members may not be instantiated at compile time. If they are being shared, then there is no problem, because variables are shared by default in OpenMP (unless you change the default to private - which you can't do in C - or none). However, if they are defined as private, then the compiler needs to know how to make private copies and this information is not always available at compile time.

不幸的是,如果您希望对所有数据进行范围调整(使用显式数据作用域子句),那么您将遇到问题.作用域子句只能处理变量,而类数据成员则不能.只要默认值保持共享状态,就不理会任何数据作用域子句.如果希望它们是私有的,那么您很不走运,需要将类数据成员定义为变量.不幸的是,由于OpenMP并不是基本语言的一部分,因此我认为这不会很快改变.

Unfortunately, if you want to scope all your data (using explicit data scoping clauses), which you should, then you have a problem. The scoping clauses can only handle variables - which class data members aren't. Leaving them off any data scoping clause works as long as the default remains shared. If you want them to be private, then you are out of luck and need to define the class data members as variables. Unfortunately, since OpenMP is not part of the base language, I don't see this changing anytime soon.

这篇关于OpenMP循环中的数据成员的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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