我正在尝试执行图块LU分解,但是,当我选择图块siz(nbtiles)与矩阵大小(nbtiles = 1)相同时,它将产生正确的答案(这意味着函数Bllu中使用的是正确的),但是当选择不同的图块大小(例如nbtiles = 2)时,它将生成矩阵A但值错误
% A is a symmetric matrix
A = [0.9 0.06 -0.39 -0.24; 0.06 1.604 0.134 0.464; -0.39 0.134 2.685 0.802; -0.24 0.464 0.802 1.977];
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
nbtiles = 1;
[nbrow nbcol]=size(A);
mink = zeros(size(nbtiles,1),size(acc,1));
for indtiles=1:size(nbtiles,1)
% Init mink array
mink(indtiles,:)=nbtiles(indtiles);
% Number of tiles
p=floor(nbrow/nbtiles(indtiles))
q=floor(nbcol/nbtiles(indtiles))
rows=nbtiles(indtiles)*ones(1,p);
if mod(nbrow,nbtiles(indtiles)) ~= 0
rows=[rows mod(nbrow,nbtiles(indtiles))];
p=p+1;
end
rows;
cols=nbtiles(indtiles)*ones(1,q);
if mod(nbcol,nbtiles(indtiles)) ~= 0
cols=[cols mod(nbcol,nbtiles(indtiles))];
q=q+1;
end
cols;
% Generate the tile format
B = cell(p,q);
B = mat2cell(A,rows,cols);
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
[A]= Bllu(B, p)
function [ AA] = Bllu(A, p )
%for each panel
%************************* dpotrf *************************
for k = 1 : p,
[L U] = lu(sparse(A{k,k}),0); %dpotrf(Akk,oAkk)
%************************* TRSM Lower *************************
for i = (k+1) : p,
A{i,k} = dtrsm(A{i,k}, U);
end
%************************* TRSM Upper *************************
for j = (k+1) : p,
A{k,j} = dtrsm( A{k,j},L);
end
%************************* dia *************************
for j = (k+1) : p,
A{j,j} = dgemm(A{j,j}, A{j,k}, A{k,j}, -1);
%************************* gemm *************************
for i = (j+1):p,
A{i,j} = dgemm(A{i,j}, A{i,k}, A{k,j}, -1);
A{j,i} = dgemm(A{j,i}, A{k,i}, A{j,k}, -1);
end
end
end
AA = A;
function [ X ] = dtrsm( A, B )
[m,n] = size(B);
X = A;
for i = 1 : m,
for k = 1 : m,
X(k,i) = A(k,i) / B(i,i);
end
for j = (i+1) : m,
for k = 1 : m,
A(k,j) = A(k,j) - X(k,i) * B(j,i);
end
end
end
function [oC] = dgemm(iC, iA, iB, ialpha)
oC = iC + ialpha * iA * iB';
end