2011-02-24 13:44:29 +00:00
|
|
|
function RunOpenEMS_MPI(Sim_Path, Sim_File, opts, Settings)
|
|
|
|
% function RunOpenEMS_MPI(Sim_Path, Sim_File, NrProc, opts, Settings)
|
2011-02-16 06:56:40 +00:00
|
|
|
%
|
|
|
|
% Run an openEMS simulation with MPI support
|
|
|
|
%
|
|
|
|
% % mpi binary path on all nodes needed
|
2011-10-27 11:35:02 +00:00
|
|
|
% Settings.MPI.Binary = '/opt/openEMS/openEMS';
|
2011-02-24 13:44:29 +00:00
|
|
|
% % number of processes to run
|
2011-10-27 11:35:02 +00:00
|
|
|
% Settings.MPI.NrProc = 3;
|
|
|
|
% % define the mpi hosts :
|
|
|
|
% Settings.MPI.Hosts = {'host1','host2','host3'};
|
2011-02-23 10:08:40 +00:00
|
|
|
%
|
2011-10-27 11:35:02 +00:00
|
|
|
% RunOpenEMS(Sim_Path, Sim_File, NrProc, opts, Settings)
|
2011-02-16 06:56:40 +00:00
|
|
|
%
|
2011-10-27 11:35:02 +00:00
|
|
|
% See also SetupMPI, WriteOpenEMS, RunOpenEMS
|
2011-02-16 06:56:40 +00:00
|
|
|
%
|
|
|
|
% openEMS matlab interface
|
|
|
|
% -----------------------
|
|
|
|
% author: Thorsten Liebig
|
|
|
|
|
|
|
|
if (isunix ~= 1)
|
|
|
|
error 'MPI version of openEMS currently only available using Linux'
|
|
|
|
end
|
|
|
|
|
2011-02-24 13:44:29 +00:00
|
|
|
if nargin < 4
|
|
|
|
error 'missing arguments: specify the Sim_Path, Sim_file, opts and Settings...'
|
2011-02-16 06:56:40 +00:00
|
|
|
end
|
|
|
|
|
2011-02-24 13:44:29 +00:00
|
|
|
NrProc = Settings.MPI.NrProc;
|
|
|
|
|
2011-02-16 06:56:40 +00:00
|
|
|
if (NrProc<2)
|
2011-02-24 13:44:29 +00:00
|
|
|
error('openEMS:RunOpenEMS_MPI','MPI number of processes to small...');
|
2011-02-16 06:56:40 +00:00
|
|
|
end
|
|
|
|
|
2011-02-23 10:08:40 +00:00
|
|
|
if ~isfield(Settings,'MPI')
|
2011-02-24 13:44:29 +00:00
|
|
|
error('openEMS:RunOpenEMS_MPI','MPI settings not found...');
|
2011-02-16 06:56:40 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
savePath = pwd;
|
|
|
|
cd(Sim_Path);
|
|
|
|
|
|
|
|
scp_options = '-C -o "PasswordAuthentication no" -o "StrictHostKeyChecking no"';
|
|
|
|
ssh_options = [scp_options ' -x'];
|
|
|
|
|
2011-05-04 15:08:39 +00:00
|
|
|
Remote_Nodes = Settings.MPI.Hosts;
|
|
|
|
HostList = '';
|
2011-02-16 06:56:40 +00:00
|
|
|
for n=1:numel(Remote_Nodes)
|
|
|
|
remote_name = Remote_Nodes{n};
|
|
|
|
|
2011-02-24 13:44:29 +00:00
|
|
|
if (n==1)
|
|
|
|
[status, result] = unix(['ssh ' ssh_options ' ' remote_name ' "mktemp -d /tmp/openEMS_MPI_XXXXXXXXXXXX"']);
|
|
|
|
if (status~=0)
|
|
|
|
disp(result);
|
|
|
|
error('openEMS:RunOpenEMS','mktemp failed to create tmp directory!');
|
|
|
|
end
|
|
|
|
work_path = strtrim(result); %remove tailing \n
|
2011-05-04 15:08:39 +00:00
|
|
|
HostList = remote_name;
|
2011-02-24 13:44:29 +00:00
|
|
|
else
|
|
|
|
[status, result] = unix(['ssh ' ssh_options ' ' remote_name ' "mkdir ' work_path '"']);
|
|
|
|
if (status~=0)
|
|
|
|
disp(result);
|
|
|
|
error('openEMS:RunOpenEMS',['mkdir failed to create tmp directory on remote ' remote_name ' !']);
|
2011-02-16 06:56:40 +00:00
|
|
|
end
|
2011-05-04 15:08:39 +00:00
|
|
|
HostList = [HostList ',' remote_name];
|
2011-02-16 06:56:40 +00:00
|
|
|
end
|
2011-02-24 13:44:29 +00:00
|
|
|
|
2011-02-16 06:56:40 +00:00
|
|
|
[stat, res] = unix(['scp ' scp_options ' * ' remote_name ':' work_path '/']);
|
|
|
|
if (stat~=0)
|
|
|
|
disp(res);
|
|
|
|
error('openEMS:RunOpenEMS',['scp to remote ' remote_name ' failed!']);
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
%run openEMS (with log file if requested)
|
|
|
|
if isfield(Settings,'LogFile')
|
|
|
|
append_unix = [' 2>&1 | tee ' Settings.LogFile];
|
|
|
|
else
|
|
|
|
append_unix = [];
|
|
|
|
end
|
|
|
|
|
2011-02-24 13:44:29 +00:00
|
|
|
disp(['Running remote openEMS_MPI in working dir: ' work_path]);
|
|
|
|
|
2011-03-08 11:06:47 +00:00
|
|
|
if ~isfield(Settings.MPI,'GlobalArgs')
|
|
|
|
Settings.MPI.GlobalArgs = '';
|
|
|
|
end
|
|
|
|
|
2011-05-04 15:08:39 +00:00
|
|
|
if isfield(Settings.MPI,'Hosts')
|
|
|
|
[status] = system(['mpiexec -host ' HostList ' -n ' int2str(NrProc) ' -wdir ' work_path ' ' Settings.MPI.Binary ' ' Sim_File ' ' opts ' ' append_unix]);
|
2011-02-24 13:44:29 +00:00
|
|
|
else
|
2011-05-04 15:08:39 +00:00
|
|
|
[status] = system(['mpiexec ' Settings.MPI.GlobalArgs ' -n ' int2str(NrProc) ' -wdir ' work_path ' ' Settings.MPI.Binary ' ' Sim_File ' ' opts ' ' append_unix]);
|
2011-02-24 13:44:29 +00:00
|
|
|
end
|
2011-02-16 06:56:40 +00:00
|
|
|
if (status~=0)
|
|
|
|
error('openEMS:RunOpenEMS','mpirun openEMS failed!');
|
|
|
|
end
|
|
|
|
|
|
|
|
disp( 'Remote simulation done... copying back results and cleaning up...' );
|
|
|
|
|
|
|
|
if (strncmp(work_path,'/tmp/',5)~=1) % savety precaution...
|
|
|
|
error('openEMS:RunOpenEMS','working path invalid for deletion');
|
|
|
|
end
|
|
|
|
|
|
|
|
for n=1:numel(Remote_Nodes)
|
|
|
|
remote_name = Remote_Nodes{n};
|
2011-02-23 10:08:40 +00:00
|
|
|
disp(['Copy data from remote node: ' remote_name]);
|
2011-05-24 09:49:55 +00:00
|
|
|
[stat, res] = unix(['scp -r ' scp_options ' ' remote_name ':' work_path '/* ''' pwd '''/']);
|
2011-02-16 06:56:40 +00:00
|
|
|
if (stat~=0);
|
|
|
|
disp(res);
|
|
|
|
error('openEMS:RunOpenEMS','remote scp failed!');
|
|
|
|
end
|
|
|
|
|
|
|
|
%cleanup
|
|
|
|
[stat, res] = unix(['ssh ' ssh_options ' ' remote_name ' rm -r ' work_path]);
|
|
|
|
if (stat~=0);
|
|
|
|
disp(res);
|
|
|
|
warning('openEMS:RunOpenEMS','remote cleanup failed!');
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
cd(savePath);
|