Using symbolic subs call inside parfor loop
4 ビュー (過去 30 日間)
古いコメントを表示
I have the following pieces of code where the symbolic expressions to be evaluated are quite heavy.
classdef T4
properties (SetAccess = private)
% symbolic properties
xe % vector of symbolic variables
ge % vector or matrix of symbolic expressions depending on xe
% numeric properties
se % numeric vector or matrix
Xe % numeric values to be assigned
end
methods
% all other methods
function T = computeG(T);
T.se = double(subs(T.ge,T.xe,T.Xe));
end
end
end
nT = 5;
Tv(nT,1) = T4;
for i=1:nT
Tv(i) = computeG(Tv(i));
end
I do not get any gain, in fact it is worse if I use instead
parfor i=1:nT
Tv(i) = computeG(Tv(i));
end
3 件のコメント
Walter Roberson
2020 年 10 月 14 日
My tests show that one mupad kernel process is allocated for each worker. (The kernels use a lot less memory than I might have guessed. They also have about 39 megabytes of shared memory; I am not sure what that is used for.)
回答 (1 件)
Raymond Norris
2020 年 10 月 13 日
Hi Antonio,
You're just not giving each of the workers enough work to do. Maybe you only need to run nT=5, but see what happens when you set it to 100, 200, or 1000. You should then start to see improvements.
Thanks,
Raymond
5 件のコメント
Walter Roberson
2020 年 10 月 14 日
My test showed that a separate mupad kernel is launched for each parfor worker, so there would be no need to rewrite the symbolic functions themselves: each worker gets its own (single-threaded) engine.
It is not possible to rewrite the internals of symbolic functions to use parfor / spmd, as the internals of symbolic functions live inside the MuPAD engine, either in the form of binary files are in the form of MuPAD code.
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!