From 87df98972969873bf035aa4a1c91280f458c44e3 Mon Sep 17 00:00:00 2001 From: andreas kotowicz Date: Wed, 9 Jul 2014 15:25:01 +0200 Subject: [PATCH] version 0.2.7 - fixes Matlab 2014a problems. --- README.md | 2 +- pool_size.m | 34 +++++++++++++++++++++++++--------- 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index dd22c95..bb75bf7 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ ## A) About -This is version 0.2.6 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.7 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. diff --git a/pool_size.m b/pool_size.m index dadca93..365f5bc 100644 --- a/pool_size.m +++ b/pool_size.m @@ -6,19 +6,31 @@ %% get pool size - this should work for ALL matlab versions try - session = com.mathworks.toolbox.distcomp.pmode.SessionFactory.getCurrentSession; x = 0; - if ~isempty( session ) && session.isSessionRunning() && session.isPoolManagerSession() + + try % this will only work with matlab <= 2013b + session = com.mathworks.toolbox.distcomp.pmode.SessionFactory.getCurrentSession; - try % works with matlab >= 2009b AND 2013a - x = session.getPoolSize(); - catch % works with matlab < 2013a - client = distcomp.getInteractiveObject(); - if strcmp( client.CurrentInteractiveType, 'matlabpool' ) - x = session.getLabs().getNumLabs(); + if ~isempty( session ) && session.isSessionRunning() && session.isPoolManagerSession() + + try % works with matlab >= 2009b && <= 2013b + x = session.getPoolSize(); + catch % works with any matlab version <= 2012b + client = distcomp.getInteractiveObject(); + if strcmp( client.CurrentInteractiveType, 'matlabpool' ) + x = session.getLabs().getNumLabs(); + end end end + + catch % check for matlab == 2014a + poolobj = gcp('nocreate'); + if isempty(poolobj) + x = 0; + else + x = poolobj.NumWorkers; + end end catch me %#ok @@ -29,10 +41,14 @@ %% is matlabpool / parpool active? + active = return_active(x); + +end + +function active = return_active(x) active = 0; if x > 0 active = 1; end - end %% EOF