Borrar filtros
Borrar filtros

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

12 visualizaciones (últimos 30 días)
Dao Nguyen
Dao Nguyen el 8 de Feb. de 2023
Comentada: Dao Nguyen el 31 de Jul. de 2023
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

Respuestas (1)

Raghav
Raghav el 5 de Abr. de 2023
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 comentario
Dao Nguyen
Dao Nguyen el 31 de Jul. de 2023
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

Iniciar sesión para comentar.

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Productos


Versión

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by