matlab: RunOpenEMS can search a list for a free host using FindFreeSSH
This commit is contained in:
parent
d8599ca3a4
commit
b6d62858cc
55
matlab/FindFreeSSH.m
Normal file
55
matlab/FindFreeSSH.m
Normal file
@ -0,0 +1,55 @@
|
||||
function host = FindFreeSSH(host_list, wait_time, command)
|
||||
% function host = FindFreeSSH(host_list, wait_time, command)
|
||||
%
|
||||
% Find a free ssh host not running openEMS
|
||||
%
|
||||
% internal function used by RunOpenEMS
|
||||
%
|
||||
% host_list: give a list of possible host
|
||||
%
|
||||
% wait_time: wait x seconds after not finding a free host and rechecking
|
||||
% default: 60 seconds
|
||||
%
|
||||
% command: unix command to check for free host (empty result --> free)
|
||||
% default: 'ps -ewwo user,args | grep openEMS'
|
||||
%
|
||||
% See also RunOpenEMS
|
||||
%
|
||||
% openEMS matlab interface
|
||||
% -----------------------
|
||||
% author: Thorsten Liebig
|
||||
|
||||
if (nargin<3)
|
||||
% command which should return an empty string if host is available
|
||||
command = 'ps -e user,args | grep openEMS';
|
||||
end
|
||||
|
||||
if (nargin<2)
|
||||
wait_time = 60;
|
||||
end
|
||||
|
||||
while 1
|
||||
|
||||
for n = 1:numel(host_list)
|
||||
host = host_list{n};
|
||||
[status, result] = unix(['ssh ' host ' ' command]);
|
||||
|
||||
if isempty(result)
|
||||
disp(['FindFreeSSH:: found a free host: ' host ]);
|
||||
return
|
||||
else
|
||||
disp(['FindFreeSSH:: ' host ' is busy running openEMS ... ' ]);
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
host = '';
|
||||
|
||||
if (wait_time<=0)
|
||||
warning('openEMS:FindFreeSSH',' unable to find a free host ');
|
||||
return
|
||||
end
|
||||
|
||||
disp([' no free host found waiting for ' num2str(wait_time) ' seconds ... '])
|
||||
pause(wait_time)
|
||||
end
|
@ -12,6 +12,8 @@ function RunOpenEMS(Sim_Path, Sim_File, opts, Settings)
|
||||
% (ssh only on unix with working ssh client)
|
||||
% Settings.SSH.host = '<hostname or ip>'
|
||||
% Settings.SSH.bin = '<path_to_openEMS>/openEMS.sh'
|
||||
% ssh optional:
|
||||
% Settings.SSH.host_list = {'list','of','hosts'}; %searches for a free host
|
||||
%
|
||||
% optional MPI:
|
||||
% Settings.MPI.xxx --> help RunOpenEMS_MPI
|
||||
@ -21,7 +23,7 @@ function RunOpenEMS(Sim_Path, Sim_File, opts, Settings)
|
||||
%
|
||||
% RunOpenEMS(Sim_Path,Sim_File,opts,Settings)
|
||||
%
|
||||
% See also WriteOpenEMS
|
||||
% See also WriteOpenEMS FindFreeSSH
|
||||
%
|
||||
% openEMS matlab interface
|
||||
% -----------------------
|
||||
@ -51,6 +53,15 @@ if (isfield(Settings,'SSH') && isunix)
|
||||
scp_options = '-C -o "PasswordAuthentication no" -o "StrictHostKeyChecking no"';
|
||||
ssh_options = [scp_options ' -x'];
|
||||
|
||||
if isfield(Settings.SSH,'host_list')
|
||||
host = FindFreeSSH(Settings.SSH.host_list);
|
||||
if ~isempty(host)
|
||||
Settings.SSH.host = host;
|
||||
else
|
||||
error('openEMS:RunOpenEMS', 'unable to find host, abort openEMS');
|
||||
end
|
||||
end
|
||||
|
||||
% create a tmp working dir
|
||||
[status, result] = unix(['ssh ' ssh_options ' ' Settings.SSH.host ' "mktemp -d /tmp/openEMS_XXXXXXXXXXXX"']);
|
||||
if (status~=0)
|
||||
|
Loading…
Reference in New Issue
Block a user