Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenMP and C++: this pointer

Tags:

c++

openmp

Is this pointer always shared in OpenMP?

Compiler does not complain about following code, despite default(none):

#pragma omp parallel for default(none), shared(n)
for ( SInt i = 0; i < n; ++i )
{
    f( i, this );  // f is some function.
}
like image 869
user2052436 Avatar asked Sep 19 '26 07:09

user2052436


1 Answers

The OpenMP standard defines data-sharing attribute rules for variables referenced in your code. Anyhow, according to the C++ standard draft (n3242 9.3.2) this is not a variable but a prvalue expression (emphasis mine):

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. The type of this in a member function of a class X is 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*.

like image 87
Massimiliano Avatar answered Sep 20 '26 19:09

Massimiliano



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!