Use parfor to save figure but it tried to display and got hanged

12 次查看(过去 30 天)
Dear all,
I am trying to save several figures at once using parfor. The code works alright in MATLAB 2019b, but after the upgrade to 2022b, the code got stucked at object.displayOutput() in remoteparfoor. Does anyone have any idea? Thanks a lot!
I tried to set the figure visibility to 'off' (set 'visibility' to 'off', and set(0, 'DefaultFigureVisible', 'off')), but they both didn't work.
I tried to close the figure after saving (somehow the figures were saved first, then it got stucked at object.displayOutput)
FigList = findobj(allchild(0), 'flat', 'Type', 'figure');
parfor iFig = 1:length(FigList)
FigHandle = FigList(iFig);
figureFile= [folderPath FigHandle.Name '.png'];
saveas(FigHandle,figureFile);
end
close all;
If paused:
function [tags, results] = getCompleteIntervals(obj, numIntervals)
q = obj.IntervalCompleteQueue;
timeUnitSeconds = iTimeUnitSeconds();
tags = nan(numIntervals, 1);
results = cell(numIntervals, 2);
for i = 1:numIntervals
r = [];
err = [];
while isempty(r)
assert(obj.NumIntervalsInController > 0, ...
'Internal error in PARFOR - no intervals to retrieve.');
r = q.poll(1, timeUnitSeconds);
obj.displayOutput(); % <======= pause here

回答(1 个)

Raghav
Raghav 2023-4-5
Hi,
Based on your question, I understand that you are facing difficulty using saveas function in parfor loop.
After going through the code, everything looks good and should work fine.. However, there might be some issue with the parfor loop. Here are some suggestions you can try to see if they solve the issue:
  1. Try running the code without the parfor loop to see if it works fine.
  2. If running the code without parfor works fine, then try running the code with a regular for loop to see if it works fine.
  3. Try running the code on a different MATLAB version to see if the issue persists.
  4. You can also try using the matlab.io.export_fig package to save figures. It is a very useful tool for exporting figures in different file formats, including png.
  5. If the issue still persists, please reach out to MathWorks technical support for assistance.
Hope it helps!
Thanks,
Raghav Bansal
  1 个评论
Dao Nguyen
Dao Nguyen 2023-7-31
Thank you a lot for your help. It seems there was an issue with the outdated driver for parallel works in my computer. After the update, it works normally.
Best,
Dao

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

产品


版本

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by