matlab: allow running MPI openEMS on a HPC

Signed-off-by: Thorsten Liebig <Thorsten.Liebig@gmx.de>
This commit is contained in:
Thorsten Liebig 2013-05-15 16:03:48 +02:00
parent a607bc6969
commit 8698f7a448
2 changed files with 54 additions and 49 deletions

View File

@ -59,7 +59,7 @@ function RunOpenEMS(Sim_Path, Sim_File, opts, Settings)
% WriteOpenEMS('/tmp/path_to_run_in/myfile.xml', FDTD, CSX)
% RunOpenEMS('/tmp/path_to_run_in','myfile.xml','-v')
%
% See also WriteOpenEMS FindFreeSSH InitCSX InitFDTD
% See also WriteOpenEMS FindFreeSSH InitCSX InitFDTD RunOpenEMS_MPI
%
% openEMS matlab interface
% -----------------------

View File

@ -2,14 +2,14 @@ function RunOpenEMS_MPI(Sim_Path, Sim_File, opts, Settings)
% function RunOpenEMS_MPI(Sim_Path, Sim_File, NrProc, opts, Settings)
%
% Run an openEMS simulation with MPI support
%
%
% % mpi binary path on all nodes needed
% Settings.MPI.Binary = '/opt/openEMS/openEMS';
% % number of processes to run
% Settings.MPI.NrProc = 3;
% % define the mpi hosts :
% Settings.MPI.Hosts = {'host1','host2','host3'};
%
%
% RunOpenEMS(Sim_Path, Sim_File, NrProc, opts, Settings)
%
% See also SetupMPI, WriteOpenEMS, RunOpenEMS
@ -42,32 +42,34 @@ cd(Sim_Path);
scp_options = '-C -o "PasswordAuthentication no" -o "StrictHostKeyChecking no"';
ssh_options = [scp_options ' -x'];
Remote_Nodes = Settings.MPI.Hosts;
HostList = '';
for n=1:numel(Remote_Nodes)
remote_name = Remote_Nodes{n};
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!');
if isfield(Settings.MPI,'Hosts')
Remote_Nodes = Settings.MPI.Hosts;
HostList = '';
for n=1:numel(Remote_Nodes)
remote_name = Remote_Nodes{n};
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
HostList = remote_name;
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 ' !']);
end
HostList = [HostList ',' remote_name];
end
work_path = strtrim(result); %remove tailing \n
HostList = remote_name;
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 ' !']);
[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
HostList = [HostList ',' remote_name];
end
[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
@ -79,42 +81,45 @@ else
append_unix = [];
end
disp(['Running remote openEMS_MPI in working dir: ' work_path]);
if ~isfield(Settings.MPI,'GlobalArgs')
Settings.MPI.GlobalArgs = '';
end
if isfield(Settings.MPI,'Hosts')
disp(['Running remote openEMS_MPI in working dir: ' work_path]);
[status] = system(['mpiexec -host ' HostList ' -n ' int2str(NrProc) ' -wdir ' work_path ' ' Settings.MPI.Binary ' ' Sim_File ' ' opts ' ' append_unix]);
else
[status] = system(['mpiexec ' Settings.MPI.GlobalArgs ' -n ' int2str(NrProc) ' -wdir ' work_path ' ' Settings.MPI.Binary ' ' Sim_File ' ' opts ' ' append_unix]);
disp('Running local openEMS_MPI');
[status] = system(['mpiexec ' Settings.MPI.GlobalArgs ' -n ' int2str(NrProc) ' ' Settings.MPI.Binary ' ' Sim_File ' ' opts ' ' append_unix]);
end
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
if isfield(Settings.MPI,'Hosts')
disp( 'Remote simulation done... copying back results and cleaning up...' );
for n=1:numel(Remote_Nodes)
remote_name = Remote_Nodes{n};
disp(['Copy data from remote node: ' remote_name]);
[stat, res] = unix(['scp -r ' scp_options ' ' remote_name ':' work_path '/* ''' pwd '''/']);
if (stat~=0);
disp(res);
error('openEMS:RunOpenEMS','remote scp failed!');
if (strncmp(work_path,'/tmp/',5)~=1) % savety precaution...
error('openEMS:RunOpenEMS','working path invalid for deletion');
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!');
for n=1:numel(Remote_Nodes)
remote_name = Remote_Nodes{n};
disp(['Copy data from remote node: ' remote_name]);
[stat, res] = unix(['scp -r ' scp_options ' ' remote_name ':' work_path '/* ''' pwd '''/']);
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
end
cd(savePath);