MATLAB Answers

0

Parallel.pool.consant slowing down code by a factor of 3, how to distribute many arrays to different variables

Asked by Samuel Christensen on 21 Jul 2019
Latest activity Answered by Edric Ellis
on 26 Jul 2019
I am trying to solve many different linear systems using gmres, each system has it's own individual matrix, but they all use the same preconditioners. I am also using a function handle to evaluate the preconditioner backsolve. Essentially,
parfor i=1:N
X{i} = gmres(A{i}, b{i}, maxit, tol, @(x) mfun(x,M{i}));
end
The individual solves take about 9 iterations and take about 0.02 seconds each, I found changing it to essentially
parfor i=1:N
for j =1:n
X{j} = gmres(A{j}, b{j}, maxit, tol, @(x) mfun(x,M{j}));
end
Xstore(i) = X;
end
was faster and was able to beat doing things in serial for small systems. In this implimentation each worker uses every preconditioner.
I tried implementing both
Mpool = parallel.pool.Constant(@() M);
and
Mpool = parallel.pool.Constant(M);
both slowed down code significantly. CPU utilization was lower and the individual gmres solves were significantly slower, there was some memory improvement.
What am I doing wrong?

  0 Comments

Sign in to comment.

Products


Release

R2019a

1 Answer

Answer by Edric Ellis
on 26 Jul 2019
 Accepted Answer

parallel.pool.Constant is useful in essentially three different ways:
  1. It can offer a performance gain by avoiding repeated transfers of data from the client to the workers (i.e. when you have several parfor loops accessing the same large dataset)
  2. It can make stuff work that otherwise would be difficult by constructing objects directly on the workers (such as a database connection, connection to a hardware device, etc.)
  3. Similar to (2), if a really large piece of data can be constructed on the workers more quickly than transferring from the client, this can be beneficial even for only a single parfor loop.
It seems like your case doesn't fit into any of those categories - you have only a single parfor loop, and the data can be transferred from the client. Perhaps the only possible benefit you could get from parallel.pool.Constant is if you could create it like this:
Mpool = parallel.pool.Constant(@buildM)
where buildM is a function returning M.

  0 Comments

Sign in to comment.