# LU factorization with Panel Rank Revealing Pivoting and its Communication Avoiding version

Save this PDF as:

Size: px
Start display at page:

Download "LU factorization with Panel Rank Revealing Pivoting and its Communication Avoiding version"

## Transcription

1 1 LU factorization with Panel Rank Revealing Pivoting and its Communication Avoiding version Amal Khabou Advisor: Laura Grigori Université Paris Sud 11, INRIA Saclay France SIAMPP12 February 17, 2012

2 2 Collaborators Jim Demmel, UC Berkeley Ming Gu, UC Berkeley

3 Plan Motivation : just work, less talk Communication Avoiding LU (CALU) LU with Panel Rank Revealing Pivoting (LU_PRRP) Communication Avoiding LU_PRRP (CALU_PRRP) Conclusions and future work 3

4 Lower bound for all direct linear algebra 4 Let M = local/ fast memory size, general lower bounds: [Ballard et al., 2011] ( # words moved = Ω # flops ( ) # flops # messages = Ω M 3 2 M )

5 Lower bound for all direct linear algebra 4 Let M = local/ fast memory size, general lower bounds: [Ballard et al., 2011] ( # words moved = Ω # flops ( ) # flops # messages = Ω Goal : reorganize linear algebra to : minimize # words moved minimize # messages M 3 2 M ) conserve numerical stability (better: to improve) don t increase the flop count (too much)

6 LU factorization (as in ScaLAPACK pdgetrf) LU factorization on a P = P r P c grid of processors For ib = 1 to n 1step b A (ib) = A(ib : n, ib : n) 1 Compute panel factorization - find pivot in each column, swap rows. 5

7 LU factorization (as in ScaLAPACK pdgetrf) LU factorization on a P = P r P c grid of processors For ib = 1 to n 1step b A (ib) = A(ib : n, ib : n) 1 Compute panel factorization # messages=o(n log 2 P r ) - find pivot in each column, swap rows. 5

8 LU factorization (as in ScaLAPACK pdgetrf) LU factorization on a P = P r P c grid of processors For ib = 1 to n 1step b A (ib) = A(ib : n, ib : n) 1 Compute panel factorization # messages=o(n log 2 P r ) - find pivot in each column, swap rows. 2 Apply all row permutations - broadcast pivot information along the rows - swap rows at left and right. 5

9 LU factorization (as in ScaLAPACK pdgetrf) LU factorization on a P = P r P c grid of processors For ib = 1 to n 1step b A (ib) = A(ib : n, ib : n) 1 Compute panel factorization # messages=o(n log 2 P r ) - find pivot in each column, swap rows. 2 Apply all row permutations # messages=o(n/b(log 2 P r + log 2 P c )) - broadcast pivot information along the rows - swap rows at left and right. 5

10 LU factorization (as in ScaLAPACK pdgetrf) LU factorization on a P = P r P c grid of processors For ib = 1 to n 1step b A (ib) = A(ib : n, ib : n) 1 Compute panel factorization # messages=o(n log 2 P r ) - find pivot in each column, swap rows. 2 Apply all row permutations # messages=o(n/b(log 2 P r + log 2 P c )) - broadcast pivot information along the rows - swap rows at left and right. 3 Compute block row of U - broadcast right diagonal block of L of current panel. 5

11 LU factorization (as in ScaLAPACK pdgetrf) LU factorization on a P = P r P c grid of processors For ib = 1 to n 1step b A (ib) = A(ib : n, ib : n) 1 Compute panel factorization # messages=o(n log 2 P r ) - find pivot in each column, swap rows. 2 Apply all row permutations # messages=o(n/b(log 2 P r + log 2 P c )) - broadcast pivot information along the rows - swap rows at left and right. 3 Compute block row of U # messages=o(n/b log 2 P c ) - broadcast right diagonal block of L of current panel. 5

12 LU factorization (as in ScaLAPACK pdgetrf) LU factorization on a P = P r P c grid of processors For ib = 1 to n 1step b A (ib) = A(ib : n, ib : n) 1 Compute panel factorization # messages=o(n log 2 P r ) - find pivot in each column, swap rows. 2 Apply all row permutations # messages=o(n/b(log 2 P r + log 2 P c )) - broadcast pivot information along the rows - swap rows at left and right. 3 Compute block row of U # messages=o(n/b log 2 P c ) - broadcast right diagonal block of L of current panel. 4 Update trailing matrix - broadcast right block column of L. - broadcast down block row of U. 5

13 LU factorization (as in ScaLAPACK pdgetrf) LU factorization on a P = P r P c grid of processors For ib = 1 to n 1step b A (ib) = A(ib : n, ib : n) 1 Compute panel factorization # messages=o(n log 2 P r ) - find pivot in each column, swap rows. 2 Apply all row permutations # messages=o(n/b(log 2 P r + log 2 P c )) - broadcast pivot information along the rows - swap rows at left and right. 3 Compute block row of U # messages=o(n/b log 2 P c ) - broadcast right diagonal block of L of current panel. 4 Update trailing matrix # messages=o(n/b(log 2 P r + log 2 P c )) - broadcast right block column of L. - broadcast down block row of U. 5

14 LU factorization (ScaLAPACK) upper bounds 2D algorithm P = P r P c, M = O [Ballard et al., 2011] ( ) # words moved = Ω n 2 P ( n 2 P ), Lower bounds : ( ) # messages = Ω P 6

15 LU factorization (ScaLAPACK) upper bounds 2D algorithm P = P r P c, M = O [Ballard et al., 2011] ( ) # words moved = Ω n 2 P ( n 2 P ), Lower bounds : ( ) # messages = Ω P LU with partial pivoting (ScaLAPACK ) P = P P, b = bound) : n P (upper Factor exceeding lower bounds for #words moved log P Factor exceeding lower bounds for #messages ( ) P n log P 6

16 LU factorization (ScaLAPACK) upper bounds 2D algorithm P = P r P c, M = O [Ballard et al., 2011] ( ) # words moved = Ω n 2 P ( n 2 P ), Lower bounds : ( ) # messages = Ω P LU with partial pivoting (ScaLAPACK ) P = P P, b = bound) : n P (upper Factor exceeding lower bounds for #words moved log P Factor exceeding lower bounds for #messages ( ) P n log P The lower bounds are attained by CALU: LU factorization with tournament pivoting [Grigori et al., 2011] 6

17 Stability of the LU factorization 7 Consider the growth factor [Wilkinson, 1961] g W = max i,j,k a (k) i,j max i,j a i,j where a (k) i,j denotes the entry in position (i, j) obtained after k steps of elimination.

18 Stability of the LU factorization 7 Consider the growth factor [Wilkinson, 1961] g W = max i,j,k a (k) i,j max i,j a i,j where a (k) i,j denotes the entry in position (i, j) obtained after k steps of elimination. Worst case growth factor : Partial pivoting : g W 2 n 1

19 Stability of the LU factorization 7 Consider the growth factor [Wilkinson, 1961] g W = max i,j,k a (k) i,j max i,j a i,j where a (k) i,j denotes the entry in position (i, j) obtained after k steps of elimination. Worst case growth factor : Partial pivoting : g W 2 n 1 For partial pivoting, the upper bound is attained for the Wilkinson matrix.

20 CALU: Tournament pivoting - the overall idea Consider a block algorithm that factors an n n matrix A by traversing panels of b columns. b {}}{ n b {}}{ A 12 A = A 11 A 21 A 22 where, W = [ A11 A 21 ] 8

21 CALU: Tournament pivoting - the overall idea Consider a block algorithm that factors an n n matrix A by traversing panels of b columns. b {}}{ n b {}}{ A 12 A = A 11 A 21 A 22 For each panel W where, W = [ A11 A 21 ] 8

22 CALU: Tournament pivoting - the overall idea Consider a block algorithm that factors an n n matrix A by traversing panels of b columns. b {}}{ n b {}}{ A 12 A = A 11 A 21 A 22 where, W = [ A11 A 21 For each panel W Find at low communication cost good pivots for the LU factorization of the panel W, return a permutation matrix Π (preprocessing step). ] 8

23 CALU: Tournament pivoting - the overall idea Consider a block algorithm that factors an n n matrix A by traversing panels of b columns. b {}}{ n b {}}{ A 12 A = A 11 A 21 A 22 where, W = [ A11 A 21 For each panel W Find at low communication cost good pivots for the LU factorization of the panel W, return a permutation matrix Π (preprocessing step). Apply Π to the input matrix A. ] 8

24 CALU: Tournament pivoting - the overall idea Consider a block algorithm that factors an n n matrix A by traversing panels of b columns. b {}}{ n b {}}{ A 12 A = A 11 A 21 A 22 where, W = [ A11 A 21 For each panel W Find at low communication cost good pivots for the LU factorization of the panel W, return a permutation matrix Π (preprocessing step). Apply Π to the input matrix A. Compute LU with no pivoting of ΠW, update trailing matrix. ] 8

25 CALU: Tournament pivoting - the overall idea Consider a block algorithm that factors an n n matrix A by traversing panels of b columns. b {}}{ n b {}}{ A 12 A = A 11 A 21 A 22 where, W = [ A11 A 21 For each panel W Find at low communication cost good pivots for the LU factorization of the panel W, return a permutation matrix Π (preprocessing step). Apply Π to the input matrix A. Compute LU with no pivoting of ΠW, update trailing matrix. benefit: b times fewer messages overall for the panel factorization - faster ] 8

26 Stability of CALU Worst case analysis of growth factor for a reduction tree of height H : CALU vs GEPP matrix of size m (b + 1) TSLU(b,H) GEPP g W upper bound 2 b(h+1) 2 b matrix of size m n CALU GEPP g W upper bound 2 n(h+1) 1 2 n 1 The growth factor upper bound of CALU is worse than GEPP, but CALU is still stable in practice.[grigori et al., 2011] 9

27 Motivation CALU does an optimal amount of communication. CALU is as stable as GEPP in practice.[grigori et al., 2011] CALU is worse than GEPP in terms of theoretical growth factor upper bound. Our goal: to improve the stability of both GEPP and CALU. 10

28 11 Strong Rank Revealing QR To improve the stability of LU: Pivoting strategy based on the Strong RRQR factorization [ A T R11 R Π = QR = Q 12 R 22 ]

29 Strong Rank Revealing QR To improve the stability of LU: Pivoting strategy based on the Strong RRQR factorization [ A T R11 R Π = QR = Q 12 R 22 This factorization satisfies three conditions [Gu and Eisenstat, 1996]: every singular value of R 11 is large. every singular value of R 22 is small. every element of R 1 11 R 12 could be bounded by a given threshold τ. ] 11

30 Strong Rank Revealing QR 12 Result: W T Π = QR with R 1 11 R 12 max τ Compute W T Π = QR RRQR with column pivoting ; [ while there exist i and j such that R 1 11 R 12 > τ do ij Compute the QR factorization of R Π ij (QR updates) ; end Algorithm: Strong RRQR of the panel W ]

31 Strong Rank Revealing QR 12 Result: W T Π = QR with R 1 11 R 12 max τ Compute W T Π = QR RRQR with column pivoting ; [ while there exist i and j such that R 1 11 R 12 > τ do ij Compute the QR factorization of R Π ij (QR updates) ; end Algorithm: Strong RRQR of the panel W ] After each swap the determinant of R 11 increases by at least τ. There are only a finite number of permutations. Strong RRQR does O(mb 2 ) flops in the worst case.

32 LU_PRRP : LU with Panel Rank Revealing Pivoting Consider a block algorithm that factors an n n matrix A by traversing panels of b columns. b n b {}}{{}}{ [ ] A = A 11 A 12 A11 where, W = A 21 A 21 A 22 13

33 LU_PRRP : LU with Panel Rank Revealing Pivoting Consider a block algorithm that factors an n n matrix A by traversing panels of b columns. b n b {}}{{}}{ [ ] A = A 11 A 12 A11 where, W = A 21 A 21 A 22 For each panel W 13

34 LU_PRRP : LU with Panel Rank Revealing Pivoting Consider a block algorithm that factors an n n matrix A by traversing panels of b columns. b n b {}}{{}}{ [ ] A = A 11 A 12 A11 where, W = A 21 A 21 A 22 For each panel W perform the Strong RRQR factorization of the transpose of the panel W, find a permutation matrix Π W T Π = Q [ R 11 R 12 ] such as L21 = R T 12(R 1 11 )T τ 13

35 LU_PRRP : LU with Panel Rank Revealing Pivoting Consider a block algorithm that factors an n n matrix A by traversing panels of b columns. b n b {}}{{}}{ [ ] A = A 11 A 12 A11 where, W = A 21 A 21 A 22 For each panel W perform the Strong RRQR factorization of the transpose of the panel W, find a permutation matrix Π W T Π = Q [ R 11 R 12 ] such as L21 = R T 12(R 1 11 )T τ Apply Π T to the input matrix A. 13

36 LU_PRRP : LU with Panel Rank Revealing Pivoting Consider a block algorithm that factors an n n matrix A by traversing panels of b columns. b n b {}}{{}}{ [ ] A = A 11 A 12 A11 where, W = A 21 A 21 A 22 For each panel W perform the Strong RRQR factorization of the transpose of the panel W, find a permutation matrix Π W T Π = Q [ R 11 R 12 ] such as L21 = R T 12(R 1 11 )T τ Apply Π T to the input matrix A. Update the trailing matrix as follows. [ ] [ Â = Π T Ib Â11 Â A =. 12 L 21 I m b where Â s 22 ] Â s 22 = Â22 L 21 Â 12 13

37 LU_PRRP : LU with Panel Rank Revealing Pivoting 14 Perform an additional GEPP on the b b diagonal block Â11.

38 LU_PRRP : LU with Panel Rank Revealing Pivoting 14 Perform an additional GEPP on the b b diagonal block Â11. Update the corresponding trailing matrix Â12. Â = [ Ib L 21 I m b ] [ L11. I m b ] [ U11 U 12. Â s 22 ]

39 LU_PRRP : LU with Panel Rank Revealing Pivoting 14 Perform an additional GEPP on the b b diagonal block Â11. Update the corresponding trailing matrix Â12. Â = [ Ib L 21 I m b ] [ L11. I m b ] [ U11 U 12. Â s 22 ] LU_PRRP has the same memory requirements as the standard LU decomposition. The total cost is about 2 3 n3 + O(n 2 b) flops. Is only O(n 2 b) flops more than GEPP.

40 Stability of LU_PRRP (1/4) Worst case analysis of the growth factor : LU_PRRP vs GEPP. matrix of size m (b + 1) LU_PRRP GEPP g W upper bound 1 + τb 2 b matrix of size m n LU_PRRP GEPP g W upper bound (1 + τb) n b 2 n 1 LU_PRRP is more stable than GEPP in terms of theoretical growth factor upper bound. 15

41 Stability of LU_PRRP (2/4) The upper bound for different panel sizes with a parameter τ = 2 For the different panel sizes, LU_PRRP is more stable than GEPP. b g W 8 (1.425) n 16 (1.244) n 32 (1.139) n 64 (1.078) n 128 (1.044) n 16

42 Stability of LU_PRRP (3/4) 17 LU_PRRP is more resistant to pathological matrices on which GEPP fails:

43 Stability of LU_PRRP (3/4) 17 LU_PRRP is more resistant to pathological matrices on which GEPP fails: the Wilkinson matrix.

44 Stability of LU_PRRP (3/4) 17 LU_PRRP is more resistant to pathological matrices on which GEPP fails: the Wilkinson matrix. n b g W U 1 U 1 1 L 1 L 1 1 PA LU F A F e e e e e e e e e e e e e e e e e e e e-19

45 Stability of LU_PRRP (3/4) 17 LU_PRRP is more resistant to pathological matrices on which GEPP fails: the Wilkinson matrix. n b g W U 1 U 1 1 L 1 L 1 1 PA LU F A F e e e e e e e e e e e e e e e e e e e e-19 the Foster matrix: a concrete physical example that arises from using the quadrature method to solve a certain Volterra integral equation [Foster, 1994].

46 Stability of LU_PRRP (4/4) n b g W U 1 U 1 1 L 1 L 1 1 PA LU F A F e e e e e e e e e e e e e e e e e e e e e e e e e-17 18

47 Stability of LU_PRRP (4/4) n b g W U 1 U 1 1 L 1 L 1 1 PA LU F A F e e e e e e e e e e e e e e e e e e e e e e e e e-17 the Wright matrix: two-point boundary value problems, the multiple shooting algorithm [WRIGHT, 1993]. 18

48 Stability of LU_PRRP (4/4) n b g W U 1 U 1 1 L 1 L 1 1 PA LU F A F e e e e e e e e e e e e e e e e e e e e e e e e e-17 the Wright matrix: two-point boundary value problems, the multiple shooting algorithm [WRIGHT, 1993]. n b g W U 1 U 1 1 L 1 L 1 1 PA LU F A F e e e e e e e e e e e e e e e e e e e e e e e e e-16 18

49 CALU_PRRP: Communication-Avoiding LU_PRRP Consider a block algorithm that factors an n n matrix A by traversing panels of b columns. b {}}{ n b {}}{ A 12 A = A 11 A 21 A 22 where, W = [ A11 A 21 ] 19

50 CALU_PRRP: Communication-Avoiding LU_PRRP Consider a block algorithm that factors an n n matrix A by traversing panels of b columns. b {}}{ n b {}}{ A 12 A = A 11 A 21 A 22 For each panel W where, W = [ A11 A 21 ] 19

51 CALU_PRRP: Communication-Avoiding LU_PRRP Consider a block algorithm that factors an n n matrix A by traversing panels of b columns. b {}}{ n b {}}{ A 12 A = A 11 A 21 A 22 where, W = [ A11 A 21 For each panel W Find at low communication cost b pivot rows for the QR factorization of W T, return a permutation matrix Π (preprocessing step). ] 19

52 CALU_PRRP: Communication-Avoiding LU_PRRP Consider a block algorithm that factors an n n matrix A by traversing panels of b columns. b {}}{ n b {}}{ A 12 A = A 11 A 21 A 22 where, W = [ A11 A 21 For each panel W Find at low communication cost b pivot rows for the QR factorization of W T, return a permutation matrix Π (preprocessing step). Apply Π T to the input matrix A. ] 19

53 CALU_PRRP: Communication-Avoiding LU_PRRP Consider a block algorithm that factors an n n matrix A by traversing panels of b columns. b {}}{ n b {}}{ A 12 A = A 11 A 21 A 22 where, W = [ A11 A 21 For each panel W Find at low communication cost b pivot rows for the QR factorization of W T, return a permutation matrix Π (preprocessing step). Apply Π T to the input matrix A. Compute QR with no pivoting ofw T Π, update trailing matrix as for the LU_PRRP algorithm. ] 19

54 CALU_PRRP: Communication-Avoiding LU_PRRP Consider a block algorithm that factors an n n matrix A by traversing panels of b columns. b {}}{ n b {}}{ A 12 A = A 11 A 21 A 22 where, W = [ A11 A 21 For each panel W Find at low communication cost b pivot rows for the QR factorization of W T, return a permutation matrix Π (preprocessing step). Apply Π T to the input matrix A. Compute QR with no pivoting ofw T Π, update trailing matrix as for the LU_PRRP algorithm. Perform GEPP on the b b diagonal block and update the corresponding trailing matrix (to obtain the LU decomposition). ] 19

55 CALU_PRRP: preprocessing step Consider the panel W, partitioned over P = 4 processors as A 00 W = A 10 A 20, A 30 20

56 CALU_PRRP: preprocessing step Consider the panel W, partitioned over P = 4 processors as The panel factorization uses the following binary tree : A 00 W = A 10 A 20, A 00 A 10 A 20 A 01 A 02 A 30 A 30 A 11 20

57 CALU_PRRP: preprocessing step Consider the panel W, partitioned over P = 4 processors as The panel factorization uses the following binary tree : A 00 W = A 10 A 20, A 00 A 10 A 20 A 01 A 02 A 30 A 30 A 11 1 Compute Strong RRQR factorization of the transpose of each block A i0 of the panel W, find a permutation Π 0 A T 00 Π 00 A T 10 Π 10 A T 20 Π 20 A T 30 Π 30 = Q 00 R 00 Q 10 R 10 Q 20 R 20 Q 30 R 30 20

58 CALU_PRRP: preprocessing step Consider the panel W, partitioned over P = 4 processors as The panel factorization uses the following binary tree : A 00 W = A 10 A 20, A 00 A 10 A 20 A 01 A 02 A 30 A 30 A 11 1 Compute Strong RRQR factorization of the transpose of each block A i0 of the panel W, find a permutation Π 0 A T 00 Π 00 A T 10 Π 10 A T 20 Π 20 A T 30 Π 30 = Q 00 R 00 Q 10 R 10 Q 20 R 20 Q 30 R 30 2 Perform log P times Strong RRQR factorizations of 2b b blocks, find permutations Π 1 and Π 2 A T [ 01 Π 01 = (A T 00 Π 00)(:, 1 : b); (A T T 10 Π 10)(:, 1 : b)] Π01 = Q 01 R 01 A T [ 11 Π 11 = (A T 20 Π 20)(:, 1 : b); (A T T 30 Π 30)(:, 1 : b)] Π11 = Q 11 R 11 A T [ 02 Π 02 = (A T 01 Π 01)(:, 1 : b); (A T ] T 11 Π 11)(:, 1 : b) Π02 = Q 02 R 02 20

59 Stability of CALU_PRRP 21 Worst case analysis of the growth factor for a reduction tree of height H : CALU_PRRP vs CALU. matrix of size m (b + 1) TSLU_PRRP(b,H) TSLU(b,H) g W upper bound (1 + τb) H+1 2 b(h+1) matrix of size m n CALU_PRRP CALU g W upper bound (1 + τb) n b (H+1) 1 2 n(h+1) 1

60 Stability of CALU_PRRP 21 Worst case analysis of the growth factor for a reduction tree of height H : CALU_PRRP vs CALU. matrix of size m (b + 1) TSLU_PRRP(b,H) TSLU(b,H) g W upper bound (1 + τb) H+1 2 b(h+1) matrix of size m n CALU_PRRP CALU g W upper bound (1 + τb) n b (H+1) 1 2 n(h+1) 1 CALU_PRRP is more stable than CALU in terms of theoretical growth factor upper bound. For the binary reduction tree, it is more stable than GEPP when b log(τb) log P (b = n ) P

61 CALU_PRRP: experimental results CALU_PRRP is as stable as GEPP in practice [Khabou et al., 2012]. QR with column pivoting is sufficient to attain the bound τ in practice. 22

62 Overall summary LU_PRRP more stable than GEPP in terms of growth factor upper bound. more resistant to pathological matrices. same memory requirements as the standard LU. CALU_PRRP an optimal amount of communication at the cost of redundant computation. more stable than CALU in terms of growth factor upper bound. more stable than GEPP in terms of growth factor upper bound under certain conditions. 23

63 24 Future work Estimating the performance of CALU_PRRP on parallel machines based on multicore processors, and comparing it with the performance of CALU. Design of a communication avoiding algorithm that has smaller bounds on the growth factor than that of GEPP in general.

64 References I Ballard, G., Demmel, J., Holtz, O., and Schwartz, O. (2011). Minimizing communication in linear algebra. SIMAX, 32: Foster, L. V. (1994). Gaussian Elimination with Partial Pivoting Can Fail in Practice. SIAM J. Matrix Anal. Appl., 15: Grigori, L., Demmel, J., and Xiang, H. (2011). CALU: A communication optimal LU factorization algorithm. SIAM Journal on Matrix Analysis and Applications. Gu, M. and Eisenstat, S. C. (1996). Efficient Algorithms For Computing A Strong Rank Reaviling QR Factorization. SIAM J. SCI.COMPUT., 17: Khabou, A., Demmel, J., Grigori, L., and Gu, M. (2012). LU factorization with panel rank revealing pivoting and its communication avoiding version. Technical Report UCB/EECS , EECS Department, University of California, Berkeley. Wilkinson, J. H. (1961). Error analysis of direct methods of matrix inversion. J. Assoc. Comput. Mach., 8: WRIGHT, S. J. (1993). A collection of problems for which gaussian elimination with partial pivoting is unstable. SIAM J. SCI. STATIST. COMPUT., 14: