parfor iteration counter display: dynamic \n at EOL?

1 visualización (últimos 30 días)
Matlabber 1.0
Matlabber 1.0 el 13 de Nov. de 2017
Comentada: Walter Roberson el 13 de Nov. de 2017
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

Respuesta aceptada

Jan
Jan el 13 de Nov. de 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 comentario
Walter Roberson
Walter Roberson el 13 de Nov. de 2017
With R2017a or later you can use a data queue or pollable data queue to send data back. See afterEach()

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Parallel for-Loops (parfor) en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by