Method of, system for, and computer program product for providing inlined nested array constructors using normalized counters5845126Abstract Method of, system for, and computer program product for generating efficient code for a set of nested Fortran 90 array constructors without introducing temporary vectors by the use of normalized counters and by maintaining array constructor extent structure trees. Non-perfectly nested array constructors and array constructors with dynamic extents may be inlined. The results provided include a reduction in run-time memory storage usage and an improvement in execution time performance. Claims We claim: Description A portion of the Disclosure of this patent document contains material which is subject to copyright protection. The copyright owner has no objection to the facsimile reproduction by anyone of the patent document or the patent disclosure, as it appears in the Patent and Trademark Office patent file or records, but otherwise reserves all copyright rights whatsoever.
______________________________________
array-constructor:
(/ac-value-list/)
ac-value-list:
ac-value-list, ac-value
ac-value: expr or ac-implied-do
ac-implied-do:
(ac-value-list, ac-implied-do-control)
ac-implied-do-control:
ac-do-variable = scalar-int-expr, scalar-int-expr
{, scalar-int-expr}
ac-do-variable:
scalar-int-variable
______________________________________
An example of an array constructor is X=(/3.2, 4.01, 6.5/) which constructs the following array: X=›3.2 4.01 6.5!. Another example of an array constructor is Y=(/(1.0*I, I=1,99),X/) which constructs the following array: Y=›1 2 3 . . . 98 99 3.2 4.01 6.5!. Generation of efficient code by a compiler for an expression containing an array constructor is non-trivial because of the combination of various complicated expressions in ac-value-lists. The following example of Table A may be used to show the varying effectiveness of different approaches for processing array constructors to generate code:
TABLE A
______________________________________
a(2:12:2) = d(1:16:3)+(/20.0,c(2:8:3)+(/0.0,b(3:4)/),(10.0*i,i=2,3)/)
______________________________________
The array constructor of Table A generates the following array of Table B:
TABLE B
______________________________________
a = ›20.0+d(1) c(2)+d(4) b(3)+c(5)+d(7) b(4)+c(8)+d(10) 20.0+d(13)
30.0+d(16)!
______________________________________
A straight-forward approach to process array constructors according to conventional teachings is to split every array constructor and implied-do, and to create a temporary vector. This approach generates the following code of Table C:
TABLE C
______________________________________
j1 = 1
r1(j1) = 0.0
do i1 = 1,2
j1 = j1 + 1
r1(j1) = b(il+2)
enddo
j2 = 0
do i = 2,3
j2 = j2 + 1
r2(j2) = 10.0 * i
enddo
j3 = 1
r3(j3) = 20.0
do i3 = 1,3
j3 = j3 + 1
r3(j3) = c(3*i3-1) + r1(i3)
enddo
do i3 = 1,3
j3 = j3 + 1
r3(j3) = r2(i3)
enddo
do i4 = 1,6
a(2*i4) = d(3*i4-2) + r3(i4)
enddo
______________________________________
The main disadvantage of this straight forward approach is the excessive use of temporary storage. In the example of Table C, three temporary vectors are created: r1 with 2 elements, r2 with 3 elements, and r3 with 6 elements. In an application with large sets of data, the excessive temporary vectors may deteriorate memory locality, which in turn may degrade execution time performance. Another approach is the single index variable approach which splits non-perfectly nested array constructors. This single index variable approach may use less temporary storage. The following code of Table D is generated from the preprocessor with unrelated optimizations removed for clarity:
TABLE D
______________________________________
j2 = 0
j2 = j2 + 1
r1(j2) = 0.0
do i2 = 1,2
j2 = j2 + 1
r1(j2) = b(i2+2)
enddo
j3 = 0
j3 = j3 + 1
r2(j3) = 20.0
do i3 = 1,2
j3 = j3 + 1
r2(j3) = c(2) + r1(1)
enddo
do i = 2,3
j3 = j3 + 1
r2(j3) = 10.0*i;
enddo
do j1 = 1, 6
a(j1*2) = d(j1*3-2) + r2(j1)
end do
______________________________________
The single index variable approach reduces the number of temporary vectors from three to two: r1 with 3 elements and r2 with 6 elements. However, this approach can only inline perfectly nested array constructors, in which each ac-value can only be an array constructor, implied-do, or an expression containing no array constructors. In this example, the array constructor in c(2:8:3)+(/0.0,b(3:4)/), is not perfectly nested. These conventional approaches are unable to inline non-perfectly nested array constructors. These conventional approaches also have difficulties generating correct code for array constructors with dynamic extents. In view of the above performance, efficiency, and functional deficiencies of traditional systems, there is a need for a method of, system for, and computer program product for generating efficient code for a set of nested Fortran 90 array constructors. SUMMARY OF THE INVENTION The invention disclosed herein comprises a method of, system for, and computer program product for generating efficient code for a set of nested Fortran 90 array constructors without introducing temporary vectors by the use of normalized counters and by maintaining array constructor extent structure trees. The results of this new array constructor process are a considerable reduction in run-time memory storage usage and an improvement in execution time performance. Although the example of Table A contains non-perfectly nested array constructors, a compiler using the present invention can generate the following efficient code of Table E with all temporary vectors removed:
TABLE E
______________________________________
nc1 = 1
a(2*ncl) = d(3*ncl-2) + 20.0
ncl = nc1+1
nc2 = 1
a(2*nc1) = d(3*nc1-2) + c(3*nc2-1) + 0.0
do j = 1,2
nc1 = nc1+1
nc2 = nc2 + 1
a(2*nc1=d(3*nc1-2)+c(3*nc2-1)+b(j+2)
enddo
do I = 2,3
nc1 = nc1+1
a(2*nc1) = d(3*nc1-2) + 10.0*I
enddo
______________________________________
This resultant code removes temporary vectors and improves memory locality, which may lead to better execution time performance. In accordance with one aspect of the present invention, a normalized counter is used at each level of array constructors (ACs) while scalarizing an expression containing array constructors. In accordance with another aspect of the present invention, array constructor extent structures are maintained while scalarizing an expression containing array constructors. The present invention has the advantage of generating efficient code for nested Fortran 90 array constructors by avoiding temporary vectors. The present invention has the advantage of reducing the amount of run-time storage required to generate code for nested Fortran 90 array constructors. The present invention has the advantage of reducing the amount of execution time storage required to generate code for nested Fortran 90 array constructors. The present invention has the advantage of providing improved memory locality in the generation of code for nested Fortran 90 array constructors. The present invention has the advantage of generating in-lined code for non-perfectly nested Fortran 90 array constructors. The present invention has the advantage of generating in-lined code for Fortran 90 array constructors with dynamic extents. DESCRIPTION OF TEE DRAWINGS For a more complete understanding of the present invention and the advantages thereof, reference is now made to the Detailed Description in conjunction with the attached Drawings, in which: FIG. 1 shows a functional block diagram of an exemplary compiling method from the prior art; FIG. 2 shows a functional block diagram of an exemplary compiling optimization method from the prior art; FIG. 3 is a flowchart illustrating the operations preferred in carrying out the Procedure TreePruning portion of the present invention; FIG. 4 illustrates an expression, its corresponding expression tree, and its corresponding extent structure tree in accordance with the present invention; FIG. 5 is a flowchart illustrating the operations preferred in carrying out the Procedure BuildEST portion of the present invention; FIG. 6 is a flowchart illustrating the operations preferred in carrying out the Procedure ScarlarAC portion of the present invention; and FIG. 7 is a block diagram of a computer system used in performing the method of the present invention, forming part of the apparatus of the present invention, and which may use the article of manufacture comprising a computer-readable storage medium having a computer program embodied in said medium which may cause the computer system to practice the present invention. DESCRIPTION OF THE PREFERRED EMBODIMENT The key element of this invention is to apply a normalized counter at each level of array constructors (ACs) while scalarizing an expression containing array constructors. Two array constructors are said to be at the same level if they share the same nearest ac-value ancestor. For example, in (/ . . . , (/c(1),c(5:8:3)/)+(/0.0,b(3:4)/), . . . /), the two array constructors, (/c(1),c(5:8:3)/) and (/0.0,b(3:4)/), are at the same level. Some terminology is defined before further description. An "elemental operator" is such that each element of the target array is obtained as the operator applied to the corresponding element or pair of elements of the source. Examples of elemental operators are +, *, and SIN(). A "surrounding expression" of expression EXPR is defined as the subset of EXPR excluding all subtrees rooted at the top level array constructors. For example, the surrounding expression at the top level of the example of Table A is "a(2:12:2)=d(1:16:3)+". If the extent or number of elements of an array constructor or implied-do is expressed in terms of the variables defined before reaching the expression containing the array constructor or implied-do, this array constructor or implied-do has a "static" extent. Otherwise, this array constructor or implied-do has a "dynamic" extent. Scalarizing an expression can be loosely interpreted as removing the array constructs in the expression and creating semantically equivalent scalar code, often with enclosing iterative statements. Three sets of pseudo code in Tables H, I, and J describe the new process. The TreePruning procedure of Table H, whose flowchart is illustrated in FIG. 3, splits the array constructors determined not to be inlined. During a post order walk of an expression tree, ExprTree of an expression, if the current node, T, is an array constructor, an Extent Structure Tree (ST) is built to represent the raw structure of the extent of T. FIG. 4 illustrates the expression 410 of the example of Table A, its corresponding expression tree 420, and the Extent Structure Tree 430 of the array constructor 440. If T is the closest array constructor descendent of a non-elemental operator or the EST of T is not identical to the existing EST at the current array constructor level, a temporary vector is created, and T is split from the expression, ExprTree. The evaluation of the EST of T can obtain the required size of the temporary. If T is an non-elemental operator, it is also split from ExprTree, which is part of the general scalarization process. After the pruning process, if an expression still contains an array constructor, a normalized counter is created and ScalarizeAC() is invoked to scalarize the expression. Table J contains the pseudo code of ScalarizeAC() and its flowchart is illustrated in FIG. 6. Table I shows the BuildEST procedure, whose flowchart is illustrated in FIG. 5, which recursively constructs ESTs for a given expression. The EST of (/0.0,b(3:4)/) is:
TABLE F
______________________________________
/ .backslash.
1 2
______________________________________
This EST indicates that "0.0" has an extent of one, and that "b(3:4)" has an extent of two. The ESTs of (/c(1),c(5:8:3)/) and (/0.0,b(3:4)/) are identical. But the ESTs of (/c(5:8:3),c(1)/) and (/0.0,b(3:4)/) are different. The EST of the former (/c(5:8:3),c(1)/) is:
TABLE G
______________________________________
/ .backslash.
2 1
______________________________________
This EST indicates that "c(5:8:3)" has an extent of two, and that "c(1)" has an extent of one. Table J shows the pseudo code to of SclarizeAC, whose flowchart is illustrated in FIG. 6, which scalarizes an expression. A normalized counter at each level is used in scalarizing the surrounding expression at the current level. The normalized counter allows the correct array element references in the surrounding expression. It also maintains the correct references across different code segments generated for multiple ac-values. This counter is referred to as normalized because the increment of the counter is one. In ScalarizeAC(), the surrounding expression is scalarized using the passed normalized counter. A statement is generated to update the counter. Next the ac-value in each array constructor at the top level is found to obtain the referenced elements. Although the AC.sub.-- VALUE.sub.-- SET from different array constructors may have different constructs, e.g. an implied-do and a vector, the ESTs of the referenced element segments are the same because of a prior checking. Therefore, the ac-values in AC.sub.-- VALUE.sub.-- SET may be treated as having the same type of constructs. If the AC.sub.-- VALUE.sub.-- SET is an implied-do, a loop is generated accordingly. ScalarizeAC() is invoked recursively to scalarize the ac-value-list. If AC.sub.-- VALUE.sub.-- SET contains an array constructor, a new normalized counter is created for the next array constructor level. The normalized counter is passed for a recursive invocation of ScalarizeAC. If AC.sub.-- VALUE.sub.-- SET is an array expression, a loop nest is created accordingly and the expression is scalarized using the loop index variables. A scalarized expression, ScalarizedExpr.sub.-- SET, is attached to the surrounding expression at a proper node.
TABLE H
______________________________________
Pseudo Code to Prune a Parse Tree
______________________________________
TreePruning(expr ExprTree)
Get a node T from ExprTree based on a post order until all nodes are
visited {
if(T = AC) {
T.sub.-- EST = BuildEST(expr rooted at T);
if(T has an ancestor of non-elemental operator and-no other AC in
between, or T.sub.-- EST not identical to the current EST (if any) at
this AC
level) {
Split T and create a temporary vector, TempV;
Create a normalized counter NC1 and generate code for an
initialization;
ScalarizedExpr = ScalarizeAC(TempV = expr rooted at T, NC1);
Generate code for ScalarizedExpr;
} endif
}
else {
if(T = non-elemental operator)
Split T;
} endif
} enddo
if(ExprTree contains AC)
Create a normalized counter NC1 and generate code for an
initialization;
ScalarizeExpr = ScalarizeAC(ExprTree, NC1);
Generate code for ScalarizedExpr;
}
______________________________________
Some additional enhancements may be performed to improve the run time performance. A Fortran DATA statement may be used to replace a split array constructor assigned to a temporary vector if possible. For example, Temp.sub.-- Vect(1:3)=(/1,2,3/) can be replaced by DATA Temp.sub.-- VEct /1,2,3/ Another improvement is to replace a normalized counter by a constant if the value can be determined at compile time. With the new process and the enhancement, the following code may be generated for the example of Table A.
TABLE K
______________________________________
a(2) = d(1) + 20.0
a(4) = d(4) + c(2) + 0.0
nc2 = 1
nc1 = 2
do j = 1,2
nc1 = nc1+1
nc2 = nc2+1
a(2*nc1)=d(3*nc1-2)+c(3*nc2-1)+b(j+2)
enddo
do i = 2,3
nc1 = nc1+1
a(2*nc1) = d(3*nc1-2) + 10.0*i
enddo
______________________________________
The use of a normalized counter at each array constructor level eases the description. It is, however, often unnecessary to generate a normalized counter at every level, although induction variable substitution can eliminate some of these normalized counters. If the extents of all of the array constructors in the expression are static, only one normalized counter at the top level is required to be created and all of the other normalized counters can be represented in terms of the sole normalized counter. An additional normalized counter is required for an array constructor of a dynamic extent to keep track of the exact extent at run time. The inventors conducted experiments designed to compare the performance of the compiling method of the present invention with the existing art. One such experiment compiled the following Fortran 90 program of Table L:
TABLE L
______________________________________
real a(80002),b(50000),c(50005),d(80002)
do k = 1,20
a(1:80002) =
d(1:80002)+(/20.0,c(1:50001)+(/0.0,b(1:50000)/),(10.0*i,i=1,30000)/)
enddo
end
______________________________________
The results of the measurements performed on an "IBM RISC SYSTEM/6000" model 580 are listed below in Table M ("IBM" and "RISC SYSTEM/6000" are registered trademarks of International Business Machines Corporation):
TABLE M
______________________________________
Execution
Compiler used time (in user CPU seconds)
______________________________________
IBM XLF compiler with VAST-2
0.32
preprocessor
Compiler using present invention
0.20
______________________________________
Referring now to FIG. 3, FIG. 5, and FIG. 6, flowcharts illustrating operations preferred in carrying out the present invention are shown. In the flowcharts, the graphical conventions of a diamond for a test or decision and a rectangle for a process or function are used. These conventions are well understood by those skilled in the art, and the flowcharts are sufficient to enable one of ordinary skill to write code in any suitable computer programming language. The operations preferred in carrying out the present invention may be implemented as three routines or programs comprising a Procedure TreePruning, a Procedure BuildEST, and a Procedure ScalarizeAC. The Procedure TreePruning, illustrated in FIG. 3, splits an array constructor determined not to be inlined. The Procedure BuildEST, illustrated in FIG. 5, builds an Extent Structure Tree (EST) representing the structure of the extent of an array constructor. The Procedure ScalarizeAC, illustrated in FIG. 6, scalarizes an array constructor. Referring now to FIG. 3, which illustrates the operations preferred in carrying out the TreePruning Procedure 300 portion of the present invention, the process begins at process block 305. Thereafter, process block 310 gets a current node T from an ExprTree based on a postorder. Thereafter, decision block 315 determines if T is an array constructor. If T is an array constructor, then process block 320 sets T.sub.-- EST=BuildEST(expr rooted at T). Thereafter, decision block 325 determines if T has an ancestor of non-elemental operator and no other AC in between, or if T.sub.-- EST not identical to the current EST (if any) at this AC level). If this is true, then process block 330 splits T and creates a temporary vector, TempV. Thereafter, process block 335 creates a normalized counter NC1 and generates code for an initialization. Thereafter, process block 340 scalarizes TempV into ScalarizedExpr by calling ScalarizeAC(TempV=expr rooted at T, NC1). Thereafter, process block 345 generates code for ScalarizedExpr, the scalarized result returned by ScalarizeAC. Thereafter, decision block 350 determines if all nodes have been visited. If all nodes have been visited, then decision block 355 determines if ExprTree contains AC. If ExprTree contains AC, then process block 360 creates a normalized counter NC1 and generates code for an initialization. Thereafter, process block 365 scalarizes ExprTree into ScalarizedExpr by calling ScalarizeAC(ExprTree, NC1). Thereafter, process block 370 generates code for ScalarizedExpr. Thereafter, the process ends at process block 375. Returning now to decision block 355, if ExprTree does not contain AC, then the process ends at process block 375. Returning now to decision block 325, if T does not have an ancestor of non-elemental operator or there is another AC in between, and if T.sub.-- EST is identical to the current EST (if any) at this AC level, then processing continues to decision block 350 to determine if all nodes have been visited. Returning now to decision block 350, if all nodes have not been visited, then processing continues to process block 310 to get another node T based on the postorder. Returning now to decision block 315, if T not equal to AC, then decision block 380 determines if T is a non-elemental operator. If T is a non-elemental operator, then process block 385 splits T. Thereafter, processing continues to decision block 350 to determine if all nodes have been visited. Returning now to decision block 380, if T is not a non-elemental operator, then processing continues to decision block 350 to determine if all nodes have been visited. Referring now to FIG. 5, which illustrates the operations preferred in carrying out the BuildEST Procedure 500 portion of the present invention, the process begins at process block 505. Thereafter, process block 510 sets ExtentStructureTree EST equal to NULL. Thereafter, decision block 515 determines if ExprTree is an implied-do. If ExprTree is an implied-do, then process block 520 returns EST equal to the extent of implied-do and an extent structure tree based on the ac-value-list of the implied-do produced by a call to BuildEST. Thereafter, process block 545 begins a loop for every immediate AC in ExprTree. Thereafter, process block 550 begins a loop for every AC.sub.-- VALUE in AC. Thereafter, process block 555 sets sub.sub.-- EST equal to an extent structure tree based on an expr rooted at AC.sub.-- VALUE produced by a call to BuildEST. Thereafter, decision block 560 determines if EST is equal to NULL. If EST is equal to NULL, then process block 570 sets EST equal to the extent of EST and sub.sub.-- EST. Thereafter, decision block 575 determines if there is an AC.sub.-- VALUE in AC remaining to do. If there is an AC.sub.-- VALUE in AC remaining to do, then processing loops back to process block 550 to process the next AC.sub.-- VALUE in AC. Returning now to decision block 575, if there is not an AC.sub.-- VALUE in AC remaining to do, then decision block 580 determines if there is an immediate AC in ExprTree remaining to do. If there is an immediate AC in ExprTree remaining to do, then processing loops back to process block 545 to process the next immediate AC in ExprTree. Returning now to decision block 580, if there is not an immediate AC in ExprTree remaining to do, then the process ends at process block 585. Returning now to decision block 560, if EST is not equal to NULL, then process block 565 sets EST equal to sub.sub.-- EST. Thereafter, processing continues to decision block 575 to determine if there is an AC.sub.-- VALUE in AC remaining to do. Returning now to decision block 515, if ExprTree is not an implied-do, then decision block 525 determines if ExprTree contains no AC. If ExprTree contains no AC, then decision block 530 determines if the Rank(ExprTree) is equal to zero. If the Rank(ExprTree) is equal to zero, then process block 535 returns EST equal to one. Thereafter, processing continues to the loop for processing every immediate AC in ExprTree starting at process block 545. Returning now to decision block 530, if the Rank(ExprTree) is not equal to zero, i.e., the Rank(ExprTree) is equal to n greater than zero, then process block 540 returns EST equal to a recursively defined extent structure tree comprising the extent of dim(1) through dim(n). Thereafter, processing continues to the loop for processing every immediate AC in ExprTree starting at process block 545. Returning now to decision block 525, if ExprTree contains an AC, then processing continues to the loop for processing every immediate AC in ExprTree starting at process block 545. Referring now to FIG. 6, which illustrates the operations preferred in carrying out the ScalarizeAC Procedure 600 portion of the present invention, the process begins at process block 605. Thereafter, process block 610 sets S.sub.-- Expr equal to the surrounding expr of ExprTree. Thereafter, process block 615 scalarizes S.sub.-- Expr using NCx as the index variable. Thereafter, process block 620 generates NCx equal to NCx+1 to update the normalized counter. Thereafter, process block 625 finds AC.sub.-- VALUE.sub.-- SET in all of ACs at top level of ExprTree to obtain current elements. Thereafter, decision block 630 determines if AC.sub.-- VALUE.sub.-- SET is an implied-do. If AC.sub.-- VALUE.sub.-- SET is an implied-do, then process block 635 creates a loop with the bounds from the implied-do. Thereafter, process block 640 scalarizes the implied do by calling ScalarizeAC(ac-value-list's of AC.sub.-- VALUE.sub.-- SET, NCx) and setting ScalarizedExpr.sub.-- SET equal to the returned results. Thereafter, process block 650 attaches ScalarizedExpr.sub.-- SET to S.sub.-- Expr. Thereafter, process block 655 returns S.sub.-- Expr as a result to the calling Procedure TreePruning, and the process ends at process block 660. Returning now to decision block 630, if AC.sub.-- VALUE.sub.-- SET is not an implied-do, then decision block 665 determines if AC.sub.-- VALUE.sub.-- SET contains an AC. If AC.sub.-- VALUE.sub.-- SET contains an AC, then process block 670 creates a normalized counter NCy and generates code for an initialization. Thereafter, process block 675 scalarizes the AC.sub.-- VALUE.sub.-- SET by calling ScalarizeAC(AC.sub.-- VALUE.sub.-- SET, NCy) and setting ScalarizedExpr.sub.-- SET equal to the returned results. Thereafter, processing continues to process block 650 for attachment of ScalarizedExpr.sub.-- SET to S.sub.-- Expr. Returning now to decision block 665, if AC.sub.-- VALUE.sub.-- SET does not contain an AC, then decision block 680 determines if AC.sub.-- VALUE.sub.-- SET is a scalar expression. If AC.sub.-- VALUE.sub.-- SET is a scalar expression, then process block 685 scalarizes the AC.sub.-- VALUE.sub.-- SET by calling ScalarizeAC(AC.sub.-- VALUE.sub.-- SET) and setting ScalarizedExpr.sub.-- SET equal to the returned results. Thereafter, processing continues to process block 650 for attachment of ScalarizedExpr.sub.-- SET to S.sub.-- Expr. Returning now to decision block 680, if AC.sub.-- VALUE.sub.-- SET is not a scalar expression, i.e., if AC.sub.-- VALUE.sub.-- SET is an array expression, then process block 690 creates a loop nest with depth equal to rank(AC.sub.-- VALUE.sub.-- SET) and bounds from extents of AC.sub.-- VALUE.sub.-- SET. Thereafter, process block 695 scalarizes the AC.sub.-- VALUE.sub.-- SET by using the loop index variables. Thereafter, processing continues to process block 650 for attachment of ScalarizedExpr.sub.-- SET to S.sub.-- Expr. Referring now to FIG. 7, a block diagram illustrates a computer system 700 used in performing the method of the present invention, forming part of the apparatus of the present invention, and which may use the article of manufacture comprising a computer-readable storage medium having a computer program embodied in said medium which may cause the computer system to practice the present invention. The computer system 700 includes a processor 702, which includes a central processing unit (CPU) 704, and a memory 706. Additional memory, in the form of a hard disk file storage 708 and a computer-readable storage device 710, is connected to the processor 702. Computer-readable storage device 710 receives a computer-readable storage medium 712 having a computer program embodied in said medium which may cause the computer system to implement the present invention in the computer system 700. The computer system 700 includes user interface hardware, including a mouse 714 and a keyboard 716 for allowing user input to the processor 702 and a display 718 for presenting visual data to the user. The computer system may also include a printer 720. Although the present invention has been particularly shown and described with reference to a preferred embodiment, it will be understood by those skilled in the art that various changes in form and detail may be made without departing from the spirit and the scope of the invention.
|
Same subclass Same class Consider this |
||||||||||
