-
Notifications
You must be signed in to change notification settings - Fork 3
/
pool_size.m
54 lines (43 loc) · 1.57 KB
/
pool_size.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
function [x, active] = pool_size()
%POOL_SIZE - temporary hack to return size of current MATLABPOOL / PARPOOL
%
% see:
% http://www.mathworks.com/support/solutions/en/data/1-5UDHQP/index.html?product=DM&solution=1-5UDHQP
%% get pool size - this should work for ALL matlab versions
try
x = 0;
try % this will only work with matlab <= 2013b
session = com.mathworks.toolbox.distcomp.pmode.SessionFactory.getCurrentSession;
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<NASGU>
% standalone matlab installations might not have the appropriate
% com module installed.
x = 0;
end
%% is matlabpool / parpool active?
active = return_active(x);
end
function active = return_active(x)
active = 0;
if x > 0
active = 1;
end
end
%% EOF