Rank: 1358 based on 114 downloads (last 30 days) and 1 file submitted
photo

Jeremy

E-mail

Personal Profile:
Professional Interests:

 

Watch this Author's files

 

Files Posted by Jeremy
Updated   File Tags Downloads
(last 30 days)
Comments Rating
25 Oct 2011 Progress monitor (progress bar) that works with parfor Displays the percentage of parfor iterations which have completed. Author: Jeremy parfor, progress bar, progressbar, status, progress, progress monitor 114 8
  • 4.66667
4.7 | 9 ratings
Comments and Ratings by Jeremy View all
Updated File Comments Rating
15 Jun 2012 Conditionally colored line plot Plots (2D line) graph split into two colors above and below a given threshold value Author: Matt Tearle

It works well as described, but could be improved by handling multiple thresholds.

05 Mar 2012 Progress monitor (progress bar) that works with parfor Displays the percentage of parfor iterations which have completed. Author: Jeremy

Ashin,

I develop on Linux and I've never seen this problem. So it's likely that it is not a Linux problem in general, but it's specific to your particular setup. Maybe something to do with the character encoding on your system?

As a test, run this and see what it outputs:

disp(['aaa', char(8)])

The output should be just aa, because char(8) is a backspace. This is the technique I used in parfor_progress to delete the previous line, so maybe the backspace isn't working on your Linux machine for some reason?

Or does anyone know of a more universally portable way of doing this?

11 Oct 2010 AREA3 Filled area plot in 3d. Author: Dirk Heber

Change break; to return; on line 95 and it seems to still work fine on recent versions of MATLAB.

Comments and Ratings on Jeremy's Files View all
Updated File Comment by Comments Rating
14 Oct 2013 Progress monitor (progress bar) that works with parfor Displays the percentage of parfor iterations which have completed. Author: Jeremy Naseri, Hassan

06 Oct 2013 Progress monitor (progress bar) that works with parfor Displays the percentage of parfor iterations which have completed. Author: Jeremy Coombs, Jesse

Would it be possible to get a version that instead prints the %complete to a txt file for use in monitoring jobs on remote/server pc's?

02 Jul 2013 Progress monitor (progress bar) that works with parfor Displays the percentage of parfor iterations which have completed. Author: Jeremy Corbetta, Alessandro

Excellent work!
Although it works badly on linux -nodesktop mode. In this case, the older (and less complete) bars remain showed in the console.
As a consequence, the screen is full of more or less complete version of the bar in few seconds.

10 Jun 2013 Progress monitor (progress bar) that works with parfor Displays the percentage of parfor iterations which have completed. Author: Jeremy Liutkus, Antoine

02 Jun 2013 Progress monitor (progress bar) that works with parfor Displays the percentage of parfor iterations which have completed. Author: Jeremy German

Thanks for the file. It works!
As Timo suggested, if there are several instances of MATLAB running (e.g., multi-core server), it won't work properly.
It can be easily solved by adding a randon sequence to the file name.

function percent = parfor_progress(N)
%PARFOR_PROGRESS Progress monitor (progress bar) that works with parfor.
% PARFOR_PROGRESS works by creating a file called parfor_progress.txt in
% your working directory, and then keeping track of the parfor loop's
% progress within that file. This workaround is necessary because parfor
% workers cannot communicate with one another so there is no simple way
% to know which iterations have finished and which haven't.
%
% PARFOR_PROGRESS(N) initializes the progress monitor for a set of N
% upcoming calculations.
%
% PARFOR_PROGRESS updates the progress inside your parfor loop and
% displays an updated progress bar.
%
% PARFOR_PROGRESS(0) deletes parfor_progress.txt and finalizes progress
% bar.
%
% To suppress output from any of these functions, just ask for a return
% variable from the function calls, like PERCENT = PARFOR_PROGRESS which
% returns the percentage of completion.
%
% Example:
%
% N = 100;
% parfor_progress(N);
% parfor i=1:N
% pause(rand); % Replace with real code
% parfor_progress;
% end
% parfor_progress(0);
%
% See also PARFOR.

% By Jeremy Scheff - jdscheff@gmail.com - http://www.jeremyscheff.com/
error(nargchk(0, 1, nargin, 'struct'));

persistent fname;

if nargin < 1
N = -1;
end

percent = 0;
w = 50; % Width of progress bar

if N > 0
rndseq = round(10^6*rand(1));
fname = strcat('parfor_progress_',num2str(rndseq),'.txt');

f = fopen(fname, 'w');
if f<0
error('Do you have write permissions for %s?', pwd);
end
fprintf(f, '%d\n', N); % Save N at the top of progress.txt
fclose(f);

if nargout == 0
disp([' 0%[>', repmat(' ', 1, w), ']']);
end
elseif N == 0
delete(fname);
percent = 100;

if nargout == 0
disp([repmat(char(8), 1, (w+9)), char(10), '100%[', repmat('=', 1, w+1), ']']);
end
else
if ~exist(fname, 'file')
error([fname,' not found. Run PARFOR_PROGRESS(N) before PARFOR_PROGRESS to initialize ',fname]);
end

f = fopen(fname, 'a');
fprintf(f, '1\n');
fclose(f);

f = fopen(fname, 'r');
progress = fscanf(f, '%d');
fclose(f);
percent = (length(progress)-1)/progress(1)*100;

if nargout == 0
perc = sprintf('%3.0f%%', percent); % 4 characters wide, percentage
disp([repmat(char(8), 1, (w+9)), char(10), perc, '[', repmat('=', 1, round(percent*w/100)), '>', repmat(' ', 1, w - round(percent*w/100)), ']']);
end
end

Contact us