diff --git a/ParforProgress2.m b/ParforProgress2.m index 47a685d..12129a8 100644 --- a/ParforProgress2.m +++ b/ParforProgress2.m @@ -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 @@ -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; diff --git a/ParforProgressClient2.class b/ParforProgressClient2.class index 8de1757..a5443f4 100644 Binary files a/ParforProgressClient2.class and b/ParforProgressClient2.class differ diff --git a/ParforProgressClient2.java b/ParforProgressClient2.java index 536e7a5..a2ef463 100644 --- a/ParforProgressClient2.java +++ b/ParforProgressClient2.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010-2014, Andreas Kotowicz + * Copyright (c) 2010-2023, Andreas Kotowicz * * * ideas for this code are from: diff --git a/ParforProgressConsole2.m b/ParforProgressConsole2.m index d2f792a..50a30a4 100644 --- a/ParforProgressConsole2.m +++ b/ParforProgressConsole2.m @@ -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 diff --git a/ParforProgressServer2$1.class b/ParforProgressServer2$1.class index 331bfe0..cf6551f 100644 Binary files a/ParforProgressServer2$1.class and b/ParforProgressServer2$1.class differ diff --git a/ParforProgressServer2.class b/ParforProgressServer2.class index 19fb3fa..8b7f2fb 100644 Binary files a/ParforProgressServer2.class and b/ParforProgressServer2.class differ diff --git a/ParforProgressServer2.java b/ParforProgressServer2.java index 6524a7d..c57cceb 100644 --- a/ParforProgressServer2.java +++ b/ParforProgressServer2.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010-2014, Andreas Kotowicz + * Copyright (c) 2010-2023, Andreas Kotowicz * * * ideas for this code are from: @@ -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; @@ -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; @@ -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; @@ -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(); @@ -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); diff --git a/ParforProgressStarter2.m b/ParforProgressStarter2.m index 6c50425..143dc11 100644 --- a/ParforProgressStarter2.m +++ b/ParforProgressStarter2.m @@ -58,7 +58,7 @@ % %%%%%%%%%%%%%% End ParforProgressStarter2 suggested usage %%%%%%%%%%%%%%%%% % -% Copyright (c) 2010-2014, Andreas Kotowicz +% Copyright (c) 2010-2023, Andreas Kotowicz % %% @@ -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 %% @@ -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 + diff --git a/ParforProgressStressTest2.m b/ParforProgressStressTest2.m index 3c95e9d..ea63966 100644 --- a/ParforProgressStressTest2.m +++ b/ParforProgressStressTest2.m @@ -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 % %% @@ -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 diff --git a/README.md b/README.md index fc1b25f..28a1323 100644 --- a/README.md +++ b/README.md @@ -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. @@ -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); ``` @@ -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 +``` +