Can a parfor loop be restarted?
조회 수: 1 (최근 30일)
이전 댓글 표시
I am processing large amounts of files. Each file might take thirty minutes to an hour. Here's the code snippet on the high level:
parfor firstfile:lastfile
[morestuff1, morestuff2] = runfunction(stuff1, stuff2);
end
Problem is that every night I leave it running on the server, something wrong happens and the parfor doesn't complete. I want to be able to catch a loop that fails for any reason and restart it later. Here's what I am proposing as the solution:
files = firstfile:lastfile;
while length(files) > 0
parfor currentfile = files
try
[morestuff1, morestuff2] = runfunction(stuff1, stuff2);
files(files == currentfile) = [];
catch
% not sure what to do here
end
end
end
댓글 수: 0
답변 (1개)
OCDER
2018년 6월 11일
Perhaps you can save the input variables used for your runfunction into a separate cell array. Try this for example:
ErrorFile = cell(1, 1000);
parfor k = 1:1000
stuff1 = rand(1);
stuff2 = rand(1);
try
assert(stuff1 > stuff2, 'OOPS: Error in this function!'); %Pretend this is the "runfunction". If there's an error, record the input variables.
catch Msg
ErrorFile{k} = {Msg, k, stuff1, stuff2}; %Save the iteration #, variables, and error message
end
end
ErrorFile(cellfun(@isempty, ErrorFile)) = []; %This stores variables required to redo parfor with errors
cellfun(@(x) display(x{1}), ErrorFile); %Display all the error messages
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!