-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathspawnmulticoreslaveinstances.m
More file actions
52 lines (47 loc) · 1.48 KB
/
spawnmulticoreslaveinstances.m
File metadata and controls
52 lines (47 loc) · 1.48 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
function multicoreDir = spawnmulticoreslaveinstances(n, multicoreDir, settings)
%STARTMULTICORESLAVEINSTANCES Start multi-core processing slave processes in new MATLAB instances.
%
% Igor Gotlibovych
% Last modified 20.07.2014
%
% See also STARTMULTICORESLAVE.
import multicore.*
if ~exist('n', 'var') || isempty(n)
%n = str2num(getenv('NUMBER_OF_PROCESSORS')) - 1;
n = feature('numCores') - 1;
end
% get slave file directory name
if ~exist('multicoreDir', 'var') || isempty(multicoreDir)
multicoreDir = fullfile(tempdir2, 'multicorefiles');
end
if ~exist(multicoreDir, 'dir')
try
mkdir(multicoreDir);
catch
error('Unable to create slave file directory %s.', multicoreDir);
end
end
if ~exist('settings', 'var')
% use default settings
settings = [];
end
% get path to multicore on this machine
wat = what('multicore');
packagepath = wat.path;
timestamp = num2str(randi(9999)); %FIXME
settingsfile = fullfile(multicoreDir, ['settings' timestamp '.mat']);
save(settingsfile, 'settings', 'multicoreDir', 'packagepath');
for i = 1:n
command = [
'matlab -nosplash -nodesktop -minimize -noFigureWindows -r "' ...
'disp(''Starting Slave ' num2str(i) ''');'...
'load(''' settingsfile ''');'...
'cd(fullfile(packagepath, ''..''));'...
'multicore.startmulticoreslave;'...
'quit()'...
'" &'
];
[status, cmdout] = system(command);
fprintf('Slave %d/%d returned status %d: %s\n', i, n, status, cmdout);
end
end