parfor iteration counter display: dynamic \n at EOL?

조회 수: 1 (최근 30일)
Matlabber 1.0
Matlabber 1.0 2017년 11월 13일
댓글: Walter Roberson 2017년 11월 13일
dear all, I made myself a function that compactifies the counter output line display in loops, and it works like a charm:
function [ output_args ] = f_CompactCount(c,f,r,d)
% compactifies commandline counter printing
% c = counter
% f = only every f-th number printed
% r = amount of counter displays per line
% d = digits per number
if mod(c,f)==0;
string=strcat('%',num2str(d),'.d');
if mod(c,r*f)==0
fprintf(strcat(string,'\n'),c)
else
fprintf(string,c)
end
end
end
it prints out every f-th counter number, r times per line of output and d digits (incl. space) per counter print. After the r-th time, at the end of a line, a new line is started.
Now, if i use this in par for loops, it is messed up since the counter follows a random sequence. How can I modify this counter display such that a line break occurs after r counter prints?
[edit] my idea would be to check how long the current command line output is and create a new line based on that or something

채택된 답변

Jan
Jan 2017년 11월 13일
You use parfor to run the different jobs independently in parallel. Now you want, that the threads communicate with each other for a coordinated output to the command window.
You find some progressbars for parfor in the file exchange: https://de.mathworks.com/matlabcentral/fileexchange/?utf8=%E2%9C%93&term=parfor. Some use a communication through files, what is a really bad idea. E.g. this looks stable: https://de.mathworks.com/matlabcentral/fileexchange/24594-parfor-progress-monitor. Perhaps you can modify it to support an output to the command window.
  댓글 수: 1
Walter Roberson
Walter Roberson 2017년 11월 13일
With R2017a or later you can use a data queue or pollable data queue to send data back. See afterEach()

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Parallel for-Loops (parfor)에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by