Parallel Programming Guide for HP-UX Systems

Memory classes
Memory class assignments
Chapter 7 129
Static assignments
Static memory class assignments are physically located with variable
type declarations in the source. Static memory classes are typically used
with data objects that are accessed with equal frequency by all threads.
These include objects of the thread_private and node_private classes.
Static assignments for all classes are explained in the subsections that
follow.
thread_private
Because thread_private variables are replicated for every thread,
static declarations make the most sense for them.
Example 7-1 thread_private
In Fortran, the thread_private memory class is assigned using the
THREAD_PRIVATE compiler directive, as shown in the following example:
REAL*8 TPX(1000)
REAL*8 TPY(1000)
REAL*8 TPZ(1000), X, Y
COMMON /BLK1/ TPZ, X, Y
C$DIR THREAD_PRIVATE(TPX, TPY, /BLK1/)
Each array declared here is 8000 bytes in size, and each scalar variable
is 8 bytes, for a total of 24,016 bytes of data. The entire COMMON block
BLK1 is placed in thread_private memory along with TPX and TPY. All
memory space is replicated for each thread in hypernode-local physical
memory.
Example 7-2 thread_private
The following C/C++ example demonstrates several ways to declare
thread_private storage. The data objects declared here are not scoped
analogously to those declared in the Fortran example:
/* tpa is global: */
thread_private double tpa[1000];
func() {
/* tpb is local to func: */
static thread_private double tpb[1000];
/* tpc, a and b are declared elsewhere: */
extern thread_private double tpc[1000],a,b;
.
.
.