[Omp] Working with threadprivate elements of structs
Shah, Sanjiv
sanjiv.shah at intel.com
Thu Jan 15 09:43:52 PST 2004
Clay,
Yes, this should be sufficient. The only other thing to worry about is
to guarantee persistence of the threadprivate's across multiple parallel
regions. If you disable omp_dynamic (as Andrey suggested) and keep the
number of threads in all the regions the same, you will have this
guarantee.
Sanjiv
--
Sanjiv, 217-403-4244
_____
From: Breshears, Clay
Sent: Tuesday, January 13, 2004 10:56 AM
To: Shah, Sanjiv; 'omp at openmp.org'
Subject: RE: [Omp] Working with threadprivate elements of structs
Sanjiv -
Okay, that make sense. If I initialized the static_ltree with a static
initializer, used a NULL in the l_desc initialization, and then stored
the address of static_ltree in l_desc within a parallel region, would
this set up the correct address and threadprivates that I need?
Example code:
ct_data static_ltree[100] = { {0,0} }; //init one element to force use?
#pragma omp threadprivate (static_ltree)
typedef struct tree_desc {
ct_data *tree;
int max_length;
int max_code;
} tree_desc;
tree_desc l_desc = {NULL, MAX_LEN, 0};
#pragma omp threadprivate (l_desc)
#pragma omp parallel
l_desc.tree = static_ltree; //threadprivate address into
threadprivate?
-----Original Message-----
From: Shah, Sanjiv
Sent: Friday, January 09, 2004 6:12 PM
To: Breshears, Clay; omp at openmp.org
Subject: RE: [Omp] Working with threadprivate elements of
structs
Clay,
Addresses of threadprivate objects are not constant, so as soon
as you make static_ltree threadprivate, you will not be able to use it
in the structure initialization for l_desc. You will have to initialize
the tree field with NULL and then use a dummy parallel region, as you
suggest, to set up the correct linkages. The code should be just a
simple assignment in the parallel region.
Sanjiv
--
Sanjiv, 217-403-4244
_____
From: Omp-bounces at openmp.org [mailto:Omp-bounces at openmp.org] On
Behalf Of Breshears, Clay
Sent: Friday, January 09, 2004 5:45 PM
To: omp at openmp.org
Subject: [Omp] Working with threadprivate elements of structs
I need to have a threadprivate array that is pointed to by a
threadprivate struct. How do I declare and initialize these so they all
refer to the correct versions?
In a C code, I have an array that needs to be threadprivate.
The original serial code also includes a struct (used as a descriptor to
carry additional information about the array and its contents) that is
also used as a parameter to some function calls. The fields of the
descriptor instances are statically initialized at declaration time.
For example, the serial code looks something like:
ct_data static_ltree[100];
typedef struct tree_desc {
ct_data *tree;
int max_length;
int max_code;
} tree_desc;
tree_desc l_desc = {static_ltree, MAX_LEN, 0};
If I put in pragmas to set static_ltree and l_desc to be
threadprivate, how can I guarantee that each thread's copy of
static_ltree will be pointed to by that same thread's copy of l_desc?
Do I need to use a "dummy" parallel region to access static_ltree and
initialize l_desc in parallel to make sure the desired linkage occurs?
Does the static initialization of l_desc suffice to hook things up
correctly? Is there a better or simpler way?
Thanks in advance for any help or advice.
clay
--
Clay Breshears
Parallel Applications Engineer
KAI Software Labs, a division of Intel Americas, Inc.
phone: 217-403-4206 fax: 217-403-4399
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.openmp.org/pipermail/omp/attachments/20040115/2a32c763/attachment.html
More information about the Omp
mailing list