Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3973878
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T04:30:08+00:00 2026-05-20T04:30:08+00:00

In a member function, I can parallelize using the shared member variable int *x

  • 0

In a member function, I can parallelize using the shared member variable int *x like this

#pragma omp parallel for default(shared)
for(int i=0;i<size;i++) {
  x[i]=i;
}

But if I try

#pragma omp parallel for default(none) shared(x,size)
for(int i=0;i<size;i++) {
  x[i]=i;
}

I get the error: 'obj::x' is not a variable in clause 'shared'.
I would prefer the second version because it announces the shared variables it is working with, reminding me to make sure there are no race conditions or similar problems.

What is going on that OpenMP claims that obj::x is not a variable?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T04:30:09+00:00Added an answer on May 20, 2026 at 4:30 am

    Most implementations of OpenMP outline the parallel region. That is, they make it a function. Private variables are generally passed to this function and shared variables may be passed or be within the function’s scope. The problem with class data members is that they are not the same as variables.

    When the compiler outlines a parallel region, variables have storage locations defined that the compiler can set up to pass to the function. Data members may not be instantiated (i.e., storage allocated) until the class is called during execution of the program. This means that the compiler cannot privatize data members by itself. It would also have to be done in the runtime and this would cause a lot more work and would affect performance of both serial and parallel programs. So far no implementation has tried to do this work and since the OpenMP spec is written by consensus the decision was made to disallow data members in all clauses. Otherwise, it seemed too confusing to say that they are allowed in shared clauses, but no other clause.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can I link a member function like this in some way? redeclaring the method
I have an inline member function defined under class MyClass int MyClass::myInlineFunction(); This function
I'm trying to store member function pointers by templates like this: (This is a
So how i can do this? So that no member function can change the
Using SFINAE, i can detect wether a given class has a certain member function.
The assignment operator can be overloaded using a member function but not a non-member
I need an array to hold member-function-pointers of different classes. How can I define
I have class with a member function that takes a default argument. struct Class
In C++, can member function pointers be used to point to derived (or even
How can I go about determining return type of a member generic function? template<class

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.