简体   繁体   English

OpenMP和C ++:这个指针

[英]OpenMP and C++: this pointer

Is this pointer always shared in OpenMP? this指针是否始终在OpenMP中共享?

Compiler does not complain about following code, despite default(none) : 尽管default(none) ,编译器不会抱怨以下代码:

#pragma omp parallel for default(none), shared(n)
for ( SInt i = 0; i < n; ++i )
{
    f( i, this );  // f is some function.
}

The OpenMP standard defines data-sharing attribute rules for variables referenced in your code. OpenMP标准为代码中引用的变量定义数据共享属性规则。 Anyhow, according to the C++ standard draft (n3242 9.3.2) this is not a variable but a prvalue expression (emphasis mine): 无论如何,根据C ++标准草案(n3242 9.3.2), this不是一个变量,而是一个prvalue表达式 (强调我的):

In the body of a non-static (9.3) member function, the keyword this is a prvalue expression whose value is the address of the object for which the function is called. 在非静态(9.3)成员函数的主体中, 关键字this是一个prvalue表达式,其值是调用该函数的对象的地址。 The type of this in a member function of a class X is X*. 类X的成员函数中的类型是X *。 If the member function is declared const, the type of this is const X*, if the member function is declared volatile, the type of this is volatile X*, and if the member function is declared const volatile, the type of this is const volatile X*. 如果成员函数声明为const,则其类型为const X *,如果成员函数声明为volatile,则其类型为volatile X *,如果成员函数声明为const volatile,则此类型为const挥发性X *。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM