parfor iteration counter display: dynamic \n at EOL?

1 次查看(过去 30 天)
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