parfor iteration counter display: dynamic \n at EOL?
6 views (last 30 days)
Show older comments
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
0 Comments
Accepted Answer
Jan
on 13 Nov 2017
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 Comment
Walter Roberson
on 13 Nov 2017
With R2017a or later you can use a data queue or pollable data queue to send data back. See afterEach()
More Answers (0)
See Also
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!