- 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)
- 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.)
- 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.
Parallel.pool.consant slowing down code by a factor of 3, how to distribute many arrays to different variables
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Samuel Christensen
el 21 de Jul. de 2019
Respondida: Edric Ellis
el 26 de Jul. de 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 comentarios
Respuesta aceptada
Edric Ellis
el 26 de Jul. de 2019
parallel.pool.Constant is useful in essentially three different ways:
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 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Parallel for-Loops (parfor) en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!