Merged with masterParallelMan (which will be eliminated).
Improved header/commenting;time-shift
parent
77ee04ef37
commit
0450edda3b
|
@ -1,31 +1,54 @@
|
||||||
function [fOutVar,nBlockPerCPU, totCPU] = masterParallel(Parallel,fBlock,nBlock,NamFileInput,fname,fInputVar,fGlobalVar,Parallel_info)
|
function [fOutVar,nBlockPerCPU, totCPU] = masterParallel(Parallel,fBlock,nBlock,NamFileInput,fname,fInputVar,fGlobalVar,Parallel_info)
|
||||||
% Top-level function called on the master computer when parallelizing a task.
|
% PARALLEL CONTEXT
|
||||||
%
|
% This is the most important function for the management of DYNARE parallel
|
||||||
|
% computing.
|
||||||
|
% It is the top-level function called on the master computer when parallelizing a task.
|
||||||
|
|
||||||
|
|
||||||
|
% This function have two main computational startegy for manage the matlab worker (slave process).
|
||||||
|
% 0 Simple Close/Open Stategy:
|
||||||
|
% In this case the new matlab istances (slave process) are open when
|
||||||
|
% necessary and then closed. This can happen many times during the
|
||||||
|
% simulation of a model.
|
||||||
|
|
||||||
|
% 1 Alway Open Stategy:
|
||||||
|
% In this case we have a more sophisticated management of slave processes,
|
||||||
|
% which are no longer closed at the end of each job. The slave processes
|
||||||
|
% waits for a new job (if exist). If a slave do not receives a new job after a
|
||||||
|
% fixed time it is destroyed. This solution removes the computational
|
||||||
|
% time necessary to Open/Close new matlab istances.
|
||||||
|
|
||||||
|
% The first (point 0) is the default Strategy
|
||||||
|
% i.e.(Parallel_info.leaveSlaveOpen=0). This value can be changed by the
|
||||||
|
% user in xxx.mod file or it is changed by the programmer if it necessary to
|
||||||
|
% reduce the overall computational time. See for example the
|
||||||
|
% prior_posterior_statistics.m.
|
||||||
|
|
||||||
% The number of parallelized threads will be equal to (nBlock-fBlock+1).
|
% The number of parallelized threads will be equal to (nBlock-fBlock+1).
|
||||||
%
|
%
|
||||||
% INPUTS
|
% INPUTS
|
||||||
% Parallel [struct vector] copy of options_.parallel
|
% o Parallel [struct vector] copy of options_.parallel
|
||||||
% fBlock [int] index number of the first thread
|
% o fBlock [int] index number of the first thread
|
||||||
% (between 1 and nBlock)
|
% (between 1 and nBlock)
|
||||||
% nBlock [int] index number of the last thread
|
% o nBlock [int] index number of the last thread
|
||||||
% NamFileInput [cell array] containins the list of input files to be
|
% o NamFileInput [cell array] containins the list of input files to be
|
||||||
% copied in the working directory of remote slaves
|
% copied in the working directory of remote slaves
|
||||||
% 2 columns, as many lines as there are files
|
% 2 columns, as many lines as there are files
|
||||||
% - first column contains directory paths
|
% - first column contains directory paths
|
||||||
% - second column contains filenames
|
% - second column contains filenames
|
||||||
% fname [string] name of the function to be parallelized, and
|
% o fname [string] name of the function to be parallelized, and
|
||||||
% which will be run on the slaves
|
% which will be run on the slaves
|
||||||
% fInputVar [struct] structure containing local variables to be used
|
% o fInputVar [struct] structure containing local variables to be used
|
||||||
% by fName on the slaves
|
% by fName on the slaves
|
||||||
% fGlobalVar [struct] structure containing global variables to be used
|
% o fGlobalVar [struct] structure containing global variables to be used
|
||||||
% by fName on the slaves
|
% by fName on the slaves
|
||||||
%
|
%
|
||||||
% OUTPUT
|
% OUTPUT
|
||||||
% fOutVar [struct vector] result of the parallel computation, one
|
% o fOutVar [struct vector] result of the parallel computation, one
|
||||||
% struct per thread
|
% struct per thread
|
||||||
% nBlockPerCPU [int vector] for each CPU used, indicates the number of
|
% o nBlockPerCPU [int vector] for each CPU used, indicates the number of
|
||||||
% threads run on that CPU
|
% threads run on that CPU
|
||||||
% totCPU [int] total number of CPU used (can be lower than
|
% o totCPU [int] total number of CPU used (can be lower than
|
||||||
% the number of CPU declared in "Parallel", if
|
% the number of CPU declared in "Parallel", if
|
||||||
% the number of required threads is lower)
|
% the number of required threads is lower)
|
||||||
|
|
||||||
|
@ -46,13 +69,33 @@ function [fOutVar,nBlockPerCPU, totCPU] = masterParallel(Parallel,fBlock,nBlock,
|
||||||
% You should have received a copy of the GNU General Public License
|
% You should have received a copy of the GNU General Public License
|
||||||
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
|
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
% Determine my hostname and my working directory
|
|
||||||
|
% Fix the strategy to be used.
|
||||||
|
Strategy=-1;
|
||||||
|
|
||||||
if ~isempty(Parallel_info)
|
if ~isempty(Parallel_info)
|
||||||
if Parallel_info.leaveSlaveOpen,
|
Strategy=Parallel_info.leaveSlaveOpen;
|
||||||
[fOutVar,nBlockPerCPU, totCPU] = masterParallelMan(Parallel,fBlock,nBlock,NamFileInput,fname,fInputVar,fGlobalVar);
|
end
|
||||||
return
|
|
||||||
end
|
if Strategy==0
|
||||||
|
display('User Strategy Now Is Open/Close (0)');
|
||||||
|
else
|
||||||
|
display('User Strategy Now Is Always Open (1)');
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if Strategy==1
|
||||||
|
% Delete the traces (if exists) of last section computations.
|
||||||
|
persistent initialize
|
||||||
|
if isempty(initialize),
|
||||||
|
mydelete(['P_slave_*End.txt']);
|
||||||
|
mydelete(['slaveParallel_input*.mat']);
|
||||||
|
initialize = 0;
|
||||||
|
pause(1),
|
||||||
|
end
|
||||||
|
totCPU=0;
|
||||||
|
end
|
||||||
|
|
||||||
|
% Determine my hostname and my working directory.
|
||||||
DyMo=pwd;
|
DyMo=pwd;
|
||||||
fInputVar.DyMo=DyMo;
|
fInputVar.DyMo=DyMo;
|
||||||
if isunix || (~matlab_ver_less_than('7.4') && ismac) ,
|
if isunix || (~matlab_ver_less_than('7.4') && ismac) ,
|
||||||
|
@ -64,35 +107,34 @@ end
|
||||||
MasterName=deblank(MasterName);
|
MasterName=deblank(MasterName);
|
||||||
fInputVar.MasterName = MasterName;
|
fInputVar.MasterName = MasterName;
|
||||||
|
|
||||||
% Save input data for use by the slaves
|
% Save input data for use by the slaves.
|
||||||
if exist('fGlobalVar'),
|
switch Strategy
|
||||||
save([fname,'_input.mat'],'fInputVar','fGlobalVar')
|
case 0
|
||||||
else
|
if exist('fGlobalVar'),
|
||||||
save([fname,'_input.mat'],'fInputVar')
|
save([fname,'_input.mat'],'fInputVar','fGlobalVar')
|
||||||
|
else
|
||||||
|
save([fname,'_input.mat'],'fInputVar')
|
||||||
|
end
|
||||||
|
save([fname,'_input.mat'],'Parallel','-append')
|
||||||
|
|
||||||
|
case 1
|
||||||
|
if exist('fGlobalVar'),
|
||||||
|
save(['temp_input.mat'],'fInputVar','fGlobalVar')
|
||||||
|
else
|
||||||
|
save(['temp_input.mat'],'fInputVar')
|
||||||
|
end
|
||||||
|
save(['temp_input.mat'],'Parallel','-append')
|
||||||
end
|
end
|
||||||
save([fname,'_input.mat'],'Parallel','-append')
|
|
||||||
|
|
||||||
% Determine the total number of available CPUs, and the number of threads to run on each CPU
|
|
||||||
[nCPU, totCPU, nBlockPerCPU] = distributeJobs(Parallel, fBlock, nBlock);
|
|
||||||
offset0 = fBlock-1;
|
|
||||||
|
|
||||||
% for j=1:length(Parallel),
|
% Determine the total number of available CPUs, and the number of threads
|
||||||
% nCPU(j)=length(Parallel(j).NumCPU);
|
% to run on each CPU.
|
||||||
% totCPU=totCPU+nCPU(j);
|
|
||||||
% end
|
|
||||||
%
|
|
||||||
% nCPU=cumsum(nCPU);
|
|
||||||
% offset0 = fBlock-1;
|
|
||||||
% if (nBlock-offset0)>totCPU,
|
|
||||||
% diff = mod((nBlock-offset0),totCPU);
|
|
||||||
% nBlockPerCPU(1:diff) = ceil((nBlock-offset0)/totCPU);
|
|
||||||
% nBlockPerCPU(diff+1:totCPU) = floor((nBlock-offset0)/totCPU);
|
|
||||||
% else
|
|
||||||
% nBlockPerCPU(1:nBlock-offset0)=1;
|
|
||||||
% totCPU = nBlock-offset0;
|
|
||||||
% end
|
|
||||||
|
|
||||||
% Clean up remnants of previous runs
|
[nCPU, totCPU, nBlockPerCPU] = distributeJobs(Parallel, fBlock, nBlock);
|
||||||
|
offset0 = fBlock-1;
|
||||||
|
|
||||||
|
|
||||||
|
% Clean up remnants of previous runs.
|
||||||
mydelete(['comp_status_',fname,'*.mat'])
|
mydelete(['comp_status_',fname,'*.mat'])
|
||||||
mydelete(['P_',fname,'*End.txt']);
|
mydelete(['P_',fname,'*End.txt']);
|
||||||
|
|
||||||
|
@ -100,6 +142,12 @@ mydelete(['P_',fname,'*End.txt']);
|
||||||
fid = fopen('ConcurrentCommand1.bat','w+');
|
fid = fopen('ConcurrentCommand1.bat','w+');
|
||||||
for j=1:totCPU,
|
for j=1:totCPU,
|
||||||
|
|
||||||
|
|
||||||
|
if Strategy==1
|
||||||
|
command1 = ' ';
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
indPC=min(find(nCPU>=j));
|
indPC=min(find(nCPU>=j));
|
||||||
|
|
||||||
if indPC>1
|
if indPC>1
|
||||||
|
@ -112,54 +160,88 @@ for j=1:totCPU,
|
||||||
fid1=fopen(['P_',fname,'_',int2str(j),'End.txt'],'w+');
|
fid1=fopen(['P_',fname,'_',int2str(j),'End.txt'],'w+');
|
||||||
fclose(fid1);
|
fclose(fid1);
|
||||||
|
|
||||||
if Parallel(indPC).Local == 1, % run on the local machine
|
if Strategy==1
|
||||||
if isunix || (~matlab_ver_less_than('7.4') && ismac),
|
fblck = offset+1;
|
||||||
if exist('OCTAVE_VERSION')
|
nblck = sum(nBlockPerCPU(1:j));
|
||||||
command1=['octave --eval fParallel\(',int2str(offset+1),',',int2str(sum(nBlockPerCPU(1:j))),',',int2str(j),',',int2str(indPC),',\''',fname,'\''\) &'];
|
save temp_input fblck nblck fname -append;
|
||||||
|
copyfile('temp_input.mat',['slaveJob',int2str(j),'.mat'])
|
||||||
|
if Parallel(indPC).Local ==0,
|
||||||
|
fid1=fopen(['stayalive',int2str(j),'.txt'],'w+');
|
||||||
|
fclose(fid1);
|
||||||
|
if isunix || (~matlab_ver_less_than('7.4') && ismac),
|
||||||
|
system(['scp stayalive',int2str(j),'.txt ',Parallel(indPC).user,'@',Parallel(indPC).PcName,':',Parallel(indPC).RemoteFolder]);
|
||||||
else
|
else
|
||||||
command1=['matlab -nosplash -nodesktop -minimize -r fParallel\(',int2str(offset+1),',',int2str(sum(nBlockPerCPU(1:j))),',',int2str(j),',',int2str(indPC),',\''',fname,'\''\) &'];
|
copyfile(['stayalive',int2str(j),'.txt'], ['\\',Parallel(indPC).PcName,'\',Parallel(indPC).RemoteDrive,'$\',Parallel(indPC).RemoteFolder]);
|
||||||
end
|
end
|
||||||
else
|
mydelete(['stayalive',int2str(j),'.txt'],'w+');
|
||||||
if exist('OCTAVE_VERSION')
|
end
|
||||||
command1=['start /B psexec -W ',DyMo, ' -a ',int2str(Parallel(indPC).NumCPU(j-nCPU0)),' -low octave --eval fParallel(',int2str(offset+1),',',int2str(sum(nBlockPerCPU(1:j))),',',int2str(j),',',int2str(indPC),',''',fname,''')'];
|
% Wait for possibly local alive CPU to start the new job or close by
|
||||||
else
|
% internal criteria.
|
||||||
command1=['start /B psexec -W ',DyMo, ' -a ',int2str(Parallel(indPC).NumCPU(j-nCPU0)),' -low matlab -nosplash -nodesktop -minimize -r fParallel(',int2str(offset+1),',',int2str(sum(nBlockPerCPU(1:j))),',',int2str(j),',',int2str(indPC),',''',fname,''')'];
|
pause(1);
|
||||||
end
|
newInstance = 0;
|
||||||
end
|
|
||||||
else
|
|
||||||
if isunix || (~matlab_ver_less_than('7.4') && ismac),
|
|
||||||
% [tempo, RemoteName]=system(['ssh ',Parallel(indPC).user,'@',Parallel(indPC).PcName,' "ifconfig | grep \''inet addr:\''| grep -v \''127.0.0.1\'' | cut -d: -f2 | awk \''{ print $1}\''"']);
|
|
||||||
[tempo, RemoteName]=system(['ssh ',Parallel(indPC).user,'@',Parallel(indPC).PcName,' "hostname --fqdn"']);
|
|
||||||
RemoteName=RemoteName(1:end-1);
|
|
||||||
RemoteFolder = Parallel(indPC).RemoteFolder;
|
|
||||||
else
|
|
||||||
RemoteName = Parallel(indPC).PcName;
|
|
||||||
RemoteFolder = [Parallel(indPC).RemoteDrive,':\',Parallel(indPC).RemoteFolder];
|
|
||||||
end
|
|
||||||
|
|
||||||
remoteFlag=1;
|
% Check if j CPU is already alive.
|
||||||
|
if isempty( dir(['P_slave_',int2str(j),'End.txt']));
|
||||||
if strcmpi(RemoteName,MasterName),
|
fid1=fopen(['P_slave_',int2str(j),'End.txt'],'w+');
|
||||||
if ~copyfile(['P_',fname,'_',int2str(j),'End.txt'],RemoteFolder),
|
fclose(fid1);
|
||||||
remoteFlag=0;
|
newInstance = 1;
|
||||||
end
|
storeGlobalVars( ['slaveParallel_input',int2str(j)]);
|
||||||
|
save( ['slaveParallel_input',int2str(j)],'Parallel','-append');
|
||||||
|
% Prepare global vars for Slave.
|
||||||
end
|
end
|
||||||
if remoteFlag,
|
end
|
||||||
if j==nCPU0+1,
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||||
if isunix || (~matlab_ver_less_than('7.4') && ismac),
|
% The following 'switch - case' code is the core of this function!
|
||||||
system(['ssh ',Parallel(indPC).user,'@',Parallel(indPC).PcName,' rm -fr ',Parallel(indPC).RemoteFolder,'/*']);
|
switch Strategy
|
||||||
|
case 0
|
||||||
|
|
||||||
|
if Parallel(indPC).Local == 1, %Run on the local machine (localhost).
|
||||||
|
if isunix || (~matlab_ver_less_than('7.4') && ismac),
|
||||||
|
if exist('OCTAVE_VERSION')
|
||||||
|
command1=['octave --eval fParallel\(',int2str(offset+1),',',int2str(sum(nBlockPerCPU(1:j))),',',int2str(j),',',int2str(indPC),',\''',fname,'\''\) &'];
|
||||||
else
|
else
|
||||||
mydelete('*.*',['\\',Parallel(indPC).PcName,'\',Parallel(indPC).RemoteDrive,'$\',Parallel(indPC).RemoteFolder,'\']);
|
command1=['matlab -nosplash -nodesktop -minimize -r fParallel\(',int2str(offset+1),',',int2str(sum(nBlockPerCPU(1:j))),',',int2str(j),',',int2str(indPC),',\''',fname,'\''\) &'];
|
||||||
adir=dir(['\\',Parallel(indPC).PcName,'\',Parallel(indPC).RemoteDrive,'$\',Parallel(indPC).RemoteFolder,'\']);
|
end
|
||||||
for jdir=3:length(adir)
|
else
|
||||||
STATUS = rmdir(['\\',Parallel(indPC).PcName,'\',Parallel(indPC).RemoteDrive,'$\',Parallel(indPC).RemoteFolder,'\',adir(jdir).name],'s');
|
if exist('OCTAVE_VERSION')
|
||||||
if STATUS == 0,
|
command1=['start /B psexec -W ',DyMo, ' -a ',int2str(Parallel(indPC).NumCPU(j-nCPU0)),' -low octave --eval fParallel(',int2str(offset+1),',',int2str(sum(nBlockPerCPU(1:j))),',',int2str(j),',',int2str(indPC),',''',fname,''')'];
|
||||||
disp(['Warning!: Directory ',adir(jdir).name,' could not be removed from ',Parallel(indPC).PcName,'.'])
|
else
|
||||||
|
command1=['start /B psexec -W ',DyMo, ' -a ',int2str(Parallel(indPC).NumCPU(j-nCPU0)),' -low matlab -nosplash -nodesktop -minimize -r fParallel(',int2str(offset+1),',',int2str(sum(nBlockPerCPU(1:j))),',',int2str(j),',',int2str(indPC),',''',fname,''')'];
|
||||||
|
end
|
||||||
|
end
|
||||||
|
else % Parallel(indPC).Local==0: Run using network on remote machine or also on local machine.
|
||||||
|
if isunix || (~matlab_ver_less_than('7.4') && ismac),
|
||||||
|
%[tempo, RemoteName]=system(['ssh ',Parallel(indPC).user,'@',Parallel(indPC).PcName,' "ifconfig | grep \''inet addr:\''| grep -v \''127.0.0.1\'' | cut -d: -f2 | awk \''{ print $1}\''"']);
|
||||||
|
[tempo, RemoteName]=system(['ssh ',Parallel(indPC).user,'@',Parallel(indPC).PcName,' "hostname --fqdn"']);
|
||||||
|
RemoteName=RemoteName(1:end-1);
|
||||||
|
RemoteFolder = Parallel(indPC).RemoteFolder;
|
||||||
|
else
|
||||||
|
RemoteName = Parallel(indPC).PcName;
|
||||||
|
RemoteFolder = [Parallel(indPC).RemoteDrive,':\',Parallel(indPC).RemoteFolder];
|
||||||
|
end
|
||||||
|
|
||||||
|
remoteFlag=1;
|
||||||
|
|
||||||
|
if strcmpi(RemoteName,MasterName),
|
||||||
|
if ~copyfile(['P_',fname,'_',int2str(j),'End.txt'],RemoteFolder),
|
||||||
|
remoteFlag=0;
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if remoteFlag,
|
||||||
|
if j==nCPU0+1,
|
||||||
|
if isunix || (~matlab_ver_less_than('7.4') && ismac),
|
||||||
|
system(['ssh ',Parallel(indPC).user,'@',Parallel(indPC).PcName,' rm -fr ',Parallel(indPC).RemoteFolder,'/*']);
|
||||||
|
else
|
||||||
|
mydelete('*.*',['\\',Parallel(indPC).PcName,'\',Parallel(indPC).RemoteDrive,'$\',Parallel(indPC).RemoteFolder,'\']);
|
||||||
|
adir=dir(['\\',Parallel(indPC).PcName,'\',Parallel(indPC).RemoteDrive,'$\',Parallel(indPC).RemoteFolder,'\']);
|
||||||
|
for jdir=3:length(adir)
|
||||||
|
STATUS = rmdir(['\\',Parallel(indPC).PcName,'\',Parallel(indPC).RemoteDrive,'$\',Parallel(indPC).RemoteFolder,'\',adir(jdir).name],'s');
|
||||||
|
if STATUS == 0,
|
||||||
|
disp(['Warning!: Directory ',adir(jdir).name,' could not be removed from ',Parallel(indPC).PcName,'.'])
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
if isunix || (~matlab_ver_less_than('7.4') && ismac),
|
||||||
|
|
||||||
if isunix || (~matlab_ver_less_than('7.4') && ismac),
|
|
||||||
system(['scp ',fname,'_input.mat ',Parallel(indPC).user,'@',Parallel(indPC).PcName,':',Parallel(indPC).RemoteFolder]);
|
system(['scp ',fname,'_input.mat ',Parallel(indPC).user,'@',Parallel(indPC).PcName,':',Parallel(indPC).RemoteFolder]);
|
||||||
for jfil=1:size(NamFileInput,1)
|
for jfil=1:size(NamFileInput,1)
|
||||||
if ~isempty(NamFileInput{jfil,1})
|
if ~isempty(NamFileInput{jfil,1})
|
||||||
|
@ -167,15 +249,15 @@ for j=1:totCPU,
|
||||||
end
|
end
|
||||||
system(['scp ',NamFileInput{jfil,1},NamFileInput{jfil,2},' ',Parallel(indPC).user,'@',Parallel(indPC).PcName,':',Parallel(indPC).RemoteFolder,'/',NamFileInput{jfil,1}]);
|
system(['scp ',NamFileInput{jfil,1},NamFileInput{jfil,2},' ',Parallel(indPC).user,'@',Parallel(indPC).PcName,':',Parallel(indPC).RemoteFolder,'/',NamFileInput{jfil,1}]);
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
copyfile([fname,'_input.mat'], ['\\',Parallel(indPC).PcName,'\',Parallel(indPC).RemoteDrive,'$\',Parallel(indPC).RemoteFolder]);
|
copyfile([fname,'_input.mat'], ['\\',Parallel(indPC).PcName,'\',Parallel(indPC).RemoteDrive,'$\',Parallel(indPC).RemoteFolder]);
|
||||||
for jfil=1:size(NamFileInput,1),
|
for jfil=1:size(NamFileInput,1),
|
||||||
if ~isempty(NamFileInput{jfil,1})
|
if ~isempty(NamFileInput{jfil,1})
|
||||||
mkdir(['\\',Parallel(indPC).PcName,'\',Parallel(indPC).RemoteDrive,'$\',Parallel(indPC).RemoteFolder,'\',NamFileInput{jfil,1}]);
|
mkdir(['\\',Parallel(indPC).PcName,'\',Parallel(indPC).RemoteDrive,'$\',Parallel(indPC).RemoteFolder,'\',NamFileInput{jfil,1}]);
|
||||||
end
|
end
|
||||||
copyfile([NamFileInput{jfil,1},NamFileInput{jfil,2}],['\\',Parallel(indPC).PcName,'\',Parallel(indPC).RemoteDrive,'$\',Parallel(indPC).RemoteFolder,'\',NamFileInput{jfil,1}])
|
copyfile([NamFileInput{jfil,1},NamFileInput{jfil,2}],['\\',Parallel(indPC).PcName,'\',Parallel(indPC).RemoteDrive,'$\',Parallel(indPC).RemoteFolder,'\',NamFileInput{jfil,1}])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -186,7 +268,7 @@ for j=1:totCPU,
|
||||||
command1=['ssh ',Parallel(indPC).user,'@',Parallel(indPC).PcName,' "cd ',Parallel(indPC).RemoteFolder, '; matlab -nosplash -nodesktop -minimize -r fParallel\(',int2str(offset+1),',',int2str(sum(nBlockPerCPU(1:j))),',',int2str(j),',',int2str(indPC),',\''',fname,'\''\);" &'];
|
command1=['ssh ',Parallel(indPC).user,'@',Parallel(indPC).PcName,' "cd ',Parallel(indPC).RemoteFolder, '; matlab -nosplash -nodesktop -minimize -r fParallel\(',int2str(offset+1),',',int2str(sum(nBlockPerCPU(1:j))),',',int2str(j),',',int2str(indPC),',\''',fname,'\''\);" &'];
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
if ~strcmp(Parallel(indPC).PcName,MasterName), % run on a remote machine
|
if ~strcmp(Parallel(indPC).PcName,MasterName), % Run on a remote machine!
|
||||||
if exist('OCTAVE_VERSION'),
|
if exist('OCTAVE_VERSION'),
|
||||||
command1=['start /B psexec \\',Parallel(indPC).PcName,' -e -u ',Parallel(indPC).user,' -p ',Parallel(indPC).passwd,' -W ',Parallel(indPC).RemoteDrive,':\',Parallel(indPC).RemoteFolder,'\ -a ',int2str(Parallel(indPC).NumCPU(j-nCPU0)), ...
|
command1=['start /B psexec \\',Parallel(indPC).PcName,' -e -u ',Parallel(indPC).user,' -p ',Parallel(indPC).passwd,' -W ',Parallel(indPC).RemoteDrive,':\',Parallel(indPC).RemoteFolder,'\ -a ',int2str(Parallel(indPC).NumCPU(j-nCPU0)), ...
|
||||||
' -low octave --eval fParallel(',int2str(offset+1),',',int2str(sum(nBlockPerCPU(1:j))),',',int2str(j),',',int2str(indPC),',''',fname,''')'];
|
' -low octave --eval fParallel(',int2str(offset+1),',',int2str(sum(nBlockPerCPU(1:j))),',',int2str(j),',',int2str(indPC),',''',fname,''')'];
|
||||||
|
@ -194,7 +276,7 @@ for j=1:totCPU,
|
||||||
command1=['start /B psexec \\',Parallel(indPC).PcName,' -e -u ',Parallel(indPC).user,' -p ',Parallel(indPC).passwd,' -W ',Parallel(indPC).RemoteDrive,':\',Parallel(indPC).RemoteFolder,'\ -a ',int2str(Parallel(indPC).NumCPU(j-nCPU0)), ...
|
command1=['start /B psexec \\',Parallel(indPC).PcName,' -e -u ',Parallel(indPC).user,' -p ',Parallel(indPC).passwd,' -W ',Parallel(indPC).RemoteDrive,':\',Parallel(indPC).RemoteFolder,'\ -a ',int2str(Parallel(indPC).NumCPU(j-nCPU0)), ...
|
||||||
' -low matlab -nosplash -nodesktop -minimize -r fParallel(',int2str(offset+1),',',int2str(sum(nBlockPerCPU(1:j))),',',int2str(j),',',int2str(indPC),',''',fname,''')'];
|
' -low matlab -nosplash -nodesktop -minimize -r fParallel(',int2str(offset+1),',',int2str(sum(nBlockPerCPU(1:j))),',',int2str(j),',',int2str(indPC),',''',fname,''')'];
|
||||||
end
|
end
|
||||||
else % run on the local machine via the network
|
else % Run on the local machine via the network
|
||||||
if exist('OCTAVE_VERSION'),
|
if exist('OCTAVE_VERSION'),
|
||||||
command1=['start /B psexec \\',Parallel(indPC).PcName,' -e -W ',Parallel(indPC).RemoteDrive,':\',Parallel(indPC).RemoteFolder,'\ -a ',int2str(Parallel(indPC).NumCPU(j-nCPU0)), ...
|
command1=['start /B psexec \\',Parallel(indPC).PcName,' -e -W ',Parallel(indPC).RemoteDrive,':\',Parallel(indPC).RemoteFolder,'\ -a ',int2str(Parallel(indPC).NumCPU(j-nCPU0)), ...
|
||||||
' -low octave --eval fParallel(',int2str(offset+1),',',int2str(sum(nBlockPerCPU(1:j))),',',int2str(j),',',int2str(indPC),',''',fname,''')'];
|
' -low octave --eval fParallel(',int2str(offset+1),',',int2str(sum(nBlockPerCPU(1:j))),',',int2str(j),',',int2str(indPC),',''',fname,''')'];
|
||||||
|
@ -204,13 +286,127 @@ for j=1:totCPU,
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
fprintf(fid,'%s\n',command1);
|
|
||||||
|
|
||||||
|
case 1
|
||||||
|
if Parallel(indPC).Local == 1 & newInstance, % run on the local machine
|
||||||
|
if isunix || (~matlab_ver_less_than('7.4') && ismac),
|
||||||
|
if exist('OCTAVE_VERSION')
|
||||||
|
%command1=['octave --eval fParallel\(',int2str(offset+1),',',int2str(sum(nBlockPerCPU(1:j))),',',int2str(j),',',int2str(indPC),',\''',fname,'\''\) &'];
|
||||||
|
command1=['octave --eval slaveParallel\(',int2str(j),',',int2str(indPC),'\) &'];
|
||||||
|
else
|
||||||
|
%command1=['matlab -nosplash -nodesktop -minimize -r fParallel\(',int2str(offset+1),',',int2str(sum(nBlockPerCPU(1:j))),',',int2str(j),',',int2str(indPC),',\''',fname,'\''\) &'];
|
||||||
|
command1=['matlab -nosplash -nodesktop -minimize -r slaveParallel\(',int2str(j),',',int2str(indPC),'\) &'];
|
||||||
|
end
|
||||||
|
else
|
||||||
|
if exist('OCTAVE_VERSION')
|
||||||
|
%command1=['start /B psexec -W ',DyMo, ' -a ',int2str(Parallel(indPC).NumCPU(j-nCPU0)),' -low octave --eval fParallel(',int2str(offset+1),',',int2str(sum(nBlockPerCPU(1:j))),',',int2str(j),',',int2str(indPC),',''',fname,''')'];
|
||||||
|
command1=['start /B psexec -W ',DyMo, ' -a ',int2str(Parallel(indPC).NumCPU(j-nCPU0)),' -low octave --eval slaveParallel(',int2str(j),',',int2str(indPC),')'];
|
||||||
|
else
|
||||||
|
%command1=['start /B psexec -W ',DyMo, ' -a ',int2str(Parallel(indPC).NumCPU(j-nCPU0)),' -low matlab -nosplash -nodesktop -minimize -r fParallel(',int2str(offset+1),',',int2str(sum(nBlockPerCPU(1:j))),',',int2str(j),',',int2str(indPC),',''',fname,''')'];
|
||||||
|
command1=['start /B psexec -W ',DyMo, ' -a ',int2str(Parallel(indPC).NumCPU(j-nCPU0)),' -low matlab -nosplash -nodesktop -minimize -r slaveParallel(',int2str(j),',',int2str(indPC),')'];
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
elseif Parallel(indPC).Local==0 %Run using network on remote machine or also on local machine.
|
||||||
|
if isunix || (~matlab_ver_less_than('7.4') && ismac),
|
||||||
|
%[tempo, RemoteName]=system(['ssh ',Parallel(indPC).user,'@',Parallel(indPC).PcName,' "ifconfig | grep \''inet addr:\''| grep -v \''127.0.0.1\'' | cut -d: -f2 | awk \''{ print $1}\''"']);
|
||||||
|
[tempo, RemoteName]=system(['ssh ',Parallel(indPC).user,'@',Parallel(indPC).PcName,' "hostname --fqdn"']);
|
||||||
|
RemoteName=RemoteName(1:end-1);
|
||||||
|
RemoteFolder = Parallel(indPC).RemoteFolder;
|
||||||
|
else
|
||||||
|
RemoteName = Parallel(indPC).PcName;
|
||||||
|
RemoteFolder = [Parallel(indPC).RemoteDrive,':\',Parallel(indPC).RemoteFolder];
|
||||||
|
end
|
||||||
|
|
||||||
|
remoteFlag=1;
|
||||||
|
|
||||||
|
if strcmpi(RemoteName,MasterName),
|
||||||
|
if ~copyfile(['P_',fname,'_',int2str(j),'End.txt'],RemoteFolder),
|
||||||
|
remoteFlag=0;
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if remoteFlag,
|
||||||
|
if (j==nCPU0+1) & newInstance, % Clean remote folder!
|
||||||
|
if isunix || (~matlab_ver_less_than('7.4') && ismac),
|
||||||
|
system(['ssh ',Parallel(indPC).user,'@',Parallel(indPC).PcName,' rm -fr ',Parallel(indPC).RemoteFolder,'/*']);
|
||||||
|
else
|
||||||
|
mydelete('*.*',['\\',Parallel(indPC).PcName,'\',Parallel(indPC).RemoteDrive,'$\',Parallel(indPC).RemoteFolder,'\']);
|
||||||
|
adir=dir(['\\',Parallel(indPC).PcName,'\',Parallel(indPC).RemoteDrive,'$\',Parallel(indPC).RemoteFolder,'\']);
|
||||||
|
for jdir=3:length(adir)
|
||||||
|
STATUS = rmdir(['\\',Parallel(indPC).PcName,'\',Parallel(indPC).RemoteDrive,'$\',Parallel(indPC).RemoteFolder,'\',adir(jdir).name],'s');
|
||||||
|
if STATUS == 0,
|
||||||
|
disp(['Warning!: Directory ',adir(jdir).name,' could not be removed from ',Parallel(indPC).PcName,'.'])
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if isunix || (~matlab_ver_less_than('7.4') && ismac),
|
||||||
|
% system(['scp ',fname,'_input.mat ',Parallel(indPC).user,'@',Parallel(indPC).PcName,':',Parallel(indPC).RemoteFolder]);
|
||||||
|
for jfil=1:size(NamFileInput,1)
|
||||||
|
if ~isempty(NamFileInput{jfil,1})
|
||||||
|
system(['ssh ',Parallel(indPC).user,'@',Parallel(indPC).PcName,' mkdir -p ',Parallel(indPC).RemoteFolder,'/',NamFileInput{jfil,1}])
|
||||||
|
end
|
||||||
|
system(['scp ',NamFileInput{jfil,1},NamFileInput{jfil,2},' ',Parallel(indPC).user,'@',Parallel(indPC).PcName,':',Parallel(indPC).RemoteFolder,'/',NamFileInput{jfil,1}]);
|
||||||
|
end
|
||||||
|
system(['scp slaveJob',int2str(j),'.mat ',Parallel(indPC).user,'@',Parallel(indPC).PcName,':',Parallel(indPC).RemoteFolder]);
|
||||||
|
if newInstance,
|
||||||
|
system(['scp slaveParallel_input',int2str(j),'.mat ',Parallel(indPC).user,'@',Parallel(indPC).PcName,':',Parallel(indPC).RemoteFolder]);
|
||||||
|
end
|
||||||
|
else
|
||||||
|
%copyfile([fname,'_input.mat'], ['\\',Parallel(indPC).PcName,'\',Parallel(indPC).RemoteDrive,'$\',Parallel(indPC).RemoteFolder])
|
||||||
|
for jfil=1:size(NamFileInput,1)
|
||||||
|
if ~isempty(NamFileInput{jfil,1})
|
||||||
|
mkdir(['\\',Parallel(indPC).PcName,'\',Parallel(indPC).RemoteDrive,'$\',Parallel(indPC).RemoteFolder,'\',NamFileInput{jfil,1}]);
|
||||||
|
end
|
||||||
|
copyfile([NamFileInput{jfil,1},NamFileInput{jfil,2}],['\\',Parallel(indPC).PcName,'\',Parallel(indPC).RemoteDrive,'$\',Parallel(indPC).RemoteFolder,'\',NamFileInput{jfil,1}])
|
||||||
|
end
|
||||||
|
copyfile(['slaveJob',int2str(j),'.mat'], ['\\',Parallel(indPC).PcName,'\',Parallel(indPC).RemoteDrive,'$\',Parallel(indPC).RemoteFolder]);
|
||||||
|
if newInstance,
|
||||||
|
copyfile(['slaveParallel_input',int2str(j),'.mat'], ['\\',Parallel(indPC).PcName,'\',Parallel(indPC).RemoteDrive,'$\',Parallel(indPC).RemoteFolder]);
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if newInstance,
|
||||||
|
if isunix || (~matlab_ver_less_than('7.4') && ismac),
|
||||||
|
if exist('OCTAVE_VERSION'),
|
||||||
|
command1=['ssh ',Parallel(indPC).user,'@',Parallel(indPC).PcName,' "cd ',Parallel(indPC).RemoteFolder, '; octave --eval slaveParallel\(',int2str(j),',',int2str(indPC),'\);" &'];
|
||||||
|
else
|
||||||
|
command1=['ssh ',Parallel(indPC).user,'@',Parallel(indPC).PcName,' "cd ',Parallel(indPC).RemoteFolder, '; matlab -nosplash -nodesktop -minimize -r slaveParallel\(',int2str(j),',',int2str(indPC),'\);" &'];
|
||||||
|
end
|
||||||
|
else
|
||||||
|
if ~strcmp(Parallel(indPC).PcName,MasterName), % Run on a remote machine.
|
||||||
|
if exist('OCTAVE_VERSION'),
|
||||||
|
command1=['start /B psexec \\',Parallel(indPC).PcName,' -e -u ',Parallel(indPC).user,' -p ',Parallel(indPC).passwd,' -W ',Parallel(indPC).RemoteDrive,':\',Parallel(indPC).RemoteFolder,'\ -a ',int2str(Parallel(indPC).NumCPU(j-nCPU0)), ...
|
||||||
|
' -low octave --eval slaveParallel(',int2str(j),',',int2str(indPC),')'];
|
||||||
|
else
|
||||||
|
command1=['start /B psexec \\',Parallel(indPC).PcName,' -e -u ',Parallel(indPC).user,' -p ',Parallel(indPC).passwd,' -W ',Parallel(indPC).RemoteDrive,':\',Parallel(indPC).RemoteFolder,'\ -a ',int2str(Parallel(indPC).NumCPU(j-nCPU0)), ...
|
||||||
|
' -low matlab -nosplash -nodesktop -minimize -r slaveParallel(',int2str(j),',',int2str(indPC),')'];
|
||||||
|
end
|
||||||
|
else % Run on the local machine via the network.
|
||||||
|
if exist('OCTAVE_VERSION'),
|
||||||
|
command1=['start /B psexec \\',Parallel(indPC).PcName,' -e -W ',Parallel(indPC).RemoteDrive,':\',Parallel(indPC).RemoteFolder,'\ -a ',int2str(Parallel(indPC).NumCPU(j-nCPU0)), ...
|
||||||
|
' -low octave --eval slaveParallel(',int2str(j),',',int2str(indPC),')'];
|
||||||
|
else
|
||||||
|
command1=['start /B psexec \\',Parallel(indPC).PcName,' -e -W ',Parallel(indPC).RemoteDrive,':\',Parallel(indPC).RemoteFolder,'\ -a ',int2str(Parallel(indPC).NumCPU(j-nCPU0)), ...
|
||||||
|
' -low matlab -nosplash -nodesktop -minimize -r slaveParallel(',int2str(j),',',int2str(indPC),')'];
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
fprintf(fid,'%s\n',command1);
|
||||||
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
fclose(fid);
|
||||||
|
|
||||||
fclose(fid);
|
% Run the slaves.
|
||||||
|
|
||||||
% Run the slaves
|
|
||||||
if isunix || (~matlab_ver_less_than('7.4') && ismac),
|
if isunix || (~matlab_ver_less_than('7.4') && ismac),
|
||||||
system('sh ConcurrentCommand1.bat &');
|
system('sh ConcurrentCommand1.bat &');
|
||||||
pause(1)
|
pause(1)
|
||||||
|
@ -218,10 +414,10 @@ else
|
||||||
system('ConcurrentCommand1.bat');
|
system('ConcurrentCommand1.bat');
|
||||||
end
|
end
|
||||||
|
|
||||||
% Wait for the slaves to finish their job, and display some progress information meanwhile
|
% Wait for the slaves to finish their job, and display some progress
|
||||||
t0=cputime;
|
% information meanwhile.
|
||||||
t00=cputime;
|
|
||||||
hh=NaN(1,nBlock);
|
|
||||||
if exist('OCTAVE_VERSION'),
|
if exist('OCTAVE_VERSION'),
|
||||||
diary off;
|
diary off;
|
||||||
printf('\n');
|
printf('\n');
|
||||||
|
@ -242,12 +438,14 @@ else
|
||||||
end
|
end
|
||||||
pcerdone = NaN(1,totCPU);
|
pcerdone = NaN(1,totCPU);
|
||||||
while (1)
|
while (1)
|
||||||
|
|
||||||
waitbarString = '';
|
waitbarString = '';
|
||||||
statusString = '';
|
statusString = '';
|
||||||
pause(1)
|
pause(1)
|
||||||
|
|
||||||
stax = dir(['comp_status_',fname,'*.mat']);
|
stax = dir(['comp_status_',fname,'*.mat']);
|
||||||
for j=1:length(stax),
|
|
||||||
|
for j=1:length(stax),
|
||||||
try
|
try
|
||||||
load(stax(j).name)
|
load(stax(j).name)
|
||||||
pcerdone(j) = prtfrc;
|
pcerdone(j) = prtfrc;
|
||||||
|
@ -260,14 +458,16 @@ while (1)
|
||||||
end
|
end
|
||||||
if prtfrc==1, delete(stax(j).name), end
|
if prtfrc==1, delete(stax(j).name), end
|
||||||
catch
|
catch
|
||||||
|
if j>1
|
||||||
|
j=j-1
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if exist('OCTAVE_VERSION'),
|
if exist('OCTAVE_VERSION'),
|
||||||
printf([statusString,'\r'], 100 .* pcerdone);
|
printf([statusString,'\r'], 100 .* pcerdone);
|
||||||
else
|
else
|
||||||
figure(hfigstatus),
|
figure(hfigstatus),
|
||||||
for j=1:length(stax),
|
for j=1:length(stax)
|
||||||
try
|
try
|
||||||
axes(hstatus(idCPU(j))),
|
axes(hstatus(idCPU(j))),
|
||||||
hpat = findobj(hstatus(idCPU(j)),'Type','patch');
|
hpat = findobj(hstatus(idCPU(j)),'Type','patch');
|
||||||
|
@ -278,7 +478,9 @@ while (1)
|
||||||
end
|
end
|
||||||
title([status_Title{j},' - ',status_String{j}]);
|
title([status_Title{j},' - ',status_String{j}]);
|
||||||
catch
|
catch
|
||||||
|
if j>1
|
||||||
|
j=j-1
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -294,13 +496,13 @@ while (1)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
% Create return value
|
% Create return value.
|
||||||
for j=1:totCPU,
|
for j=1:totCPU,
|
||||||
load([fname,'_output_',int2str(j),'.mat'],'fOutputVar');
|
load([fname,'_output_',int2str(j),'.mat'],'fOutputVar');
|
||||||
delete([fname,'_output_',int2str(j),'.mat']);
|
delete([fname,'_output_',int2str(j),'.mat']);
|
||||||
fOutVar(j)=fOutputVar;
|
fOutVar(j)=fOutputVar;
|
||||||
end
|
end
|
||||||
|
|
||||||
% Cleanup
|
% Cleanup.
|
||||||
delete([fname,'_input.mat'])
|
delete([fname,'_input.mat'])
|
||||||
delete ConcurrentCommand1.bat
|
delete ConcurrentCommand1.bat
|
||||||
|
|
Loading…
Reference in New Issue