File: RunOpenEMS_Parallel.m

package info (click to toggle)
openems 0.0.35+dfsg.1-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 6,288 kB
  • sloc: cpp: 40,259; yacc: 580; lex: 350; makefile: 258; sh: 169; ruby: 19
file content (92 lines) | stat: -rw-r--r-- 2,889 bytes parent folder | download | duplicates (2)
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
80
81
82
83
84
85
86
87
88
89
90
91
92
function [stdout, stderr] = RunOpenEMS_Parallel(Sim_Paths, Sim_Files, opts, Settings, varargin)
% function [stdout, stderr] = RunOpenEMS_Parallel(Sim_Paths, Sim_Files, opts, Settings, varargin)
% 
% Run multiple openEMS simulations in parallel, distributed on multiple 
% machines using a ssh host_list! (currently on Linux only)
% 
% This function relies on InitQueue etc.
% 
% input:
%       Sim_Paths:  cell array of pathes to simulate by RunOpenEMS
%       Sim_Files:  filename or cell array of filenames to simulate
%       opts:       openEMS options. sa RunOpenEMS
%       Settings:   use the settings to define multiple host for simulation
%                   e.g.: Settings.SSH.bin ='<path_to_openEMS>/openEMS.sh';
%                         Settings.SSH.host_list = {'list','of','hosts'};
% 
% Note: If no SSH host_list is defined, this function will skip the
%       parallel run and switch back to a default RunOpenEMS!
% 
% See also RunOpenEMS, FindFreeSSH, InitQueue
% 
% openEMS matlab interface
% -----------------------
% author: Thorsten Liebig 2011

pause_queue = 5; %pause between consecutive runs (needed for FindFreeSSH)

skip_parallel = 0;

% currently only supporting linux, run conventional RunOpenEMS
if ~isunix
    warning 'your OS is not supported (Unix only), running default RunOpenEMS';
    skip_parallel = 1;    
end

% in case only one path is given, run conventional RunOpenEMS
if ischar(Sim_Paths)
    warning 'only a single path given, running default RunOpenEMS'
    skip_parallel = 1;
end

% in case SSH.host_list is not defined, run conventional RunOpenEMS
if ~isfield(Settings,'SSH')
    warning 'SSH options missing, running default RunOpenEMS'
    skip_parallel = 1;
elseif ~isfield(Settings.SSH,'host_list')
    warning 'SSH.host_list option missing, running default RunOpenEMS'
    skip_parallel = 1;    
end

if (skip_parallel)
    for n=1:numel(Sim_Paths)
        if iscell(Sim_Files)
            Sim_File = Sim_Files{n};
        else
            Sim_File = Sim_Files;
        end
        RunOpenEMS(Sim_Paths{n}, Sim_Files, opts, Settings)
    end
    stdout = [];
    stderr = [];
    return
end
    
if ~iscell(Sim_Paths)
    error('RunOpenEMS_Parallel:needs a cell array of Sim_Paths to simulate');
end

% get the path to this file
[dir] = fileparts( mfilename('fullpath') );

queue = InitQueue('DependPath',{dir}, varargin{:});

% spawn multiple simulations
for n=1:numel(Sim_Paths)
    if iscell(Sim_Files)
        Sim_File = Sim_Files{n};
    else
        Sim_File = Sim_Files;
    end
    
    queue = Add2Queue(queue,'RunOpenEMS',{Sim_Paths{n}, Sim_File, opts, Settings});
    disp(['openEMS simulation #' int2str(n) ' in directory: ' Sim_Paths{n} ' started!']);
    pause(pause_queue);
end

[queue] = FinishQueue(queue);
   
for n=1:numel(Sim_Paths)
    stdout{n} = queue.jobs{n}.stdout;    
    stderr{n} = queue.jobs{n}.stderr;
end