Unique addresses with threadprivate?

General OpenMP discussion

Unique addresses with threadprivate?

Postby PGK » Fri Sep 07, 2012 7:09 am

I had thought that a threadprivate variable within a parallel region would have a unique address for each thread. With code based on the following, I often see duplicate addresses. Am I on the right track? Is this a bug in the implementation?

Code: Select all
int main(int argc, char *argv[])
{
  static int x;
  #pragma omp threadprivate(x)

  omp_set_nested(true);
  omp_set_num_threads(4);

  #pragma omp parallel
  {
    #pragma omp parallel
    {
      printf("%p\n", &x);
    }
  }
  return 0;
}
PGK
 
Posts: 5
Joined: Thu Jan 28, 2010 7:38 am

Re: Unique addresses with threadprivate?

Postby MarkB » Mon Sep 10, 2012 3:50 am

Hi there,

Seeing duplicate addresses does suggest a bug, but given some of the devious trickery which is used for some implementations of threadprivate, I would not be 100% certain. Can you actually observe race conditions (e.g. by assigning a unique value to x for every thread)? Which implmentation(s) are you suspicious of?

Mark.
MarkB
 
Posts: 428
Joined: Thu Jan 08, 2009 10:12 am

Re: Unique addresses with threadprivate?

Postby PGK » Wed Sep 12, 2012 2:53 am

Hi,

I assigned x to gnum using the code below, and still see the duplicates.

Code: Select all
int lvl      = omp_get_level();
int anum     = omp_get_ancestor_thread_num(lvl-1);
int nthreads = omp_get_num_threads();
int gnum     = (anum*nthreads)+omp_get_thread_num();
x            = gnum;


The compiler was GCC 4.5.3 under cygwin. I also tried GCC 4.6.3 and GCC 4.8.0 20120902 (experimental) under a single-core Ubuntu virtual machine, and neither has the bug.

Cheers,
Paul
PGK
 
Posts: 5
Joined: Thu Jan 28, 2010 7:38 am


Return to Using OpenMP

Who is online

Users browsing this forum: Google [Bot] and 14 guests