Patent ID: 7590977

Claim:
A method for accessing threadprivate memory for a first set of threadprivate variables in a parallel program during program compilation, the method comprising: building a call graph for a program, using a processor, wherein a node is created in the call graph for each procedure in the program and a region node is created for each region in the program; classifying a first set of threadprivate variables in the program into a second set of threadprivate variables and a third set of threadprivate variables, wherein the second set of threadprivate variables require a static initialization and the third set of threadprivate variables do not require the static initialization; performing a traversal of the call graph; responsive to traversing a node that represents a defined procedure, replacing references to a fourth set of threadprivate variables in the defined procedure with a set of indirect references using a set of base addresses of the fourth set of threadprivate variables; responsive to the node being a region node, a main procedure node or the node representing a procedure called by an undefined procedure, moving address load operations of the threadprivate variables within the procedure such that there is only one address load operation for each threadprivate variable in each control flow path; responsive to the node not being the region node, not being the main procedure node, and not being the node representing the procedure called by the undefined procedure, moving the address load operations of the threadprivate variables outside of the procedure using an inter-procedural code motion; replacing, in a memory, the address load operations of the threadprivate variables with calls to runtime routines to access the threadprivate memory; and generating a unique structured data for each threadprivate variable from the first set of threadprivate variables to pass to the runtime routine calls to obtain threadprivate memory addresses, wherein each of the unique structured data includes an address of a static copy of an associated threadprivate variable and a static initialization for the associated threadprivate variable.