parfeval performance inside appdesigner apps
24 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I have an image processing routine that takes 4-5s when run on a single thread. If parallelized using parfeval() inside an m script and function file the time elapsed is ~2s. When I use the same methods inside an appdesigner (where the structure of functions has to be adapted such that the function takes in 'app') I see weird things. E.g. if the funtion is structured in a manner as below I see warning message Warning: Unable to save App Designer app object. Save notsupported for matlab.apps.AppBase objects.
% Style-1 %
function result = somePrivateFcn(app,img,a,b)
%
F(1) = parfeval(Pool,@processImg,1,img(1:500,1:500),Type,1);
F(2) = parfeval(Pool,@processImg,1,img(1:500,501:end),Type,1);
% some processing %
function out = processImg(img,Type,N)
%some processing
out = x.centroid;
end
end
I'm confused by the warning since I'm not passing in the app object to the processImg subfunction. Perhaps all the workspace of parent function needs to be available and hence app object from parent function needs to be copied to workers. I don't know if this is the reason but the execution takes 6s instead of expected 2s.
I tried taking the processImg() out of the somePrivateFcn() and made it just another private function with definitions like below that would ensure app object is not copied to workers (just using 0 instead of app).
% Style-2 %
function result = somePrivateFcn(app,img,a,b)
F(1) = parfeval(Pool,@processImg,1,0,img(1:500,1:500),Type,1);
F(2) = parfeval(Pool,@processImg,1,0,img(1:500,501:end),Type,1);
% some processing %
end
function out = processImg(~,img,Type,N)
%some processing
out = x.centroid;
end
This however showed new messages in cmd window (not warning, just info) Analyzing and transferring files to the workers ...done. The execution time now shot to ~15s.
I tried creating a separate mfile for procesImg function to get rid of the need to pass app obj. This time there were no warnings or messages but the processing time rose to 12s.
Can someone help understand what's going on. What should I do to get the performance of parfeval in appdesigner on par with that in script implementation?
Last year in a different project (using R2023a) I recall doing a task like in style-2 above but with app object sent to processImg() when called from parfeval and also app mentioned in the function definition of processImg() (instead of being skipped with ~). The parallel exection worked fine and I never saw save App warnings or the "... transferring data..." message ever. Has the behaviour changed between R2023a and R2023b?
Thanks.
3 comentarios
Rik
el 1 de Nov. de 2024
If your license allows, you might want to create a support ticket. This sounds like an issue with the Matlab internals to me.
Respuestas (0)
Ver también
Categorías
Más información sobre Develop Apps Using App Designer 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!