parallel coding: how to solve linear system?

Hi everyone! I need to solve a (very large) linear system in my code, so I'm trying to use a parallel session.
Basically my original local code does the following:
function U = myfun(U0,J0,nx,S0,Mbcs,Bbcs)
A = spdiags(funA(J0),0,nx,nx);
B = spdiags(funB(J0),0,nx,nx);
C = spdiags(funC(J0),0,nx,nx);
D = spdiags(funD(J0),0,nx,nx);
K = [A B; C D];
V = S0;
K([1,nx,nx+1,2*nx],:)=0;
V([1,nx,nx+1,2*nx])=0;
K = K + Mbcs;
V = V + Bbcs;
U = K\V;
The use of sparse array speeds up a lot the solver time. Now I tried to launch a parallel session:
parpool('local2');
And the code was modified as follows for distributing the matrices to the workers:
K = distributed(K);
V = distributed(V);
But at the end I get this error:
Error using \ (line 48)
Sparse input arguments are not supported.
Error in distributed/wrapRemoteCall>iInnerWrapper (line 83)
[varargout{:}] = fcnH( varargin{:} );
Error in spmd_feval_fcn>get_f/body (line 78)
[outCell{:}] = fcnH( inCell{:} );
Where is the error? I don't know much about parallel programming, but from the examples I found, it seems to me that I only need do distribute the matrix to the workers.
Thanks in advance for all your suggestions.
Pietro

 採用された回答

Edric Ellis
Edric Ellis 2015 年 3 月 19 日

0 投票

Unfortunately, as the error message states, you cannot use the \ operator with sparse distributed arrays at this time.

4 件のコメント

Pietro Pollaci
Pietro Pollaci 2015 年 3 月 19 日
So, which is the solution? Using dense arrays and allocating more memory? I'll try to use diag()! Thanks
John D'Errico
John D'Errico 2015 年 3 月 19 日
Suppose you gain a 10-1 speedup by the use of sparse matrices. This would not be at all surprising. If you go back to dense matrices so that you can use a pool of workers to solve it, then you would need to use a pool with at least 10 workers to get the same speedup, and that just gets you to break-even.
Pietro Pollaci
Pietro Pollaci 2015 年 3 月 19 日
編集済み: Pietro Pollaci 2015 年 3 月 19 日
Then, the use of a pool is not (always) convenient, right? Let us assume, as you wrote, a 10:1 gain then, if I well understood, at least "11" workers are needed in the parallel session in order to get significant advantages. The questions are:
- is it always true?
- does it depend on the size of the problem?
- when does a parallel session beat a sparse-array approach?
Edric Ellis
Edric Ellis 2015 年 3 月 20 日
Unfortunately, the best options you have are either:
  1. Use sparse on your local machine
  2. Use dense distributed arrays on a cluster
  3. Solve a smaller problem
Note that distributed arrays on a single machine almost never offer any benefit since most linear algebra operations are already fairly efficiently multi-threaded by MATLAB, and using a multi-process approach cannot usually compete.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeLinear Algebra についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by