-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPCPool.m
More file actions
80 lines (71 loc) · 2.35 KB
/
PCPool.m
File metadata and controls
80 lines (71 loc) · 2.35 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
classdef PCPool < handle
% Manage the parpool/matlabpool handling independent of the
% current MatLab release.
% This has been introduced to maximize backwards compatibility of
% KerMor. PCPool = "Parallel Computing Pool".
properties(Constant)
% For versions older than 8.3 (R2014a) we still have the
% matlabpool syntax available. (could be a different one, but
% doesnt really matter)
OldSyntax = verLessThan('matlab','8.3.0');
end
methods(Static)
function res = isAvailable
if PCPool.OldSyntax
res = exist('matlabpool','file') == 2;
else
res = exist('parpool','file') == 2;
end
end
function res = isOpen
% Checks if the parpool is open and active.
if PCPool.OldSyntax
res = matlabpool('size') > 0;%#ok
else
res = ~isempty(gcp('nocreate'));
end
end
function res = size
% Returns the size of the current pool, zero if inactive
res = 0;
poolobj = gcp('nocreate');
if ~isempty(poolobj)
poolobj.NumWorkers;
end
end
function created = open(varargin)
% Opens a new pool using the specified arguments.
% No arguments use the default pool.
created = false;
if ~PCPool.isOpen
if PCPool.OldSyntax
matlabpool('open',varargin{:});%#ok
else
parpool(varargin{:});
end
created = true;
end
end
function close(force)
% Closes any currently open pool.
%
% If force argument only applies for
% the old matlabpool syntax.
if nargin < 1
force = false;
end
if PCPool.OldSyntax
if force
matlabpool close force;%#ok
elseif ~PCPool.isOpen
matlabpool close;%#ok
end
else
poolobj = gcp('nocreate');
if ~isempty(poolobj)
delete(poolobj);
end
end
end
end
end