| 1 |
function [X, nnzlu] = LUdriver(A, k, B) |
| 2 |
%function X = LUdriver(A, k, B) |
| 3 |
% |
| 4 |
% A driver for the LU factorization using hypergraph partitioner. |
| 5 |
% |
| 6 |
% Input: |
| 7 |
% A, matrix to be factored. |
| 8 |
% k, (integer) number of parts. |
| 9 |
% B, right hand side |
| 10 |
% Output: |
| 11 |
% X, left hand side |
| 12 |
% nnzlu, not including the non zeros in the band of A, including the non |
| 13 |
% zeros in the factor of the Schur complement. |
| 14 |
% |
| 15 |
% Erik Boman, Sandia National Labs, 2010. |
| 16 |
% Siva Rajamanickam, Sandia National Labs, 2010. |
| 17 |
|
| 18 |
if (nargin<2) |
| 19 |
k = max(2, ceil(size(A,1)/1000)); % Default value for #blocks |
| 20 |
end |
| 21 |
|
| 22 |
[m,n] = size(A); |
| 23 |
|
| 24 |
if (m ~= n) |
| 25 |
error('Input A must be square'); |
| 26 |
return; |
| 27 |
end |
| 28 |
|
| 29 |
if (k<1) |
| 30 |
error('Input k must be > 1'); |
| 31 |
return; |
| 32 |
end |
| 33 |
|
| 34 |
if (nargin < 3) |
| 35 |
B = sprand(n, 1, 0.4); |
| 36 |
end |
| 37 |
|
| 38 |
% Compute hypergraph partition and the LU factors of the diagonal blocks. |
| 39 |
LUdata = LUfactor(A, k); |
| 40 |
% Find Bhat, the rhs for Schur complement. |
| 41 |
Bhat = LUfsolve(LUdata, B); |
| 42 |
nnzlu = LUdata.nnzlu ; |
| 43 |
|
| 44 |
khalf = floor(k/2) ; |
| 45 |
|
| 46 |
if (khalf == 1) |
| 47 |
% Solve Schur complement. Sequential bottle neck. |
| 48 |
LUdata.Xhat = LUdata.U{k+1} \ (LUdata.L{k+1} \ Bhat(LUdata.p{k+1})); |
| 49 |
|
| 50 |
% Solve the diagonal blocks |
| 51 |
X = LUbsolve(LUdata, B); |
| 52 |
else |
| 53 |
% Ignore the L and U of the Schur complement, refactor S using hypergraph |
| 54 |
% partitioning |
| 55 |
%%SLUdata = LUfactor(LUdata.S{k+1}, khalf); |
| 56 |
%%B1hat = LUfsolve(SLUdata, Bhat); |
| 57 |
%%SLUdata.Xhat = SLUdata.U{khalf+1} \ (SLUdata.L{khalf+1} \ ... |
| 58 |
%%B1hat(SLUdata.p{khalf+1})); |
| 59 |
%%LUdata.Xhat = LUbsolve(SLUdata, Bhat); |
| 60 |
|
| 61 |
LUdata.q{k+1} = LUdata.c{k+1}; |
| 62 |
[LUdata.Xhat, nnzlu1] = LUdriver(LUdata.S{k+1}, khalf, Bhat) ; |
| 63 |
% Adjust for the non zeros the factors of S{k+1} |
| 64 |
nnzlu = nnzlu - nnz(LUdata.L{k+1}) - nnz(LUdata.U{k+1}) + nnzlu1 ; |
| 65 |
% Solve the diagonal blocks. |
| 66 |
X = LUbsolve(LUdata, B); |
| 67 |
end |