Docsity

Deriving Dense Linear Algebra Libraries, Lecture notes of Linear Algebra

Toggle sidebar
bg1
Deriving Dense Linear Algebra Libraries
Paolo Bientinesi∗John Gunnels†Maggie Myers‡Enrique Quintana-Ort´ı§
Tyler Rhodes‡Robert van de Geijn‡Field G. Van Zee‡
May 31, 2011
Abstract
Starting in the late 1960s computer scientists including Dijkstra and Hoare advocated goal-oriented program-
ming and the formal derivation of algorithms. The chief impediment to realizing this for loop-based programs
was that a priori determination of loop-invariants, a prerequisite for developing loops, was a task too complex
for any but the simplest of operations. Around 2000, these techniques were for the first time successfully applied
to the domain of high-performance dense linear algebra libraries. This has led to a multitude of papers, mostly
published in the ACM Transactions for Mathematical Software, as well as a system for the mechanical derivation
of algorithms and a high-performance linear algebra library, libflame, that includes more than a thousand vari-
ants of algorithms for more than a hundred linear algebra operations. To our knowledge, this success story has
unfolded with limited awareness on the part the formal methods community. This paper reports on ten years of
experience and is meant to raise that awareness.
1 Introduction
Linear algebra libraries reside at the bottom of the scientific computing food chain. While most practical applications
give rise to sparse linear algebra problems, a significant number of them spends most computational time solving
dense matrix problems. Even sparse linear algebra problems often have dense subproblems to be solved. As a result,
LAPACK [1], a package for dense matrix operations, developed in the late 1980s and early 1990s, is undoubtedly the
most commonly used library in this field.
Since 2000, the FLAME project at The University of Texas at Austin, Universidad Jaume I (Spain), and RWTH
Aachen University (Germany) has been pursuing a modern replacement of LAPACK, libflame [28]. The domain
poses a few interesting challenges: scientific computing tends to exploit the latest architectures, demanding the
highest possible performance. This requires the design of loop-based algorithms that cast most computation in terms
of high-performing matrix-matrix operations (like matrix-matrix multiplication). The loop steps through matrices
with block sizes chosen so as to optimize the reuse of data in caches. For a specific operation, there are often multiple
algorithmic variants, with one algorithmic variant matching a given architecture better than the others, yielding
higher performance. Thus, unlike LAPACK, a library should incorporate multiple loop-based algorithms for a given
operation so that the best one can be chosen. This brings up the question of how to systematically find algorithmic
variants for a given operation. The formal derivation of loops turns out to be the answer [19, 17, 18, 3, 25, 2, 26, 4],
as we will illustrate.
This paper does not provide a scholarly treatment of the field of derivation of algorithms. All we have ever
needed to develop the described techniques is given in the text by Gries [16], which itself is based on the works of
Dijkstra [8, 7] and Hoare [20]. What the paper does provide is what we believe to be an excellent practical example
of the application of formal derivation of loops to the domain of dense linear algebra.
∗Aachen Institute for Advanced Study in Computational Engineering Science, RWTH Aachen, Schinkelstrasse 2, 52056 Aachen,
Germany.
†IBM T.J. Watson Research Center, Yorktown Heights, NY 10598
‡Department of Computer Science, The University of Texas at Austin, Austin, TX 78712.
§Departamento de Ingenier´ıa y Ciencia de Computadores, Universidad Jaime I, 12.071-Castell´on, Spain.
1
pf3
pf4
pf5
pf8
pf9
pfa
pfd

Partial preview of the text

Download Deriving Dense Linear Algebra Libraries and more Lecture notes Linear Algebra in PDF only on Docsity!

Deriving Dense Linear Algebra Libraries

Paolo Bientinesi∗^ John Gunnels†^ Maggie Myers‡^ Enrique Quintana-Ort´ı§

Tyler Rhodes‡^ Robert van de Geijn‡^ Field G. Van Zee‡

May 31, 2011

Abstract Starting in the late 1960s computer scientists including Dijkstra and Hoare advocated goal-oriented program- ming and the formal derivation of algorithms. The chief impediment to realizing this for loop-based programs was that a priori determination of loop-invariants, a prerequisite for developing loops, was a task too complex for any but the simplest of operations. Around 2000, these techniques were for the first time successfully applied to the domain of high-performance dense linear algebra libraries. This has led to a multitude of papers, mostly published in the ACM Transactions for Mathematical Software, as well as a system for the mechanical derivation of algorithms and a high-performance linear algebra library, libflame, that includes more than a thousand vari- ants of algorithms for more than a hundred linear algebra operations. To our knowledge, this success story has unfolded with limited awareness on the part the formal methods community. This paper reports on ten years of experience and is meant to raise that awareness.

1 Introduction

Linear algebra libraries reside at the bottom of the scientific computing food chain. While most practical applications give rise to sparse linear algebra problems, a significant number of them spends most computational time solving dense matrix problems. Even sparse linear algebra problems often have dense subproblems to be solved. As a result, LAPACK [1], a package for dense matrix operations, developed in the late 1980s and early 1990s, is undoubtedly the most commonly used library in this field. Since 2000, the FLAME project at The University of Texas at Austin, Universidad Jaume I (Spain), and RWTH Aachen University (Germany) has been pursuing a modern replacement of LAPACK, libflame [28]. The domain poses a few interesting challenges: scientific computing tends to exploit the latest architectures, demanding the highest possible performance. This requires the design of loop-based algorithms that cast most computation in terms of high-performing matrix-matrix operations (like matrix-matrix multiplication). The loop steps through matrices with block sizes chosen so as to optimize the reuse of data in caches. For a specific operation, there are often multiple algorithmic variants, with one algorithmic variant matching a given architecture better than the others, yielding higher performance. Thus, unlike LAPACK, a library should incorporate multiple loop-based algorithms for a given operation so that the best one can be chosen. This brings up the question of how to systematically find algorithmic variants for a given operation. The formal derivation of loops turns out to be the answer [19, 17, 18, 3, 25, 2, 26, 4], as we will illustrate. This paper does not provide a scholarly treatment of the field of derivation of algorithms. All we have ever needed to develop the described techniques is given in the text by Gries [16], which itself is based on the works of Dijkstra [8, 7] and Hoare [20]. What the paper does provide is what we believe to be an excellent practical example of the application of formal derivation of loops to the domain of dense linear algebra.

∗Aachen Institute for Advanced Study in Computational Engineering Science, RWTH Aachen, Schinkelstrasse 2, 52056 Aachen, Germany. †IBM T.J. Watson Research Center, Yorktown Heights, NY 10598 ‡Department of Computer Science, The University of Texas at Austin, Austin, TX 78712. §Departamento de Ingenier´ıa y Ciencia de Computadores, Universidad Jaime I, 12.071-Castell´on, Spain.

Step Annotated Algorithm: [D, E,.. .] := op(A, B,.. .) 1a {Ppre } 4 Partition where 2 {Pinv } 3 While G do 2,3 {Pinv ∧ G} 5a (^) Repartition

where 6 {Pbefore } 8 SU 5b (^) Continue with

7 {Pafter } 2 {Pinv } EndWhile 2,3 {(Pinv ) ∧ ¬ (G)} 1b {Ppost }

Figure 1: Blank FLAME worksheet used to derive algorithms.

2 Derivation of Linear Algebra Algorithms

In this section we walk the reader through the derivation process. The procedure is completely routine for us, having been applied to more than a hundred operations, yielding more than a thousand routines that are part of the libflame library. We use the solution of the triangular Lyapunov equation as our motivating example. A reader who is not well-versed in linear algebra should not worry: the methology is systematic to the point where one does not need to be an expert in order to apply it. A more basic treatment that targets novices and has been used at the undergraduate level can be found in [26].

2.1 The FLAME methodology

A fundamental insight in our project was the realization that the Fundamental Invariance Theorem, used to prove the correctness of a loop in a program, can be formulated as a worksheet that is systematically filled out, first with assertions (predicates) and then with commands (imperative statements) [3]. The worksheet, given in Figure 1, will be filled out with predicates that indicate prescribed states and commands that achieve those states. It is filled out in the order indicated in the column marked by Step. The predicates Ppre , Ppost , Pinv , and G represent the precondition, postcondition, loop-invarant, and loop-guard, respectively. The loop-invariant has to be true in four different places: before and after the loop, and at the top and bottom of the loop body. The other parts of the worksheet will become obvious as we fill it out for our example.

2.2 Example: the solution of the triangular Lyapunov equation

We now show how the methodology is applied to a prototypical example: the solution of the triangular Lyapunov equation given by U T^ X + XU = −C, where U is an upper triangular matrix and C and X are symmetric matrices. Here the superscript “T ” indicates matrix transposition. The solution X is to be computed. Because of symmetry, only the upper triangular part of C is stored and is overwritten with the upper triangular part of X. This operation is preceded by a pre-processing phase (not discussed in this paper) that transforms the general (non-triangular) time-

Step Annotated Algorithm: C := lyap unb(U, C) 1a

n C = Cˆ

o

4 Partition U →

UT L UT R 0 UBR

! , X →

XT L XT R ⋆ XBR

! , C →

CT L CT R ⋆ CBR

! , Cˆ →

C^ ˆT L CˆT R ⋆ CˆBR

!

where UT L is 0 × 0, XT L is 0 × 0, CT L is 0 × 0, CˆT L is 0 × 0

2

8 >< >:

CT L CT R ⋆ CBR

!

XT L XT R ⋆ XBR

! ∧

8 >< >:

U (^) T LT XT L + XT LUT L = − CˆT L U (^) T LT XT R + XT RUBR = − CˆT R − XT LUT R XBR = CˆBR

9 >= >;

3 While m(UT L) < m(U ) do

2,

8 >< >:

CT L CT R ⋆ CBR

!

XT L XT R ⋆ XBR

! ∧

8 >< >:

U (^) T LT XT L + XT LUT L = − CˆT L U (^) T LT XT R + XT RUBR = − CˆT R − XT LUT R XBR = CˆBR

∧ m(UT L) < m(U )

9 >= >;

5a Repartition

UT L UT R 0 UBR

! →

0 BB @

U 00 u 01 U 02 0 υ 11 uT 12 0 0 U 22

1 CC A ,^

XT L XT R ⋆ XBR

! →

0 BB @

X 00 x 01 X 02 ⋆ χ 11 xT 12 ⋆ ⋆ X 22

1 CC A ,^

CT L CT R ⋆ CBR

! → · · ·

where υ 11 , χ 11 , γ 11 are scalars

6

8 >>> >< >>> >:

0 BB @

C 00 c 01 C 02 ⋆ γ 11 cT 12 ⋆ ⋆ C 22

1 CC A =

0 BB @

X 00 x 01 X 02 ⋆ χ 11 xT 12 ⋆ ⋆ X 22

1 CC A ∧

8 >>> >< >>> >:

U 00 TX 00 + X 00 U 00 = − Cˆ 00 U 00 Tx 01 + X 00 u 01 + x 01 υ 11 = −ˆc 01 U 00 TX 02 + X 00 U 02 + x 01 uT 12 + X 02 U 22 = − Cˆ 02 χ 11 = ˆγ 11 ∧ xT 12 = ˆcT 12 ∧ X 22 = Cˆ 22

9 >>> >= >>> >;

8

γ 11 := (−γ 11 − 2 uT 01 c 01 )/(2υ 11 ) cT 12 := −cT 12 − uT 01 C 02 − cT 01 U 02 − γ 11 uT 12 Solve υ 11 xT 12 + xT 12 U 22 = cT 12 overwriting cT 12 with xT 12 5b Continue with

UT L UT R 0 UBR

! ←

0 BB @

U 00 u 01 U 02 0 υ 11 uT 12 0 0 U 22

1 CC A ,^

XT L XT R ⋆ XBR

! ←

0 BB @

X 00 x 01 X 02 ⋆ χ 11 xT 12 ⋆ ⋆ X 22

1 CC A ,^

CT L CT R ⋆ CBR

! ← · · ·

7

8 >>> >>> >>> < >>> >>> >>> :

0 BB @

C 00 c 01 C 02 ⋆ γ 11 cT 12 ⋆ ⋆ C 22

1 CC A =

0 BB @

X 00 x 01 X 02 ⋆ χ 11 xT 12 ⋆ ⋆ X 22

1 CC A ∧

8 >>> >>> >>> < >>> >>> >>> :

U 00 TX 00 + X 00 U 00 = − Cˆ 00 U 00 Tx 01 + X 00 u 01 + x 01 υ 11 = −ˆc 01 U 00 TX 02 + X 00 U 02 + x 01 uT 12 + X 02 U 22 = − Cˆ 02 2 uT 01 x 01 + 2υ 11 χ 11 = −γˆ 11 uT 01 X 02 + υ 11 xT 12 + xT 01 U 02 + χ 11 uT 12 + xT 12 U 22 = −ˆcT 12 X 22 = Cˆ 22

9 >>> >>> >>> = >>> >>> >>> ;

2

8 >< >:

CT L CT R ⋆ CBR

!

XT L XT R ⋆ XBR

! ∧

8 >< >:

U (^) T LT XT L + XT LUT L = − CˆT L U (^) T LT XT R + XT RUBR = − CˆT R − XT LUT R XBR = CˆBR

9 >= >;

EndWhile

2,

8 >< >:

0 B@ CT L^ CT R ⋆ CBR

!

XT L XT R ⋆ XBR

! ∧

8 >< >:

U (^) T LT XT L + XT LUT L = − CˆT L U (^) T LT XT R + XT RUBR = − CˆT R − XT LUT R XBR = CˆBR

1 CA ∧ ¬ (m(UT L) < m(U ))

9 >= >;

1b

˘ U T^ X + XU = −C

¯

Figure 2: Worksheet for deriving the unblocked algorithm for solving the triangular Lyapunov equation corresponding to Loop-invariant 3.

happen in the loop body, and then that row and column are moved across the thick line to capture the traversal through the matrices. The fact that the top-left quadrant is initially empty ( 0 × 0 ) and must eventually envelop the entire matrix dictates how the algorithm traverses through the matrices. The traversal through the matrix,

Substituting the partitioned operands in (1) into U T^ X + XU = − Cˆ (the postcondition), yields ( CT L CT R ⋆ CBR

XT L XT R

⋆ XBR

U T LT 0

U T RT U BRT

XT L XT R

⋆ XBR

XT L XT R

⋆ XBR

UT L UT R

0 UBR

− CˆT L − CˆT R

⋆ − CˆBR

which (by linear algebra manipulation) is equivalent to

( CT L CT R ⋆ CBR

XT L XT R

⋆ XBR

U T LTXT L + XT LUT L = − CˆT L

U T LTXT R + XT RUBR = − CˆT R − XT LUT R

U BRT XBR + XBRUBR = − CˆBR − (U T RT XT R + XT RT UT R)

Figure 3: The Partitioned Matrix Expression (PME) (recursive definition of the operation) for overwriting C with the solution of the triangular Lyapunov equation.

Loop-invariant 1: ( CT L CT R ⋆ CBR

XT L XT R

⋆ XBR

U T LT XT L + XT LUT L = − CˆT L

U T LT XT R+XT RUBR = CˆT R−XT LUT R

U BRT XBR+XBRUBR = CˆBR−(U T RT XT R + XTT RUT R)

Loop-invariant 2: ( CT L CT R ⋆ CBR

XT L XT R

⋆ XBR

U T LT XT L + XT LUT L = − CˆT L

U T LT XT R+XT RUBR = − CˆT R − XT LUT R

U BRT XBR+XBRUBR = CˆBR−(U T RT XT R + XTT RUT R)

Loop-invariant 3: ( CT L CT R ⋆ CBR

XT L XT R

⋆ XBR

U T LT XT L + XT LUT L = − CˆT L

U T LT XT R + XT RUBR = − CˆT R − XT LUT R

U BRT XBR+XBRUBR = CˆBR−(U T RT XT R + XTT RUT R)

Loop-invariant 4: ( CT L CT R ⋆ CBR

XT L XT R

⋆ XBR

U T LT XT L + XT LUT L = − CˆT L

U T LT XT R + XT RUBR = − CˆT R − XT LUT R

U BRT XBR+XBRUBR = − CˆBR − (U T RT XT R + XT RT UT R)

Figure 4: Loop-invariants for the triangular Lyapunov equation.

together with the finite size of the operands, means that there is a natural, monotonically decreasing loop-bound function, t = n − m(UT L), that is bounded below. This ensures that the loop terminates. In exposing submatrices, we used notational conventions that allow special properties of the submatrices to be easily recognized: lower case Greek letters denote scalars, lower case Roman letters denote column vectors, and upper case Roman letter denote matrices. Submatrices like uT 12 can be easily recognized as being part of a row and hence a row vector (transposed column vector).

Substituting the redefinition of quadrants in Step 5b

( UT L UT R 0 UBR

U 00 u 01 U 02 0 υ 11 uT 12 0 0 U 22

XT L XT R

⋆ XBR

X 00 x 01 X 02 ⋆ χ 11 xT 12 ⋆ ⋆ X 22

CT L CT R

⋆ CBR

C 00 c 01 C 02 ⋆ γ 11 cT 12 ⋆ ⋆ C 22

CˆT L CˆT R

⋆ CˆBR

C^ ˆ 00 ˆc 01 Cˆ 02 ⋆ γˆ 11 ˆcT 12 ⋆ ⋆ Cˆ 22

into the desired state of the variables at the bottom of the loop (the invariant)

( CT L CT R ⋆ CBR

XT L XT R

⋆ XBR

U T LT XT L + XT LUT L = − CˆT L

U T LT XT R + XT RUBR = − CˆT R − XT LUT R

XBR = CˆBR

results in    

C 00 c 01 C 02 ⋆ γ 11 cT 12 ⋆ ⋆ C 22

X 00 x 01 X 02 ⋆ χ 11 xT 12 ⋆ ⋆ X 22

U 00 u 01 0 υ 11

)T (

X 00 x 01 ⋆ χ 11

X 00 x 01 ⋆ χ 11

U 00 u 01 0 υ 11

Cˆ 00 ˆc 01 ⋆ γˆ 11

U 00 u 01 0 υ 11

)T (

X 02

xT 12

X 02

xT 12

U 22 = −

Cˆ 02

c ˆT 12

X 00 x 01 ⋆ χ 11

U 02

uT 12

X 22 = Cˆ 22.

Algebraic manipulation yields the expression in Step 7.

Figure 6: Systematic derivation of the state of the variables at Step 7 in Figure 2.

Step 8: Update. The update in Step 8 is now dictated by the state that the variables are in at Step 6 and the state that they must be in at Step 7:

  • C 00 already contains X 00 , the solution to U 00 TX 00 + X 00 U 00 = − Cˆ 00 , and hence is not updated.
  • c 01 already contains x 01 , the solution to U 00 Tx 01 + X 00 u 01 + x 01 υ 11 = −ˆc 01 , and hence is not updated.
  • C 02 already contains X 02 , the solution to U 00 TX 02 + X 00 U 02 + x 01 uT 12 + X 02 U 22 = − Cˆ 02 , and hence is not updated.
  • γ 11 contains χ 11 = ˆγ 11 and needs to be overwritten by the solution, χ 11 , of 2uT 01 x 01 + 2υ 11 χ 11 = −ˆγ 11. Recognizing that at this point c 01 contains x 01 and γ 11 contains ˆγ 11 , this can be accomplished by updating γ 11 with γ 11 := (−γ 11 − 2 uT 01 c 01 )/(2υ 11 ).
  • cT 12 holds xT 12 = ˆcT 12 and needs to be overwritten with the solution, xT 12 , of uT 01 X 02 + υ 11 xT 12 + xT 01 U 02 + χ 11 uT 12 + xT 12 U 22 = −cˆT 12. Recognizing that X 02 has overwritten C 02 , etc., this can be accomplished by updating it with the solution, xT 12 , of υ 11 xT 12 + xT 12 U 22 = −cT 12 − uT 01 C 02 − cT 01 U 02 − γ 11 uT 12 :
  • First, we update cT 12 := −cT 12 − uT 01 C 02 − cT 01 U 02 − γ 11 uT 12.
  • Next, we compute cT 12 := cT 12 (υ 11 I + U 22 )−^1. This requires the solution of a triangular system of equations, since it is equivalent to computing the solution to (υ 11 I + U 22 )T^ x 12 = c 12 and overwriting cT 12 with xT 12.

We reiterate that the state in Step 6 and the desired state in Step 7 dictate how the variables (submatrices of C) must be updated.

Resulting algorithm. The resulting algorithm, stripped of the annotations that were used to derive it, is given in Figure 7 (left), executing only the commands indicated under Variant 3.

2.4 Other algorithms

Other algorithms are derived from the other loop-invariants. In addition, blocked algorithms, which cast most computation in terms of matrix-matrix operations and hence can attain higher performance, can be derived by moving through the matrix several rows and columns at a time. Resulting algorithms are given in Figure 7. In the blocked algorithms, the operation

Solve U (^) IIT XIJ + XIJ UJJ = CIJ

requires the solution of the Sylvester equation. Algorithms for that operations were derived in [25].

2.5 Discussion

It is the notation we use that facilitates the derivation process: by presenting submatrices rather than index ranges, the derived algorithm avoids much of the indexing clutter (both in the presentation of the algorithm and the details of the proof of correctness) that is typically found in conventional loop-based algorithms. Indeed, the algorithm exposes only one loop even though it requires approximately n^3 floating point operations. The other loops are hidden inside of the linear algebra operations that form the body of the loop. Algorithms for these operations themselves can be, and have been, formally derived.

2.6 From algorithm to code

Having a correct algorithm does not mean one has a correct implementation. To preserve the correctness of the algorithm as we translate it to code, we defined APIs for different languages so that the code closely resembles the algorithm [5, 26, 27]. An example of this is given in Figure 8. In that figure, unblocked Variant 3 is coded in M-script, the scripting language of Matlab [23]. We created a handful of routines that partition and repartition the matrices. White-space is used to make the code resemble the algorithm as closely as possible. The code in the figure actually executes and gave the correct answer the first time it was run. We have developed APIs for the C programming language [5, 26, 27, 28]. Additionally, the recently developed Elemental library for distributed memory architectures uses a similar API [24].

3 Performance

In Figure 9 we show the performance of different algorithmic variants that are implemented as part of libflame, blocked and unblocked, on a Dell PowerEdge R900 server, using four cores and double precision arithmetic. We report performance in GFLOPS (billions of floating point operations per second) by taking the known floating point operation count for this operation, n^3 , dividing it by the time required to complete the computation, and then scaling it by dividing it by 10^9. The commands in the body of the loop map are implemented as calls to Basic Linear Algebra Subprograms (BLAS) [22, 10, 9], an interface to commonly encountered linear algebra operations, as well as other routines supported by libflame, which themselves eventually call BLAS operations. As part of our project, we have derived a full library of these operations, but for this experiment we are depending on optimized implementations provided by the GotoBLAS2 implementation [15, 14] For the blocked algorithms, a block size of 128 was used. While most of our papers focus on achieving high performance, this paper does not and hence we do not go into further details regarding the experiments.

function [ C_out ] = lyap_unb_var3( U, C ) [ UTL, UTR, ... UBL, UBR ] = FLA_Part_2x2( U, ... 0, 0, ’FLA_TL’ ); [ CTL, CTR, ... CBL, CBR ] = FLA_Part_2x2( C, ... 0, 0, ’FLA_TL’ ); while ( size( CTL, 1 ) < size( C, 1 ) ) [ U00, u01, U02, ... u10t, upsilon11, u12t, ... U20, u21, U22 ] = ... FLA_Repart_2x2_to_3x3( UTL, UTR, ... UBL, UBR, ... 1, 1, ’FLA_BR’ ); [ C00, c01, C02, ... c10t, gamma11, c12t, ... C20, c21, C22 ] = ... FLA_Repart_2x2_to_3x3( CTL, CTR, ... CBL, CBR, ... 1, 1, ’FLA_BR’ ); %----------------------------------------------% gamma11 = -gamma11 - 2 * u01’ * c01; gamma11 = gamma11 / ( 2 * upsilon11 ); c12t = -c12t - u01’ * C02 - c01’ * U ...

  • gamma11 * u12t; c12t = SolveSylv( upsilon11, U22, c12t ); %-----------------------------------------------% [ CTL, CTR, ... CBL, CBR ] = FLA_Cont_with_3x3_to_2x2( ... C00, c01, C02, ... c10t, gamma11, c12t, ... C20, c21, C22, ’FLA_TL’ ); [ UTL, UTR, ... UBL, UBR ] = FLA_Cont_with_3x3_to_2x2( ... U00, u01, U02, ... u10t, upsilon11, u12t, ... U20, u21, U22, ’FLA_TL’ ); end C_out = [ CTL, CTR CBL, CBR ]; return

Figure 8: M-script implementation of unblocked Variant 3.

4 Past, Current, and Future Directions

This paper gives a refined presentation of the methodology already proposed in [3, 26]. In this section, we discuss the developments that this work has enabled over the last decade, the current impact of the project, and future directions.

Mechanical derivation of linear algebra libraries. Early on in the project it was recognized that with the introduction of the worksheet, the methodology became systematic to the point where it could be automated. This led to a mechanical system, implemented in Mathematica, that does just that [2]. For an operation like the solution of a triangular Lyapunov equation, that system performs the steps described in Section 2 mechanically, provided a loop- invariant is given by the user. The system outputs an algorithm, M-script implementation, and C implementation. More recently, a system that can automatically generate PMEs has been developed [13] as well as one that then automatically generates loop-invariants [12]. Combining these efforts would yield a system that, given a linear algebra operation, would automate all steps described in this paper.

Scope. As part of the libflame library, the described methology has been applied to all operations supported by the BLAS and a large number of operations supported by the LAPACK library. In all, this C library comprises about 1500 implementations of algorithms for about 150 distinct operations (operations that differ in whether they work, for example, with upper or lower triangular matrices are counted separately). Most of these were formally

0 500 1000 1500 2000 2500 3000

0

5

10

15

problem size

GFLOPS

blk variant 1 36% of peak blk variant 4 blk variant 2 blk variant 3 unb variant 1 unb variant 2 unb variant 4 unb variant 3

Figure 9: Performance of the various algorithms on a four core architecture.

derived as described in this paper.

Formal derivation of stability analyses. The notion of correctness of an algorithm is somewhat different in the presence of round-off error. There, we must instead establish that an algorithm is numerically stable. We have extended the derivation process and worksheet described in this paper so that once algorithms have been derived, numerical stability results can be similarly systematically derived [2, 6].

Sparse linear solvers. As mentioned in the introduction, sparse iterative solvers for linear algebra problems are more commonly used by applications. These are based on Krylov subspace methods, the Conjugate Gradient method being one example. Recently, we showed that the formal derivation methodology we developed can be extended to the formal derivation of these Krylov subspace methods [11].

5 Conclusion

We have demonstrated how formal derivation of loop-based algorithms is both viable and valuable for the domain of dense linear algebra. Key to the success of the methodology has been a notation that hides indexing details when using arrays and subarrays, the definition of an operation to be implemented via the Partitioned Matrix Expression (PME), a systematic way for identifying loop-invariants, and a framework (the worksheet) that captures the Fundamental Invariance Theorem in a way that clearly links it to a loop-based algorithm.

Acknowledgments

This research was initially started as a Freshman Research Initiative project that also involved Eileen Martin, Burns Healey, and Nick Wiz. We thank Jay Misra for encouraging us to target the formal methods community with this paper and the remaining members of the FLAME team for their contributions over the last ten years. This research was supported in part by NSF grants CCF-0342369, CCF-0540926, CCF-0702714, and CCF- 0917167, and Microsoft. Any opinions, findings and conclusions or recommendations expressed in this material are those of the author(s) and do not necessarily reflect the views of the National Science Foundation (NSF).

[19] John A. Gunnels and Robert A. van de Geijn. Formal methods for high-performance linear algebra libraries. In Ronald F. Boisvert and Ping Tak Peter Tang, editors, The Architecture of Scientific Software, pages 193–210. Kluwer Academic Press, 2001.

[20] C. A. R. Hoare. An axiomatic basis for computer programming. Communications of the ACM, pages 576–580, October 1969.

[21] Hassan K Khalil. Nonlinear systems; 3rd ed. Prentice-Hall, Upper Saddle River, NJ, 2002.

[22] C. L. Lawson, R. J. Hanson, D. R. Kincaid, and F. T. Krogh. Basic linear algebra subprograms for Fortran usage. ACM Trans. Math. Soft., 5(3):308–323, Sept. 1979.

[23] C. Moler, J. Little, and S. Bangert. Pro-Matlab, User’s Guide. The Mathworks, Inc., 1987.

[24] Jack Poulson, Robert van de Geijn, and Jeffrey Bennighof. Parallel algorithms for reducing the generalized hermitian-definite eigenvalue problem. ACM Transactions on Mathematical Software. submitted.

[25] Enrique S. Quintana-Ort´ı and Robert A. van de Geijn. Formal derivation of algorithms: The triangular Sylvester equation. ACM Trans. Math. Soft., 29(2):218–243, June 2003.

[26] Robert A. van de Geijn and Enrique S. Quintana-Ort´ı. The Science of Programming Matrix Computations. http://www.lulu.com/content/1911788, 2008.

[27] Field G. Van Zee, Ernie Chan, Robert van de Geijn, Enrique S. Quintana-Ort´ı, and Gregorio Quintana-Ort´ı. Introducing: The libflame library for dense matrix computations. IEEE Computation in Science & Engineering, 11(6):56–62, 2009.

[28] Field G. Van Zee. libflame: The Complete Reference. www.lulu.com, 2009.