Skip to content

Commit

Permalink
use option "show_execution_time" to enable/disable execution time dis…
Browse files Browse the repository at this point in the history
…play.
  • Loading branch information
kotowicz committed Jul 9, 2014
1 parent 87df989 commit 4fa1b48
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 18 deletions.
10 changes: 7 additions & 3 deletions ParforProgress2.m
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
end

methods
function o = ParforProgress2(s, n, percentage, do_debug, use_gui)
function o = ParforProgress2(s, n, percentage, do_debug, use_gui, show_execution_time)
% ParforProgress Build a Parfor Progress Monitor
% Use the syntax: ParforProgress( 'Window Title', N, percentage, do_debug, use_gui )
% where N is the number of iterations in the PARFOR loop
Expand All @@ -60,7 +60,11 @@
o.Port = [];

% initialize server
elseif (nargin == 5 || nargin == 4 || nargin == 3 || nargin == 2)
elseif (nargin == 6 || nargin == 5 || nargin == 4 || nargin == 3 || nargin == 2)

if nargin < 6
show_execution_time = 1;
end

if nargin < 5
use_gui = 1;
Expand All @@ -79,7 +83,7 @@
o.OldVersion = 1;
end

o.JavaBit = ParforProgressServer2.createServer(s, n, percentage, use_gui);
o.JavaBit = ParforProgressServer2.createServer(s, n, percentage, use_gui, show_execution_time);
o.Port = double(o.JavaBit.getPort());

% Get the client host name from pctconfig - needs
Expand Down
Binary file modified ParforProgressServer2$1.class
Binary file not shown.
Binary file modified ParforProgressServer2.class
Binary file not shown.
15 changes: 9 additions & 6 deletions ParforProgressServer2.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ public class ParforProgressServer2 implements Runnable, ActionListener {
private boolean USE_GUI = true;
private int counter;
private int DEBUG = 0;
private AtomicBoolean show_execution_time_executed;
private AtomicBoolean enable_show_execution_time; // should we run / execute "show_execution_time"?
private AtomicBoolean show_execution_time_executed; // did we execute "show_execution_time"?
private AtomicBoolean stop_program_executed;
private Console console;

Expand Down Expand Up @@ -207,10 +208,10 @@ public String ETA(int maximum) {
* Create a "server" progress monitor - this runs on the desktop client and
* pops up the progress monitor UI.
*/
public static ParforProgressServer2 createServer(String s, int N, double update_percentage, boolean use_gui) throws IOException {
public static ParforProgressServer2 createServer(String s, int N, double update_percentage, boolean use_gui, boolean show_execution_time) throws IOException {
ParforProgressServer2 ret = new ParforProgressServer2();
int show_port = 0;
ret.setup(s, N, update_percentage, show_port, use_gui);
ret.setup(s, N, update_percentage, show_port, use_gui, show_execution_time);
ret.start();
return ret;
}
Expand Down Expand Up @@ -313,15 +314,16 @@ public static void main( String args[] ) {
ParforProgressServer2 myserver = new ParforProgressServer2();
int show_port = 1;
boolean use_gui = true;
myserver.setup(displayString, totalNumberRuns, updateEachPercent, show_port, use_gui);
boolean show_execution_time = true;
myserver.setup(displayString, totalNumberRuns, updateEachPercent, show_port, use_gui, show_execution_time);
myserver.start();
}

public int getPort() {
return ((InetSocketAddress)serverSocket.socket().getLocalSocketAddress()).getPort();
}

public void setup(String s, int N, double update_percentage, int show_port, boolean use_gui) {
public void setup(String s, int N, double update_percentage, int show_port, boolean use_gui, boolean show_execution_time) {

serverSocket = null;

Expand Down Expand Up @@ -364,6 +366,7 @@ public void setup(String s, int N, double update_percentage, int show_port, bool

show_execution_time_executed = new AtomicBoolean(false);
stop_program_executed = new AtomicBoolean(false);
enable_show_execution_time = new AtomicBoolean(show_execution_time);

// initialize console output
console = System.console();
Expand Down Expand Up @@ -477,7 +480,7 @@ public void stop_program() {
}

public void show_execution_time() {
if (show_execution_time_executed.get() == false) {
if (show_execution_time_executed.get() == false && enable_show_execution_time.get() == true) {

show_execution_time_executed.set(true);

Expand Down
16 changes: 11 additions & 5 deletions ParforProgressStarter2.m
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function ppm = ParforProgressStarter2(s, n, percentage, do_debug, run_javaaddpath)
function ppm = ParforProgressStarter2(s, n, percentage, do_debug, run_javaaddpath, show_execution_time)
% Starter function for parfor progress-monitor, that will automatically
% choose between a text or a GUI progress monitor. You can use this
% progress-monitor in both for and parfor loops.
Expand All @@ -19,8 +19,10 @@
% % by default we always run 'javaaddpath'. Set this to 0 if you are
% % making use of globals.
% run_javaaddpath = 1;
% % by default we show the execution time once ParforProgress ends.
% show_execution_time = 1;
% try % Initialization
% ppm = ParforProgressStarter2('test', N, percentage_update, do_debug, run_javaaddpath);
% ppm = ParforProgressStarter2('test', N, percentage_update, do_debug, run_javaaddpath, show_execution_time);
% catch me % make sure "ParforProgressStarter2" didn't get moved to a different directory
% if strcmp(me.message, 'Undefined function or method ''ParforProgressStarter2'' for input arguments of type ''char''.')
% error('ParforProgressStarter2 not in path.');
Expand Down Expand Up @@ -51,7 +53,7 @@
%%

if nargin < 2
disp('usage: ppm = ParforProgressStarter2( text, number_runs, update_percentage, do_debug, run_javaaddpath )');
disp('usage: ppm = ParforProgressStarter2( text, number_runs, update_percentage, do_debug, run_javaaddpath, show_execution_time )');
ppm = [];
return;
end
Expand All @@ -67,6 +69,10 @@
if nargin < 5
run_javaaddpath = 1;
end

if nargin < 6
show_execution_time = 1;
end

%% determine whether java and awt are available
java_enabled = 1;
Expand Down Expand Up @@ -126,10 +132,10 @@
switch version_to_use
case 1
use_gui = 1;
ppm = ParforProgress2(s, n, percentage, do_debug, use_gui);
ppm = ParforProgress2(s, n, percentage, do_debug, use_gui, show_execution_time);
case 2
use_gui = 0;
ppm = ParforProgress2(s, n, percentage, do_debug, use_gui);
ppm = ParforProgress2(s, n, percentage, do_debug, use_gui, show_execution_time);
case 3
% no java, no awt, or old matlab version
disp('Progress will update in arbitrary order.');
Expand Down
9 changes: 7 additions & 2 deletions ParforProgressStressTest2.m
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function ParforProgressStressTest2(N, run_javaaddpath)
function ParforProgressStressTest2(N, run_javaaddpath, show_execution_time)
% Stress test for 'ParforProgressStarter2'. In case of timeouts, you can
% use this function to determine how many simultaneous connections your
% computer can handle, and adjust the ppm.increment() call accordingly.
Expand All @@ -7,6 +7,11 @@ function ParforProgressStressTest2(N, run_javaaddpath)
%
%%

if nargin < 3
% by default we show the execution time once ParforProgress ends.
show_execution_time = 1;
end

if nargin < 2
% by default we always run 'javaaddpath'. Set this to 0 if you are
% making use of globals.
Expand All @@ -25,7 +30,7 @@ function ParforProgressStressTest2(N, run_javaaddpath)
% show debugging information.
do_debug = 1;
try % Initialization
ppm = ParforProgressStarter2('test task - ParforProgressStarter2', N, percentage_update, do_debug, run_javaaddpath);
ppm = ParforProgressStarter2('test task - ParforProgressStarter2', N, percentage_update, do_debug, run_javaaddpath, show_execution_time);
catch me % make sure "ParforProgressStarter2" didn't get moved to a different directory
if strcmp(me.message, 'Undefined function or method ''ParforProgressStarter2'' for input arguments of type ''char''.')
error('ParforProgressStarter2 not in path.');
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## A) About

This is version 0.2.7 of `ParforProgress2`, a simple parfor progress monitor for matlab. See also http://www.mathworks.com/matlabcentral/fileexchange/35609-matlab-parforprogress2.
This is version 0.2.8 of `ParforProgress2`, a simple parfor progress monitor for matlab. See also http://www.mathworks.com/matlabcentral/fileexchange/35609-matlab-parforprogress2.

This progress monitor comes with a nice wrapper [`ParforProgressStarter2.m`](ParforProgressStarter2.m) which will take care of adding the classes to the java class path, depending on whether matlabpool / parpool is enabled or not.

Expand Down Expand Up @@ -45,14 +45,15 @@ Next, startup Matlab and call `ParforProgressStarter2`, but do not run `javaddpa

```
>> % setup parameters
>> show_execution_time = 1;
>> run_javaaddpath = 0;
>> s = 'dummy task';
>> n = 100;
>> percentage = 0.1;
>> do_debug = 0;
>>
>> % initialize the ProgressMonitor
>> ppm = ParforProgressStarter2(s, n, percentage, do_debug, run_javaaddpath)
>> ppm = ParforProgressStarter2(s, n, percentage, do_debug, run_javaaddpath, show_execution_time)
>>
>> % run your computation
>> for j = 1 : n
Expand Down

0 comments on commit 4fa1b48

Please sign in to comment.