-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparallelSetup.m
63 lines (61 loc) · 2.1 KB
/
parallelSetup.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
55
56
57
58
59
60
61
62
63
function [queueMax] = parallelSetup(n)
% Cases: n undefined - use existing pool
% n = existing pool size - use exising pool
% n = 0 - leave existing pool alone (if any). Don't use it.
% n != existing pool size - delete any old pool and create one
if nargin == 0
% User wants to use whatever exists.
pool = gcp('nocreate'); % Maximum number of threads for PDF creation.
if isempty(pool)
threads = 0;
multiThread = false;
else
threads = pool.NumWorkers;
multiThread = true;
end
fprintf('Using existing pool size with %d threads.\n', threads);
poolReady = true;
elseif n <= 1
% User wants no parallel threads.
threads = 0;
multiThread = false;
poolReady = true;
else
% User specified a number of threads. This will fail if more are
% asked for than the value in Parallel Preferences.
pool = gcp('nocreate');
if isempty(pool)
threads = n;
multiThread = true;
poolReady = false;
elseif n == pool.NumWorkers
threads = n;
multiThread = true;
poolReady = true;
else
threads = n;
multiThread = true;
poolReady = false;
delete(gcp('nocreate'));
end
end
% Start a pool if needed, and notify in most cases.
if multiThread && ~poolReady
pool = parpool(threads);
fprintf('Running with up to %d threads.\n', pool.NumWorkers);
elseif nargin == 0 && ~multiThread
fprintf('Multithreaded computation is off.');
end
queueMax = threads;
if multiThread
% I'm not sure whether this line does anything. Check some time.
queue = parallel.FevalFuture.empty;
% Call plot function with no arguments. If the workers have been used
% before this clears their variables. If not it gets the plot routine
% loaded onto them.
spmd
Plot_One_Reef();
graphCompare();
end
end
end