LadFol
LadFol

Reputation: 5

LU decomposition by parallel MATLAB

I'm trying to compute LU decomposition of NxN matrix in MATLAB with parallel toolbox. I would like to use parfor but there is a problem. Steps in for loop are dependent. This is example of my LU decomposition (columns):

function[L, U] = LU_col(A)  

n=size(A,1);
L=eye(n);
U=A    

for k=1:n-1
 L(k+1:n,k) = U(k+1:n,k)/U(k,k);
 for j=k+1:n
   U(k+1:n,j) = U(k+1:n,j) - L(k+1:n,k)*U(k,j);
 end
end

end

Do you have any idea how to solve it with parfor? Thanks

Upvotes: 0

Views: 1035

Answers (2)

Edric
Edric

Reputation: 25140

As High Performance Mark points out, MATLAB's built-in LU is multithreaded and therefore pretty much guaranteed to beat the performance of anything you might try in PARFOR on a single machine. If you have several machines, your best bet is to use a distributed array.

matlabpool open mycluster 64
d = distributed.rand(60000);
[l, u] = lu(d);

Upvotes: 0

Pursuit
Pursuit

Reputation: 12345

The contract for parfor includes the following somewhat vague comment "Restrictions apply to the STATEMENTS in the loop body". These restrictions include anything which prevents this from being embarrassingly parallel. In your case, each element of L and U will be modified by multiple loops, which means that the iterations of the for loop would need some coordination, which triggers Matlab's safety checks on use of the parfor commands.

I would be very surprised if you could find a workaround for this, without implementing a major change to the algorithm.

To echo prior comments, the built-in lu command should be very efficient. As a built-in, it's implementation is most likely compiled C or Fortan with heavy use of best in class linear algebra libraries.

Upvotes: 0

Related Questions