Skip to content

Commit

Permalink
version 1.23.1
Browse files Browse the repository at this point in the history
- ParforProgressServer2 class updates:
 - support usage of multiple objects in parallel (removed static from time_start & CurrentRuntime())
 - added version number & getVersion() method
 - left comment on where to change progress bar width & height
- README:
 - added usage instructions for macOS
 - added compile instructions
- re-compiled java code with openjdk 13
- ParforProgressStarter2.m:
 - added check for pctRunOnAll / javaaddpath / addpath
  • Loading branch information
kotowicz committed Oct 5, 2023
1 parent 8c15151 commit 1905d8c
Show file tree
Hide file tree
Showing 10 changed files with 95 additions and 44 deletions.
25 changes: 16 additions & 9 deletions ParforProgress2.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,22 @@
% end of each iteration. This sends a notification back to the server which
% then updates the GUI.
%
% Example:
%
% N = 100;
% ppm = ParforProgress2('my task', N);
% parfor i = 1 : N
% rand(1);
% ppm.increment(i);
% end
% delete(ppm);
% Example:
%{
N = 10000;
ppm = ParforProgress2('my task', N);
parfor i = 1 : N
rand(1);
ppm.increment(i);
end
delete(ppm);
%}
%
%
% Copyright (c) 2010-2014, Andreas Kotowicz
% Copyright (c) 2010-2023, Andreas Kotowicz

classdef ParforProgress2 < handle

Expand Down Expand Up @@ -86,6 +90,9 @@
o.JavaBit = ParforProgressServer2.createServer(s, n, percentage, use_gui, show_execution_time);
o.Port = double(o.JavaBit.getPort());

% get the version number
% o.JavaBit.getVersion()

% Get the client host name from pctconfig - needs
% distcomp toolbox.
% cfg = pctconfig;
Expand Down
Binary file modified ParforProgressClient2.class
Binary file not shown.
2 changes: 1 addition & 1 deletion ParforProgressClient2.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010-2014, Andreas Kotowicz
* Copyright (c) 2010-2023, Andreas Kotowicz
*
*
* ideas for this code are from:
Expand Down
2 changes: 1 addition & 1 deletion ParforProgressConsole2.m
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
% use ParforProgressStarter() instead.
% not using saveobj and loadobj, because old matlab versions have problems
% with it.
% Copyright (c) 2010-2014, Andreas Kotowicz
% Copyright (c) 2010-2023, Andreas Kotowicz

properties (GetAccess = private, SetAccess = private)
message
Expand Down
Binary file modified ParforProgressServer2$1.class
Binary file not shown.
Binary file modified ParforProgressServer2.class
Binary file not shown.
16 changes: 11 additions & 5 deletions ParforProgressServer2.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010-2014, Andreas Kotowicz
* Copyright (c) 2010-2023, Andreas Kotowicz
*
*
* ideas for this code are from:
Expand Down Expand Up @@ -41,13 +41,13 @@

import java.awt.GridLayout;
import java.awt.event.*;

import java.io.Console;

import java.util.concurrent.atomic.AtomicBoolean;

public class ParforProgressServer2 implements Runnable, ActionListener {

private static final String VERSION = "1.23.1";

private JFrame fFrame;
private JLabel fLabel;
private JProgressBar fBar;
Expand Down Expand Up @@ -141,6 +141,11 @@ public synchronized void updateGUI(){

}

// Getter method for version
public static String getVersion() {
return VERSION;
}

private double goal;
private double PERCENTAGE = 0.05;
private double fraction_all;
Expand All @@ -150,7 +155,7 @@ public synchronized void updateGUI(){
private double ETA_time = 0;

// when did the monitor start / stop?
private static double time_start;
private double time_start;
private static double time_stop;

private ServerSocketChannel serverSocket;
Expand All @@ -172,7 +177,7 @@ public static double Round(double val, int places) {
return (double) tmp / factor;
}

public static String CurrentRuntime(int precision) {
public String CurrentRuntime(int precision) {
String runtime;
time_stop = System.currentTimeMillis();

Expand Down Expand Up @@ -258,6 +263,7 @@ public void windowClosing(WindowEvent e) {
}
});

// change width & height of progress bar here, then recompile
fFrame.setSize(300, 75);
fFrame.setVisible(true);
fFrame.setResizable(true);
Expand Down
31 changes: 26 additions & 5 deletions ParforProgressStarter2.m
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
%
%%%%%%%%%%%%%% End ParforProgressStarter2 suggested usage %%%%%%%%%%%%%%%%%
%
% Copyright (c) 2010-2014, Andreas Kotowicz
% Copyright (c) 2010-2023, Andreas Kotowicz
%
%%

Expand Down Expand Up @@ -126,16 +126,21 @@
a = which(mfilename);
dir_to_add = fileparts(a);

pathDelimiter = pathsep; % Gets the path delimiter based on OS
if pool_slaves > 0
if java_enabled == 1 && run_javaaddpath == 1
if java_enabled == 1 && run_javaaddpath == 1 && ~isInJavaPath(dir_to_add)
pctRunOnAll(['javaaddpath({''' dir_to_add '''})']);
end
pctRunOnAll(['addpath(''' dir_to_add ''')']);
if ~isInMatlabPath(dir_to_add, pathDelimiter)
pctRunOnAll(['addpath(''' dir_to_add ''')']);
end
else
if java_enabled == 1 && run_javaaddpath == 1
if java_enabled == 1 && run_javaaddpath == 1 && ~isInJavaPath(dir_to_add)
javaaddpath({dir_to_add});
end
addpath(dir_to_add);
if ~isInMatlabPath(dir_to_add, pathDelimiter)
addpath(dir_to_add);
end
end

%%
Expand All @@ -156,4 +161,20 @@
end

end


%% Helper functions
function isPresent = isInJavaPath(dir_to_check)
currentStaticJavaPath = javaclasspath('-static');
currentDynamicJavaPath = javaclasspath('-dynamic');
combinedJavaPath = [currentStaticJavaPath; currentDynamicJavaPath];
isPresent = any(strcmp(dir_to_check, combinedJavaPath));
end

function isPresent = isInMatlabPath(dir_to_check, pathDelimiter)
currentPath = strsplit(path, pathDelimiter);
isPresent = any(strcmp(dir_to_check, currentPath));
end

%% EOF

4 changes: 2 additions & 2 deletions ParforProgressStressTest2.m
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ function ParforProgressStressTest2(N, run_javaaddpath, show_execution_time)
% use this function to determine how many simultaneous connections your
% computer can handle, and adjust the ppm.increment() call accordingly.
%
% Copyright (c) 2010-2014, Andreas Kotowicz
% Copyright (c) 2010-2023, Andreas Kotowicz
%
%%

Expand All @@ -20,7 +20,7 @@ function ParforProgressStressTest2(N, run_javaaddpath, show_execution_time)

if nargin < 1
% how many iterations of the for loop do we run?
N = 10000;
N = 5000;
end

%% initialize ParforProgress monitor
Expand Down
59 changes: 38 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## A) About

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 is version 1.23.1 of `ParforProgress2`, a simple parfor progress monitor for matlab. See also matlab-ParforProgress2 on File Exchange [![View matlab-ParforProgress2 on File Exchange](https://www.mathworks.com/matlabcentral/images/matlab-file-exchange.svg)](https://de.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 @@ -40,29 +41,36 @@ $ cd .matlab/R2013a
$ echo "/path/to/matlab-ParforProgress2" > javaclasspath.txt
```

Next, startup Matlab and call `ParforProgressStarter2`, but do not run `javaddpath`:
On macOS this translates to:
```
$ cd ~/Library/Application\ Support/MathWorks/MATLAB/R2020a/
$ echo "/Users/username/Documents/GitHub/matlab-ParforProgress2" > javaclasspath.txt
```


Next, startup Matlab (or restart Matlab if it was running) and call `ParforProgressStarter2`, but do not run `javaddpath`:


```
>> % 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, show_execution_time)
>>
>> % run your computation
>> for j = 1 : n
>> your_computation();
>> ppm.increment(i);
>> end
>>
>> % delete the ProgressMonitor
>> delete(ppm);
% 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, show_execution_time)
% run your computation
for j = 1 : n
your_computation();
ppm.increment(j);
end
% delete the ProgressMonitor
delete(ppm);
```


Expand All @@ -81,4 +89,13 @@ edit this file. Here's how you can locate it:



## D) Recompile

On macOS

```
javac -source 1.8 -target 1.8 -cp .: ParforProgressServer2.java
javac -source 1.8 -target 1.8 -cp .: ParforProgressClient2.java
```


0 comments on commit 1905d8c

Please sign in to comment.