A question ablout A.25.3c (threadprivate with global var)

General OpenMP discussion

A question ablout A.25.3c (threadprivate with global var)

Postby TRX2 » Mon Aug 04, 2008 4:57 am

The code following :

Code: Select all
class T {
  public:
    int val;
    T (int);
    T (const T&);
};
T :: T (int v){
   val = v;
}
T :: T (const T& t) {
   val = t.val;
}
void g(T a, T b){
   a.val += b.val;
}

int x = 1;
T a(x);
const T b_aux(x); /* Capture value of x = 1 */
T b(b_aux);
#pragma omp threadprivate(a, b)

void f(int n) {
   x++;
   #pragma omp parallel for
   /* In each thread:
    * a is constructed from x (with value 1 or 2?)
    * b is copy-constructed from b_aux
    */
   for (int i=0; i<n; i++) {
       g(a, b); /* Value of a is unspecified. */
   }

  int main{
    f(10);
  }


}



my gcc version is 4.1.2

when I use "g++ A.25.3c.cpp -fopenmp" to compile the code

I get two error :
A.25.1c.cpp:27: error: [a] declared [threadprivate] after first use
A.25.1c.cpp:27: error: [b] declared [threadprivate] after first use

even if I want to declare a int to be threadprivte there still the same error message ??

how to avoid this kind of erroe ??

------

I am a new to openMP and using broken English,
Would someone tell me how to learn better :)
TRX2
 

Re: A question ablout A.25.3c (threadprivate with global var)

Postby ejd » Tue Aug 05, 2008 5:41 am

This seems to be a gcc error. You might try reporting it to the gcc developers.

If you are asking about learning OpenMP better, there are a couple of books and numerous presentations that you can find that can help. If you are asking about learning English better, I am afraid that all I can suggest is looking to see if there are any classes in your area. The best way to learn either would be by use (in my opinion).
ejd
 
Posts: 1025
Joined: Wed Jan 16, 2008 7:21 am


Return to Using OpenMP

Who is online

Users browsing this forum: No registered users and 7 guests