[Omp] Working with threadprivate elements of structs
Shah, Sanjiv
sanjiv.shah at intel.com
Fri Jan 9 16:12:07 PST 2004
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/20040109/630f971b/attachment.html
More information about the Omp
mailing list