Clear Filters
Clear Filters

linear least squares/mldivide for large matrices in parallel?

7 views (last 30 days)
I have a really large system to solve using linear least squares. The A matrix can have 2-3 million rows and 2000-3000 columns. The B matrix has same row size but with a single column.
I have access to a supercomputer, and I want to run the x = A\B (or) mldivide(A,B) command in parallel, since I can easily run out of RAM even on workstations with lots of memory.
Any ideas? I am able to run EIG and SVD without any issues in parallel, since I assume it is automatically parallelized by MATLAB. What about linear least squares? Suggestions outside of MATLAB are also welcome. Thanks.

Accepted Answer

Edric Ellis
Edric Ellis on 8 Apr 2015
Edited: Edric Ellis on 8 Apr 2015
If you have access to a cluster of machines, you could use distributed arrays to solve the large system in parallel using the multiple memories. You'll need MATLAB Distributed Computing Server worker licenses on the cluster, and Parallel Computing Toolbox on the client machine. Something like this:
parpool();
A = distributed.rand(20000,2000);
b = sum(A, 2);
x = A\b;
  3 Comments
David
David on 27 Jul 2016
Okay so how do I then load up my distributed matrix? It seems that distributed arrays don't support non scalar right hand assignment... do I really need to loop through the entire 200,000 x 20,000 array in my case one by one? Won't this be really slow compared with the vectorized matrix manipulations I was using before?
I tried stuffing the matrix and then distributing it, but its over my single thread RAM limit at this point.
Sean de Wolski
Sean de Wolski on 27 Jul 2016
David, please ask this in a new question - the answer will end up being to use codistributed arrays inside of spmd.

Sign in to comment.

More Answers (1)

Mahdiyar
Mahdiyar on 8 Apr 2015
Hi Arvind
Parallel computing helps you to use more amount of CPU to run your simulation in a shorter time. As well as I know, when you have memory problem, it does not help you.
What I can suggest you is that you can implement the "x=A\B" by your own code.
I mean that write the m-file to calculate this x = A\B. The only difference is that you have to save your data and delete another one when you do not need it to avoid Memory problem.
For example, to calculate the A\B, you need to calculate A^(-1). Thus, first, JUST load matrix A and calculate A^(-1) and then save that matrix as a matrix and delete matrix A (be cause you do not need it anymore).
I hope it helps you.
Regards,

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!