New parallel dynare:

1) safe management of remote folder;
2) shh scp (and windows equivalent) commands are concentrated in the master;
3) management of remote crashes;
4) begin building option to interrupt remote processes;
5) better parallel waitbar: pops up only at STARTUP (can be minimized subsequently); adaptive dimension;
time-shift
Marco Ratto 2010-10-08 16:15:50 +02:00
parent f587e0f1d2
commit e846c5cda7
8 changed files with 468 additions and 810 deletions

View File

@ -1,4 +1,4 @@
function closeSlave(Parallel), function closeSlave(Parallel,TmpFolder),
% PARALLEL CONTEXT % PARALLEL CONTEXT
% In parallel context, this utility closes all remote matlab instances % In parallel context, this utility closes all remote matlab instances
% called by masterParallel with strategy (1) i.e. always open (which leaves % called by masterParallel with strategy (1) i.e. always open (which leaves
@ -7,8 +7,8 @@ function closeSlave(Parallel),
% INPUTS % INPUTS
% o Parallel [struct vector] copy of options_.parallel. % o Parallel [struct vector] copy of options_.parallel.
% %
% OUTPUTS % OUTPUTS
% None % None
% %
% Copyright (C) 2010 Dynare Team % Copyright (C) 2010 Dynare Team
% %
@ -27,29 +27,28 @@ function closeSlave(Parallel),
% 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/>.
try for indPC=1:length(Parallel),
delete( 'slaveParallel_input*.mat'); if (Parallel(indPC).Local==0),
dynareParallelDelete( 'slaveParallel_input*.mat',TmpFolder,Parallel(indPC));
else
delete( 'slaveParallel_input*.mat');
pause(1)
delete(['slaveParallel_*.log']);
end
end
for indPC=1:length(Parallel), while(1)
if (Parallel(indPC).Local==0), if isempty(dynareParallelDir(['P_slave_',int2str(j),'End.txt'],TmpFolder,Parallel));
if isunix || (~matlab_ver_less_than('7.4') && ismac), for indPC=1:length(Parallel),
system(['ssh ',Parallel(indPC).user,'@',Parallel(indPC).PcName,' rm -fr ',Parallel(indPC).RemoteFolder,'/slaveParallel_input*.mat']); if (Parallel(indPC).Local==0),
system(['ssh ',Parallel(indPC).user,'@',Parallel(indPC).PcName,' rm -fr ',Parallel(indPC).RemoteFolder,'/*']); dynareParallelRmDir(TmpFolder,Parallel(indPC)),
else
mydelete('slaveParallel_input*.mat',['\\',Parallel(indPC).PcName,'\',Parallel(indPC).RemoteDrive,'$\',Parallel(indPC).RemoteFolder,'\']);
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
break
end end
catch end
% Only for testing, will be remouved!
E1=fopen('Errore1-closeSlave.txt','w+');
fclose(E1);
end

View File

@ -1,4 +1,4 @@
function [nCPU, totCPU, nBlockPerCPU] = distributeJobs(Parallel, fBlock, nBlock) function [nCPU, totCPU, nBlockPerCPU, totSLAVES] = distributeJobs(Parallel, fBlock, nBlock)
% PARALLEL CONTEXT % PARALLEL CONTEXT
% In parallel context this function is used to determine the total number of available CPUs, % In parallel context this function is used to determine the total number of available CPUs,
% and the number of threads to run on each CPU. % and the number of threads to run on each CPU.
@ -46,7 +46,9 @@ if (nBlock-offset0)>totCPU,
diff = mod((nBlock-offset0),totCPU); diff = mod((nBlock-offset0),totCPU);
nBlockPerCPU(1:diff) = ceil((nBlock-offset0)/totCPU); nBlockPerCPU(1:diff) = ceil((nBlock-offset0)/totCPU);
nBlockPerCPU(diff+1:totCPU) = floor((nBlock-offset0)/totCPU); nBlockPerCPU(diff+1:totCPU) = floor((nBlock-offset0)/totCPU);
totSLAVES=length(Parallel);
else else
nBlockPerCPU(1:nBlock-offset0)=1; nBlockPerCPU(1:nBlock-offset0)=1;
totCPU = nBlock-offset0; totCPU = nBlock-offset0;
totSLAVES = min(find(cumsum(nCPU)>=totCPU));
end end

View File

@ -39,11 +39,13 @@ if nargin<5,
Parallel.Local=1; Parallel.Local=1;
end end
save(['comp_status_',funcName,int2str(njob),'.mat'],'prtfrc','njob','waitbarString','waitbarTitle'); try
if Parallel.Local==0, save(['comp_status_',funcName,int2str(njob),'.mat'],'prtfrc','njob','waitbarString','waitbarTitle');
if isunix || (~matlab_ver_less_than('7.4') && ismac), catch
system(['scp comp_status_',funcName,int2str(njob),'.mat ',Parallel.user,'@',MasterName,':',DyMo]);
else
copyfile(['comp_status_',funcName,int2str(njob),'.mat'],['\\',MasterName,'\',DyMo(1),'$\',DyMo(4:end),'\']);
end
end end
fslave = dir( ['slaveParallel_input',int2str(njob),'.mat']);
if isempty(fslave),
error('Master asked to break the job')
end

View File

@ -5,15 +5,15 @@ function fParallel(fblck,nblck,whoiam,ThisMatlab,fname)
% computing task itself. % computing task itself.
% %
% INPUTS % INPUTS
% o fblck [int] index number of the first thread to run in this % o fblck [int] index number of the first thread to run in this
% MATLAB instance % MATLAB instance
% o nblck [int] number of threads to run in this % o nblck [int] number of threads to run in this
% MATLAB instance % MATLAB instance
% o whoiam [int] index number of this CPU among all CPUs in the % o whoiam [int] index number of this CPU among all CPUs in the
% cluster % cluster
% o ThisMatlab [int] index number of this slave machine in the cluster % o ThisMatlab [int] index number of this slave machine in the cluster
% (entry in options_.parallel) % (entry in options_.parallel)
% o fname [string] function to be run, containing the computing task % o fname [string] function to be run, containing the computing task
% %
% OUTPUTS % OUTPUTS
% None % None
@ -46,11 +46,10 @@ delete( [fname,'_',int2str(whoiam),'.log']);
diary( [fname,'_',int2str(whoiam),'.log']); diary( [fname,'_',int2str(whoiam),'.log']);
% Configure dynare environment.
% configure dynare environment
dynareroot = dynare_config(); dynareroot = dynare_config();
% Load input data % Load input data.
load( [fname,'_input']) load( [fname,'_input'])
if exist('fGlobalVar') && ~isempty (fGlobalVar) if exist('fGlobalVar') && ~isempty (fGlobalVar)
@ -60,67 +59,52 @@ if exist('fGlobalVar') && ~isempty (fGlobalVar)
evalin('base',['global ',globalVars{j},';']) evalin('base',['global ',globalVars{j},';'])
end end
struct2local(fGlobalVar); struct2local(fGlobalVar);
% create global variables in the base workspace as well % Create global variables in the base workspace as well.
evalin('base',['load( [''',fname,'_input''],''fGlobalVar'')']) evalin('base',['load( [''',fname,'_input''],''fGlobalVar'')'])
evalin('base','struct2local(fGlobalVar)'); evalin('base','struct2local(fGlobalVar)');
end end
% On UNIX, mount the master working directory through SSH FS
% if (isunix | (~matlab_ver_less_than('7.4') & ismac) ) & Parallel(ThisMatlab).Local==0,
% system(['mkdir ~/MasterRemoteMirror_',fname,'_',int2str(whoiam)]);
% system(['sshfs ',Parallel(ThisMatlab).user,'@',fInputVar.MasterName,':/',fInputVar.DyMo,' ~/MasterRemoteMirror_',fname,'_',int2str(whoiam)]);
% end
% Special hack for MH directory: possibly no longer needed ?????? now all
% files are managed locally and sent backwards later on in this routine!
% if isfield(fInputVar,'MhDirectoryName') & Parallel(ThisMatlab).Local==0,
% if isunix | (~matlab_ver_less_than('7.4') & ismac),
% fInputVar.MhDirectoryName = ['~/MasterRemoteMirror_',fname,'_',int2str(whoiam),'/',fInputVar.MhDirectoryName];
% else
% fInputVar.MhDirectoryName = ['\\',fInputVar.MasterName,'\',fInputVar.DyMo(1),'$\',fInputVar.DyMo(4:end),'\',fInputVar.MhDirectoryName];
% end
% end
fInputVar.Parallel = Parallel; fInputVar.Parallel = Parallel;
% Launch the routine to be run in parallel
tic,
% keyboard;
fOutputVar = feval(fname, fInputVar ,fblck, nblck, whoiam, ThisMatlab);
toc,
if isfield(fOutputVar,'OutputFileName'),
OutputFileName = fOutputVar.OutputFileName;
else
OutputFileName = '';
end
if(whoiam)
% Launch the routine to be run in parallel.
% Save the output result
save([ fname,'_output_',int2str(whoiam),'.mat'],'fOutputVar' ) try,
tic,
% Inform the master that the job is finished, and transfer the output data
if Parallel(ThisMatlab).Local fOutputVar = feval(fname, fInputVar ,fblck, nblck, whoiam, ThisMatlab);
delete(['P_',fname,'_',int2str(whoiam),'End.txt']); toc,
if isfield(fOutputVar,'OutputFileName'),
OutputFileName = fOutputVar.OutputFileName;
else else
if isunix || (~matlab_ver_less_than('7.4') && ismac), OutputFileName = '';
for j=1:size(OutputFileName,1),
system(['scp ',OutputFileName{j,1},OutputFileName{j,2},' ',Parallel(ThisMatlab).user,'@',fInputVar.MasterName,':',fInputVar.DyMo,'/',OutputFileName{j,1}]);
end
system(['scp ',fname,'_output_',int2str(whoiam),'.mat ',Parallel(ThisMatlab).user,'@',fInputVar.MasterName,':',fInputVar.DyMo]);
system(['ssh ',Parallel(ThisMatlab).user,'@',fInputVar.MasterName,' rm -f ',fInputVar.DyMo,'/P_',fname,'_',int2str(whoiam),'End.txt']);
% system(['fusermount -u ~/MasterRemoteMirror_',fname,'_',int2str(whoiam)]);
% system(['rm -r ~/MasterRemoteMirror_',fname,'_',int2str(whoiam)]);
else
for j=1:size(OutputFileName,1),
copyfile([OutputFileName{j,1},OutputFileName{j,2}],['\\',fInputVar.MasterName,'\',fInputVar.DyMo(1),'$\',fInputVar.DyMo(4:end),'\',OutputFileName{j,1}])
end
copyfile([fname,'_output_',int2str(whoiam),'.mat'],['\\',fInputVar.MasterName,'\',fInputVar.DyMo(1),'$\',fInputVar.DyMo(4:end)]);
delete(['\\',fInputVar.MasterName,'\',fInputVar.DyMo(1),'$\',fInputVar.DyMo(4:end),'\P_',fname,'_',int2str(whoiam),'End.txt']);
end
end end
if(whoiam)
% Save the output result.
save([ fname,'_output_',int2str(whoiam),'.mat'],'fOutputVar' )
end
disp(['fParallel ',int2str(whoiam),' completed.'])
catch ME
disp(['fParallel ',int2str(whoiam),' crashed.'])
fOutputVar.error = ME;
save([ fname,'_output_',int2str(whoiam),'.mat'],'fOutputVar' )
waitbarString = fOutputVar.error.message;
% waitbarTitle=['Metropolis-Hastings ',options_.parallel(ThisMatlab).PcName];
if Parallel(ThisMatlab).Local,
waitbarTitle='Local ';
else
waitbarTitle=[Parallel(ThisMatlab).PcName];
end
fMessageStatus(NaN,whoiam,waitbarString, waitbarTitle, Parallel(ThisMatlab));
end end
disp(['fParallel ',int2str(whoiam),' completed.'])
diary off; diary off;
delete(['P_',fname,'_',int2str(whoiam),'End.txt']);
exit; exit;

View File

@ -196,6 +196,7 @@ options_.plot_priors = 1;
options_.cova_compute = 1; options_.cova_compute = 1;
options_.parallel = 0; options_.parallel = 0;
options_.parallel_info.leaveSlaveOpen = 0; options_.parallel_info.leaveSlaveOpen = 0;
options_.parallel_info.RemoteTmpFolder = '';
options_.number_of_grid_points_for_kde = 2^9; options_.number_of_grid_points_for_kde = 2^9;
quarter = 1; quarter = 1;
years = [1 2 3 4 5 10 20 30 40 50]; years = [1 2 3 4 5 10 20 30 40 50];

View File

@ -1,22 +1,22 @@
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,initialize)
% PARALLEL CONTEXT % PARALLEL CONTEXT
% This is the most important function for the management of DYNARE parallel % This is the most important function for the management of DYNARE parallel
% computing. % computing.
% It is the top-level function called on the master computer when parallelizing a task. % 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). % This function have two main computational startegy for manage the matlab worker (slave process).
% 0 Simple Close/Open Stategy: % 0 Simple Close/Open Stategy:
% In this case the new matlab istances (slave process) are open when % In this case the new matlab istances (slave process) are open when
% necessary and then closed. This can happen many times during the % necessary and then closed. This can happen many times during the
% simulation of a model. % simulation of a model.
% 1 Alway Open Stategy: % 1 Alway Open Stategy:
% In this case we have a more sophisticated management of slave processes, % 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 % 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 % 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 % fixed time it is destroyed. This solution removes the computational
% time necessary to Open/Close new matlab istances. % time necessary to Open/Close new matlab istances.
% The first (point 0) is the default Strategy % The first (point 0) is the default Strategy
% i.e.(Parallel_info.leaveSlaveOpen=0). This value can be changed by the % i.e.(Parallel_info.leaveSlaveOpen=0). This value can be changed by the
@ -70,42 +70,60 @@ function [fOutVar,nBlockPerCPU, totCPU] = masterParallel(Parallel,fBlock,nBlock,
% along with Dynare. If not, see <http://www.gnu.org/licenses/>. % along with Dynare. If not, see <http://www.gnu.org/licenses/>.
% Fix the strategy to be used.
Strategy=-1;
if ~isempty(Parallel_info) % If islocal==0, create a new directory for remote computation.
Strategy=Parallel_info.leaveSlaveOpen; % This directory is named using current data and time,
end % is used only one time and then deleted.
persistent PRCDir
% PRCDir= Present Remote Computational Directory!
Strategy=Parallel_info.leaveSlaveOpen;
islocal = 0;
for j=1:length(Parallel),
islocal=islocal+Parallel(j).Local;
end
if nargin>8 && initialize==1
if islocal == 0,
PRCDir=CreateTimeString();
assignin('base','PRCDirTmp',PRCDir),
evalin('base','options_.parallel_info.RemoteTmpFolder=PRCDirTmp;')
evalin('base','clear PRCDirTmp,')
else
% Delete the traces (if exists) of last local section computations.
if Strategy==1,
mydelete(['slaveParallel_input*.mat']);
end
end
return
end
for j=1:length(Parallel), for j=1:length(Parallel),
if isempty(Parallel(j).MatlabPath), if isempty(Parallel(j).MatlabPath),
Parallel(j).MatlabPath = 'matlab'; Parallel(j).MatlabPath = 'matlab';
end end
end end
if Strategy==0
disp('User Strategy Now Is Open/Close (0)'); % if Strategy==0
else % disp('User Strategy Now Is Open/Close (0)');
disp('User Strategy Now Is Always Open (1)'); % else
end % disp('User Strategy Now Is Always Open (1)');
% end
if Strategy==1 if Strategy==1
% Delete the traces (if exists) of last section computations. totCPU=0;
persistent initialize
if isempty(initialize),
mydelete(['P_slave_*End.txt']);
mydelete(['slaveParallel_input*.mat']);
initialize = 0;
pause(1),
end
totCPU=0;
end end
% Determine my hostname and my working directory. % 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) ,
% [tempo, MasterName]=system(['ifconfig | grep ''inet addr:''| grep -v ''127.0.0.1'' | cut -d: -f2 | awk ''{ print $1}''']);
[tempo, MasterName]=system('hostname --fqdn'); [tempo, MasterName]=system('hostname --fqdn');
else else
[tempo, MasterName]=system('hostname'); [tempo, MasterName]=system('hostname');
end end
MasterName=deblank(MasterName); MasterName=deblank(MasterName);
@ -113,44 +131,52 @@ fInputVar.MasterName = MasterName;
% Save input data for use by the slaves. % Save input data for use by the slaves.
switch Strategy switch Strategy
case 0 case 0
if exist('fGlobalVar'), if exist('fGlobalVar'),
save([fname,'_input.mat'],'fInputVar','fGlobalVar') save([fname,'_input.mat'],'fInputVar','fGlobalVar')
else else
save([fname,'_input.mat'],'fInputVar') save([fname,'_input.mat'],'fInputVar')
end end
save([fname,'_input.mat'],'Parallel','-append') save([fname,'_input.mat'],'Parallel','-append')
case 1 case 1
if exist('fGlobalVar'), if exist('fGlobalVar'),
save(['temp_input.mat'],'fInputVar','fGlobalVar') save(['temp_input.mat'],'fInputVar','fGlobalVar')
else else
save(['temp_input.mat'],'fInputVar') save(['temp_input.mat'],'fInputVar')
end end
save(['temp_input.mat'],'Parallel','-append') save(['temp_input.mat'],'Parallel','-append')
end end
% Determine the total number of available CPUs, and the number of threads % Determine the total number of available CPUs, and the number of threads
% to run on each CPU. % to run on each CPU.
[nCPU, totCPU, nBlockPerCPU] = distributeJobs(Parallel, fBlock, nBlock); [nCPU, totCPU, nBlockPerCPU, totSlaves] = distributeJobs(Parallel, fBlock, nBlock);
offset0 = fBlock-1; offset0 = fBlock-1;
% Clean up remnants of previous runs. % Clean up remnants of previous runs.
mydelete(['comp_status_',fname,'*.mat']) mydelete(['comp_status_',fname,'*.mat'])
mydelete(['P_',fname,'*End.txt']);
% Create a shell script containing the commands to launch the required tasks on the slaves % Create a shell script containing the commands to launch the required tasks on the slaves
fid = fopen('ConcurrentCommand1.bat','w+'); fid = fopen('ConcurrentCommand1.bat','w+');
% Creo la directory in cui effettuare i calcoli in remoto ...
if isempty(PRCDir) && ~islocal,
error('PRCDir not initialized!')
else
dynareParallelMkDir(PRCDir,Parallel(1:totSlaves));
end
for j=1:totCPU, for j=1:totCPU,
if Strategy==1 if Strategy==1
command1 = ' '; command1 = ' ';
end end
indPC=min(find(nCPU>=j)); indPC=min(find(nCPU>=j));
@ -161,254 +187,178 @@ for j=1:totCPU,
end end
offset = sum(nBlockPerCPU(1:j-1))+offset0; offset = sum(nBlockPerCPU(1:j-1))+offset0;
% Creo un file che mi serve per sapere se la computazione di un
% blocco parallelo (una core) è terminata oppure no!
fid1=fopen(['P_',fname,'_',int2str(j),'End.txt'],'w+'); fid1=fopen(['P_',fname,'_',int2str(j),'End.txt'],'w+');
fclose(fid1); fclose(fid1);
if Strategy==1 if Strategy==1,
fblck = offset+1;
nblck = sum(nBlockPerCPU(1:j)); fblck = offset+1;
save temp_input fblck nblck fname -append; nblck = sum(nBlockPerCPU(1:j));
copyfile('temp_input.mat',['slaveJob',int2str(j),'.mat']) save temp_input fblck nblck fname -append;
if Parallel(indPC).Local ==0, copyfile('temp_input.mat',['slaveJob',int2str(j),'.mat'])
if Parallel(indPC).Local ==0,
fid1=fopen(['stayalive',int2str(j),'.txt'],'w+'); fid1=fopen(['stayalive',int2str(j),'.txt'],'w+');
fclose(fid1); fclose(fid1);
if isunix || (~matlab_ver_less_than('7.4') && ismac), dynareParallelSendFiles(['stayalive',int2str(j),'.txt'],PRCDir,Parallel(indPC));
system(['scp stayalive',int2str(j),'.txt ',Parallel(indPC).user,'@',Parallel(indPC).PcName,':',Parallel(indPC).RemoteFolder]); mydelete(['stayalive',int2str(j),'.txt']);
else end
copyfile(['stayalive',int2str(j),'.txt'], ['\\',Parallel(indPC).PcName,'\',Parallel(indPC).RemoteDrive,'$\',Parallel(indPC).RemoteFolder]); % Wait for possibly local alive CPU to start the new job or close by
end % internal criteria.
mydelete(['stayalive',int2str(j),'.txt'],'w+'); pause(1);
end
% Wait for possibly local alive CPU to start the new job or close by
% internal criteria.
pause(1);
newInstance = 0; newInstance = 0;
% Check if j CPU is already alive. % Check if j CPU is already alive.
if isempty( dir(['P_slave_',int2str(j),'End.txt'])); if isempty(dynareParallelDir(['P_slave_',int2str(j),'End.txt'],PRCDir,Parallel(indPC)));
fid1=fopen(['P_slave_',int2str(j),'End.txt'],'w+'); fid1=fopen(['P_slave_',int2str(j),'End.txt'],'w+');
fclose(fid1); fclose(fid1);
if Parallel(indPC).Local==0,
dynareParallelSendFiles(['P_slave_',int2str(j),'End.txt'],PRCDir,Parallel(indPC));
delete(['P_slave_',int2str(j),'End.txt']);
end
newInstance = 1; newInstance = 1;
storeGlobalVars( ['slaveParallel_input',int2str(j)]); storeGlobalVars( ['slaveParallel_input',int2str(j)]);
save( ['slaveParallel_input',int2str(j)],'Parallel','-append'); save( ['slaveParallel_input',int2str(j)],'Parallel','-append');
% Prepare global vars for Slave. % Prepare global vars for Slave.
end end
end else
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% The following 'switch - case' code is the core of this function!
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 "addpath(''',Parallel(indPC).DynarePath,'''), fParallel(',int2str(offset+1),',',int2str(sum(nBlockPerCPU(1:j))),',',int2str(j),',',int2str(indPC),',''',fname,''')" &'];
else
command1=[Parallel(indPC).MatlabPath,' -nosplash -nodesktop -minimize -r "addpath(''',Parallel(indPC).DynarePath,'''), fParallel(',int2str(offset+1),',',int2str(sum(nBlockPerCPU(1:j))),',',int2str(j),',',int2str(indPC),',''',fname,''')" &'];
end
else
if exist('OCTAVE_VERSION')
command1=['start /B psexec -W ',DyMo, ' -a ',int2str(Parallel(indPC).NumCPU(j-nCPU0)),' -low octave --eval "addpath(''',Parallel(indPC).DynarePath,'''), fParallel(',int2str(offset+1),',',int2str(sum(nBlockPerCPU(1:j))),',',int2str(j),',',int2str(indPC),',''',fname,''')"'];
else
command1=['start /B psexec -W ',DyMo, ' -a ',int2str(Parallel(indPC).NumCPU(j-nCPU0)),' -low ',Parallel(indPC).MatlabPath,' -nosplash -nodesktop -minimize -r "addpath(''',Parallel(indPC).DynarePath,'''), 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; % Se la computazione è remota, lo creo in locale, lo copio directory remota (creata
% sopra) e lo cancello in locale. Lo stesso vale per gli altri
% dati.
save( ['slaveParallel_input',int2str(j)],'Parallel');
if Parallel(indPC).Local==0,
dynareParallelSendFiles(['P_',fname,'_',int2str(j),'End.txt'],PRCDir,Parallel(indPC));
delete(['P_',fname,'_',int2str(j),'End.txt']);
dynareParallelSendFiles(['slaveParallel_input',int2str(j),'.mat'],PRCDir,Parallel(indPC));
delete(['slaveParallel_input',int2str(j),'.mat']);
end
if strcmpi(RemoteName,MasterName), end
if ~copyfile(['P_',fname,'_',int2str(j),'End.txt'],RemoteFolder),
remoteFlag=0; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% The following 'switch - case' code is the core of this function!
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 "addpath(''',Parallel(indPC).DynarePath,'''), fParallel(',int2str(offset+1),',',int2str(sum(nBlockPerCPU(1:j))),',',int2str(j),',',int2str(indPC),',''',fname,''')" &'];
else
command1=[Parallel(indPC).MatlabPath,' -nosplash -nodesktop -minimize -r "addpath(''',Parallel(indPC).DynarePath,'''), fParallel(',int2str(offset+1),',',int2str(sum(nBlockPerCPU(1:j))),',',int2str(j),',',int2str(indPC),',''',fname,''')" &'];
end
else
if exist('OCTAVE_VERSION')
command1=['start /B psexec -W ',DyMo, ' -a ',int2str(Parallel(indPC).NumCPU(j-nCPU0)),' -low octave --eval "addpath(''',Parallel(indPC).DynarePath,'''), fParallel(',int2str(offset+1),',',int2str(sum(nBlockPerCPU(1:j))),',',int2str(j),',',int2str(indPC),',''',fname,''')"'];
else
command1=['start /B psexec -W ',DyMo, ' -a ',int2str(Parallel(indPC).NumCPU(j-nCPU0)),' -low ',Parallel(indPC).MatlabPath,' -nosplash -nodesktop -minimize -r "addpath(''',Parallel(indPC).DynarePath,'''), 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 j==nCPU0+1,
dynareParallelSendFiles([fname,'_input.mat'],PRCDir,Parallel(indPC));
dynareParallelSendFiles(NamFileInput,PRCDir,Parallel(indPC));
end
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,'/',PRCDir, '; octave --eval \"addpath(''',Parallel(indPC).DynarePath,'''), fParallel(',int2str(offset+1),',',int2str(sum(nBlockPerCPU(1:j))),',',int2str(j),',',int2str(indPC),',''',fname,''');\" " &'];
else
command1=['ssh ',Parallel(indPC).user,'@',Parallel(indPC).PcName,' "cd ',Parallel(indPC).RemoteFolder,'/',PRCDir, '; ',Parallel(indPC).MatlabPath,' -nosplash -nodesktop -minimize -r \"addpath(''',Parallel(indPC).DynarePath,'''), fParallel(',int2str(offset+1),',',int2str(sum(nBlockPerCPU(1:j))),',',int2str(j),',',int2str(indPC),',''',fname,''');\" " &'];
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,'\',PRCDir,'\ -a ',int2str(Parallel(indPC).NumCPU(j-nCPU0)), ...
' -low octave --eval "addpath(''',Parallel(indPC).DynarePath,'''), fParallel(',int2str(offset+1),',',int2str(sum(nBlockPerCPU(1:j))),',',int2str(j),',',int2str(indPC),',''',fname,''')"'];
else
command1=['start /B psexec \\',Parallel(indPC).PcName,' -e -u ',Parallel(indPC).user,' -p ',Parallel(indPC).passwd,' -W ',Parallel(indPC).RemoteDrive,':\',Parallel(indPC).RemoteFolder,'\',PRCDir,'\ -a ',int2str(Parallel(indPC).NumCPU(j-nCPU0)), ...
' -low ',Parallel(indPC).MatlabPath,' -nosplash -nodesktop -minimize -r "addpath(''',Parallel(indPC).DynarePath,'''), fParallel(',int2str(offset+1),',',int2str(sum(nBlockPerCPU(1:j))),',',int2str(j),',',int2str(indPC),',''',fname,''')"'];
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,'\',PRCDir,'\ -a ',int2str(Parallel(indPC).NumCPU(j-nCPU0)), ...
' -low octave --eval "addpath(''',Parallel(indPC).DynarePath,'''), fParallel(',int2str(offset+1),',',int2str(sum(nBlockPerCPU(1:j))),',',int2str(j),',',int2str(indPC),',''',fname,''')"'];
else
command1=['start /B psexec \\',Parallel(indPC).PcName,' -e -W ',Parallel(indPC).RemoteDrive,':\',Parallel(indPC).RemoteFolder,'\',PRCDir,'\ -a ',int2str(Parallel(indPC).NumCPU(j-nCPU0)), ...
' -low ',Parallel(indPC).MatlabPath,' -nosplash -nodesktop -minimize -r "addpath(''',Parallel(indPC).DynarePath,'''), fParallel(',int2str(offset+1),',',int2str(sum(nBlockPerCPU(1:j))),',',int2str(j),',',int2str(indPC),',''',fname,''')"'];
end
end
end end
end end
if remoteFlag,
if j==nCPU0+1,
if isunix || (~matlab_ver_less_than('7.4') && ismac), case 1
system(['ssh ',Parallel(indPC).user,'@',Parallel(indPC).PcName,' rm -fr ',Parallel(indPC).RemoteFolder,'/*']); 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 "addpath(''',Parallel(indPC).DynarePath,'''), slaveParallel(',int2str(j),',',int2str(indPC),')" &'];
else else
mydelete('*.*',['\\',Parallel(indPC).PcName,'\',Parallel(indPC).RemoteDrive,'$\',Parallel(indPC).RemoteFolder,'\']); %command1=[Parallel(indPC).MatlabPath,' -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,'\']); command1=[Parallel(indPC).MatlabPath,' -nosplash -nodesktop -minimize -r "addpath(''',Parallel(indPC).DynarePath,'''), slaveParallel(',int2str(j),',',int2str(indPC),')" &'];
for jdir=3:length(adir) end
STATUS = rmdir(['\\',Parallel(indPC).PcName,'\',Parallel(indPC).RemoteDrive,'$\',Parallel(indPC).RemoteFolder,'\',adir(jdir).name],'s'); else
if STATUS == 0, if exist('OCTAVE_VERSION')
disp(['Warning!: Directory ',adir(jdir).name,' could not be removed from ',Parallel(indPC).PcName,'.']) %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 "addpath(''',Parallel(indPC).DynarePath,'''), slaveParallel(',int2str(j),',',int2str(indPC),')"'];
else
%command1=['start /B psexec -W ',DyMo, ' -a ',int2str(Parallel(indPC).NumCPU(j-nCPU0)),' -low ',Parallel(indPC).MatlabPath,' -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 ',Parallel(indPC).MatlabPath,' -nosplash -nodesktop -minimize -r "addpath(''',Parallel(indPC).DynarePath,'''), slaveParallel(',int2str(j),',',int2str(indPC),')"'];
end
end
elseif Parallel(indPC).Local==0, % Run using network on remote machine or also on local machine.
dynareParallelSendFiles(['P_',fname,'_',int2str(j),'End.txt'],PRCDir,Parallel(indPC));
dynareParallelSendFiles(['slaveJob',int2str(j),'.mat'],PRCDir,Parallel(indPC));
if j==nCPU0+1,
dynareParallelSendFiles(NamFileInput,PRCDir,Parallel(indPC));
end
if newInstance,
dynareParallelSendFiles(['slaveParallel_input',int2str(j),'.mat'],PRCDir,Parallel(indPC))
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,'/',PRCDir '; octave --eval \"addpath(''',Parallel(indPC).DynarePath,'''), slaveParallel(',int2str(j),',',int2str(indPC),');\" " &'];
else
command1=['ssh ',Parallel(indPC).user,'@',Parallel(indPC).PcName,' "cd ',Parallel(indPC).RemoteFolder,'/',PRCDir '; ',Parallel(indPC).MatlabPath,' -nosplash -nodesktop -minimize -r \"addpath(''',Parallel(indPC).DynarePath,'''), 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,'\',PRCDir,'\ -a ',int2str(Parallel(indPC).NumCPU(j-nCPU0)), ...
' -low octave --eval "addpath(''',Parallel(indPC).DynarePath,'''), 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,'\',PRCDir,'\ -a ',int2str(Parallel(indPC).NumCPU(j-nCPU0)), ...
' -low ',Parallel(indPC).MatlabPath,' -nosplash -nodesktop -minimize -r "addpath(''',Parallel(indPC).DynarePath,'''), 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,'\',PRCDir,'\ -a ',int2str(Parallel(indPC).NumCPU(j-nCPU0)), ...
' -low octave --eval "addpath(''',Parallel(indPC).DynarePath,'''), slaveParallel(',int2str(j),',',int2str(indPC),')"'];
else
command1=['start /B psexec \\',Parallel(indPC).PcName,' -e -W ',Parallel(indPC).RemoteDrive,':\',Parallel(indPC).RemoteFolder,'\',PRCDir,'\ -a ',int2str(Parallel(indPC).NumCPU(j-nCPU0)), ...
' -low ',Parallel(indPC).MatlabPath,' -nosplash -nodesktop -minimize -r "addpath(''',Parallel(indPC).DynarePath,'''), slaveParallel(',int2str(j),',',int2str(indPC),')"'];
end end
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
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
end
end
end
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 \"addpath(''',Parallel(indPC).DynarePath,'''), fParallel(',int2str(offset+1),',',int2str(sum(nBlockPerCPU(1:j))),',',int2str(j),',',int2str(indPC),',''',fname,''');\" " &'];
else
command1=['ssh ',Parallel(indPC).user,'@',Parallel(indPC).PcName,' "cd ',Parallel(indPC).RemoteFolder, '; ',Parallel(indPC).MatlabPath,' -nosplash -nodesktop -minimize -r \"addpath(''',Parallel(indPC).DynarePath,'''), fParallel(',int2str(offset+1),',',int2str(sum(nBlockPerCPU(1:j))),',',int2str(j),',',int2str(indPC),',''',fname,''');\" " &'];
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 "addpath(''',Parallel(indPC).DynarePath,'''), fParallel(',int2str(offset+1),',',int2str(sum(nBlockPerCPU(1:j))),',',int2str(j),',',int2str(indPC),',''',fname,''')"'];
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 ',Parallel(indPC).MatlabPath,' -nosplash -nodesktop -minimize -r "addpath(''',Parallel(indPC).DynarePath,'''), fParallel(',int2str(offset+1),',',int2str(sum(nBlockPerCPU(1:j))),',',int2str(j),',',int2str(indPC),',''',fname,''')"'];
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 "addpath(''',Parallel(indPC).DynarePath,'''), fParallel(',int2str(offset+1),',',int2str(sum(nBlockPerCPU(1:j))),',',int2str(j),',',int2str(indPC),',''',fname,''')"'];
else
command1=['start /B psexec \\',Parallel(indPC).PcName,' -e -W ',Parallel(indPC).RemoteDrive,':\',Parallel(indPC).RemoteFolder,'\ -a ',int2str(Parallel(indPC).NumCPU(j-nCPU0)), ...
' -low ',Parallel(indPC).MatlabPath,' -nosplash -nodesktop -minimize -r "addpath(''',Parallel(indPC).DynarePath,'''), fParallel(',int2str(offset+1),',',int2str(sum(nBlockPerCPU(1:j))),',',int2str(j),',',int2str(indPC),',''',fname,''')"'];
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 "addpath(''',Parallel(indPC).DynarePath,'''), slaveParallel(',int2str(j),',',int2str(indPC),')" &'];
else
%command1=[Parallel(indPC).MatlabPath,' -nosplash -nodesktop -minimize -r fParallel\(',int2str(offset+1),',',int2str(sum(nBlockPerCPU(1:j))),',',int2str(j),',',int2str(indPC),',\''',fname,'\''\) &'];
command1=[Parallel(indPC).MatlabPath,' -nosplash -nodesktop -minimize -r "addpath(''',Parallel(indPC).DynarePath,'''), 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 "addpath(''',Parallel(indPC).DynarePath,'''), slaveParallel(',int2str(j),',',int2str(indPC),')"'];
else
%command1=['start /B psexec -W ',DyMo, ' -a ',int2str(Parallel(indPC).NumCPU(j-nCPU0)),' -low ',Parallel(indPC).MatlabPath,' -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 ',Parallel(indPC).MatlabPath,' -nosplash -nodesktop -minimize -r "addpath(''',Parallel(indPC).DynarePath,'''), 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 \"addpath(''',Parallel(indPC).DynarePath,'''), slaveParallel(',int2str(j),',',int2str(indPC),');\" " &'];
else
command1=['ssh ',Parallel(indPC).user,'@',Parallel(indPC).PcName,' "cd ',Parallel(indPC).RemoteFolder, '; ',Parallel(indPC).MatlabPath,' -nosplash -nodesktop -minimize -r \"addpath(''',Parallel(indPC).DynarePath,'''), 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 "addpath(''',Parallel(indPC).DynarePath,'''), 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 ',Parallel(indPC).MatlabPath,' -nosplash -nodesktop -minimize -r "addpath(''',Parallel(indPC).DynarePath,'''), 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 "addpath(''',Parallel(indPC).DynarePath,'''), 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 ',Parallel(indPC).MatlabPath,' -nosplash -nodesktop -minimize -r "addpath(''',Parallel(indPC).DynarePath,'''), 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),
@ -418,6 +368,7 @@ else
system('ConcurrentCommand1.bat'); system('ConcurrentCommand1.bat');
end end
% Wait for the slaves to finish their job, and display some progress % Wait for the slaves to finish their job, and display some progress
% information meanwhile. % information meanwhile.
@ -427,92 +378,186 @@ if exist('OCTAVE_VERSION'),
printf('\n'); printf('\n');
else else
hfigstatus = figure('name',['Parallel ',fname],... hfigstatus = figure('name',['Parallel ',fname],...
'MenuBar', 'none', ... 'DockControls','off', ...
'NumberTitle','off'); 'IntegerHandle','off', ...
'Interruptible','off', ...
'MenuBar', 'none', ...
'NumberTitle','off', ...
'Renderer','Painters', ...
'Resize','off');
vspace = 0.1; vspace = 0.1;
ncol = ceil(totCPU/10); ncol = ceil(totCPU/10);
hspace = 0.9/ncol; hspace = 0.9/ncol;
hstatus(1) = axes('position',[0.05/ncol 0.92 0.9/ncol 0.03], ...
'box','on','xtick',[],'ytick',[],'xlim',[0 1],'ylim',[0 1]);
set(hstatus(1),'Units','pixels')
hpixel = get(hstatus(1),'Position');
hfigure = get(hfigstatus,'Position');
hfigure(4)=hpixel(4)*10/3*min(10,totCPU);
set(hfigstatus,'Position',hfigure)
set(hstatus(1),'Units','normalized'),
vspace = max(0.1,1/totCPU);
vstart = 1-vspace+0.2*vspace;
for j=1:totCPU, for j=1:totCPU,
jrow = mod(j-1,10)+1; jrow = mod(j-1,10)+1;
jcol = ceil(j/10); jcol = ceil(j/10);
hstatus(j) = axes('position',[0.05/ncol+(jcol-1)/ncol 0.92-vspace*(jrow-1) 0.9/ncol 0.03], ... hstatus(j) = axes('position',[0.05/ncol+(jcol-1)/ncol vstart-vspace*(jrow-1) 0.9/ncol 0.3*vspace], ...
'box','on','xtick',[],'ytick',[],'xlim',[0 1],'ylim',[0 1]); 'box','on','xtick',[],'ytick',[],'xlim',[0 1],'ylim',[0 1]);
hpat(j) = patch([0 0 0 0],[0 1 1 0],'r','EdgeColor','r');
htit(j) = title(['Initialize ...']);
end end
cumBlockPerCPU = cumsum(nBlockPerCPU); cumBlockPerCPU = cumsum(nBlockPerCPU);
end end
pcerdone = NaN(1,totCPU); pcerdone = NaN(1,totCPU);
while (1) idCPU = NaN(1,totCPU);
delete(['comp_status_',fname,'*.mat']);
ForEver=1;
while (ForEver)
waitbarString = ''; waitbarString = '';
statusString = ''; statusString = '';
pause(1)
stax = dir(['comp_status_',fname,'*.mat']);
for j=1:length(stax),
pause(1)
try
if Parallel(indPC).Local ==0,
dynareParallelGetFiles(['comp_status_',fname,'*.mat'],PRCDir,Parallel(1:totSlaves));
end
catch
end
% stax = dir(['comp_status_',fname,'*.mat']);
for j=1:totCPU, %length(stax),
try try
load(stax(j).name) if ~isempty(['comp_status_',fname,int2str(j),'.mat'])
load(['comp_status_',fname,int2str(j),'.mat']);% (stax(j).name)
end
pcerdone(j) = prtfrc; pcerdone(j) = prtfrc;
idCPU(j) = njob;
if exist('OCTAVE_VERSION'), if exist('OCTAVE_VERSION'),
statusString = [statusString, int2str(j), ' %3.f%% done! ']; statusString = [statusString, int2str(j), ' %3.f%% done! '];
else else
status_String{j} = waitbarString; status_String{j} = waitbarString;
status_Title{j} = waitbarTitle; status_Title{j} = waitbarTitle;
idCPU(j) = njob;
end end
if prtfrc==1, delete(stax(j).name), end % if prtfrc==1, delete(stax(j).name), end
catch catch
if j>1 pcerdone(j) = NaN;
j=j-1 idCPU(j) = NaN;
end % 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), for j=1:totCPU, %length(stax)
for j=1:length(stax)
try try
axes(hstatus(idCPU(j))), set(hpat(j),'XData',[0 0 pcerdone(j) pcerdone(j)]);
hpat = findobj(hstatus(idCPU(j)),'Type','patch'); set(htit(j),'String',[status_Title{j},' - ',status_String{j}]);
if ~isempty(hpat), catch ME
set(hpat,'XData',[0 0 pcerdone(j) pcerdone(j)])
end
end
end
if isempty(dynareParallelDir(['P_',fname,'_*End.txt'],PRCDir,Parallel(1:totSlaves)));
HoTuttiGliOutput=0;
for j=1:totCPU,
if ~isempty(dynareParallelDir([fname,'_output_',int2str(j),'.mat'],PRCDir,Parallel(1:totSlaves)))
HoTuttiGliOutput=HoTuttiGliOutput+1;
end
end
if HoTuttiGliOutput==totCPU,
mydelete(['comp_status_',fname,'*.mat'])
if ~exist('OCTAVE_VERSION'),
close(hfigstatus),
else else
patch([0 0 pcerdone(j) pcerdone(j)],[0 1 1 0],'r','EdgeColor','r') printf('\n');
diary on;
end end
title([status_Title{j},' - ',status_String{j}]);
catch break
if j>1
j=j-1
end
end
end
end
if isempty(dir(['P_',fname,'_*End.txt']))
mydelete(['comp_status_',fname,'*.mat'])
if ~exist('OCTAVE_VERSION'),
close(hfigstatus),
else else
printf('\n'); disp('Waiting for output files from slaves ...')
diary on;
end end
break
end end
end end
dynareParallelGetFiles([fname,'_output_*.mat'],PRCDir,Parallel(1:totSlaves));
% 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']);
if isfield(fOutputVar,'OutputFileName'),
dynareParallelGetFiles([fOutputVar.OutputFileName],PRCDir,Parallel(1:totSlaves));
end
if isfield(fOutputVar,'error'),
disp(['Job number ',int2str(j),'crashed with error:']);
error([fOutputVar.error.message]);
end
fOutVar(j)=fOutputVar; fOutVar(j)=fOutputVar;
end end
% Cleanup. pause(1), % wait for all remote diary off completed
% Cleanup. (Only if the computing is executed remotly).
dynareParallelGetFiles('*.log',PRCDir,Parallel(1:totSlaves));
switch Strategy switch Strategy
case 0 case 0
delete([fname,'_input.mat']) for indPC=1:length(Parallel)
case 1 if Parallel(indPC).Local == 0
delete(['temp_input.mat']) dynareParallelRmDir(PRCDir,Parallel(indPC));
end end
if isempty(dir('dynareParallelLogFiles'))
[A B C]=rmdir('dynareParallelLogFiles');
mkdir('dynareParallelLogFiles');
end
copyfile('*.log','dynareParallelLogFiles');
delete([fname,'*.log']);
%%%%%%%% E' GIUSTO??? %%%%%%%%%%%%%
mydelete(['*_core*_input*.mat']);
if Parallel(indPC).Local == 1
delete(['slaveParallel_input*.mat']);
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
end
delete ConcurrentCommand1.bat delete ConcurrentCommand1.bat
case 1
delete(['temp_input.mat'])
if newInstance,
if isempty(dir('dynareParallelLogFiles'))
[A B C]=rmdir('dynareParallelLogFiles');
mkdir('dynareParallelLogFiles');
end
end
copyfile('*.log','dynareParallelLogFiles');
if newInstance,
delete ConcurrentCommand1.bat
end
end

View File

@ -1,368 +0,0 @@
function [fOutVar,nBlockPerCPU, totCPU] = masterParallelMan(Parallel,fBlock,nBlock,NamFileInput,fname,fInputVar,fGlobalVar)
% Top-level function called on the master computer when parallelizing a task.
% This version has amore sophisticated management of slave processes,
% which are no longer closed at the end of each job
%
% The number of parallelized threads will be equal to (nBlock-fBlock+1).
%
% INPUTS
% Parallel [struct vector] copy of options_.parallel
% fBlock [int] index number of the first thread
% (between 1 and nBlock)
% nBlock [int] index number of the last thread
% NamFileInput [cell array] containins the list of input files to be
% copied in the working directory of remote slaves
% 2 columns, as many lines as there are files
% - first column contains directory paths
% - second column contains filenames
% fname [string] name of the function to be parallelized, and
% which will be run on the slaves
% fInputVar [struct] structure containing local variables to be used
% by fName on the slaves
% fGlobalVar [struct] structure containing global variables to be used
% by fName on the slaves
%
% OUTPUT
% fOutVar [struct vector] result of the parallel computation, one
% struct per thread
% nBlockPerCPU [int vector] for each CPU used, indicates the number of
% threads run on that CPU
% totCPU [int] total number of CPU used (can be lower than
% the number of CPU declared in "Parallel", if
% the number of required threads is lower)
% Copyright (C) 2009-2010 Dynare Team
%
% This file is part of Dynare.
%
% Dynare is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% Dynare is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
% 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;
% Determine my hostname and my working directory
DyMo=pwd;
fInputVar.DyMo=DyMo;
if isunix || (~matlab_ver_less_than('7.4') && ismac) ,
% [tempo, MasterName]=system(['ifconfig | grep ''inet addr:''| grep -v ''127.0.0.1'' | cut -d: -f2 | awk ''{ print $1}''']);
[tempo, MasterName]=system('hostname --fqdn');
else
[tempo, MasterName]=system('hostname');
end
MasterName=deblank(MasterName);
fInputVar.MasterName = MasterName;
% Save input data for use by the slaves
if exist('fGlobalVar'),
save(['temp_input.mat'],'fInputVar','fGlobalVar')
else
save(['temp_input.mat'],'fInputVar')
end
save(['temp_input.mat'],'Parallel','-append')
% Determine the total number of available CPUs, and the number of threads to run on each CPU
for j=1:length(Parallel),
nCPU(j)=length(Parallel(j).NumCPU);
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
mydelete(['comp_status_',fname,'*.mat'])
mydelete(['P_',fname,'*End.txt']);
% Create a shell script containing the commands to launch the required tasks on the slaves
fid = fopen('ConcurrentCommand1.bat','w+');
for j=1:totCPU,
command1 = ' ';
indPC=min(find(nCPU>=j));
if indPC>1
nCPU0 = nCPU(indPC-1);
else
nCPU0=0;
end
offset = sum(nBlockPerCPU(1:j-1))+offset0;
fid1=fopen(['P_',fname,'_',int2str(j),'End.txt'],'w+');
fclose(fid1);
fblck = offset+1;
nblck = sum(nBlockPerCPU(1:j));
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
copyfile(['stayalive',int2str(j),'.txt'], ['\\',Parallel(indPC).PcName,'\',Parallel(indPC).RemoteDrive,'$\',Parallel(indPC).RemoteFolder]);
end
mydelete(['stayalive',int2str(j),'.txt'],'w+');
end
pause(1); % wait for possibly local alive CPU to start the new job or close by internal criteria
newInstance = 0;
if isempty( dir(['P_slave_',int2str(j),'End.txt'])); % check if j CPU is already alive
fid1=fopen(['P_slave_',int2str(j),'End.txt'],'w+');
fclose(fid1);
newInstance = 1;
storeGlobalVars( ['slaveParallel_input',int2str(j)]);
save( ['slaveParallel_input',int2str(j)],'Parallel','-append');
% prepare global vars for Slave
end
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,
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
fprintf(fid,'%s\n',command1);
end
fclose(fid);
% Run the slaves
if isunix || (~matlab_ver_less_than('7.4') && ismac),
system('sh ConcurrentCommand1.bat &');
pause(1)
else
system('ConcurrentCommand1.bat');
end
% Wait for the slaves to finish their job, and display some progress information meanwhile
t0=cputime;
t00=cputime;
hh=NaN(1,nBlock);
if exist('OCTAVE_VERSION'),
diary off;
printf('\n');
else
hfigstatus = figure('name',['Parallel ',fname],...
'MenuBar', 'none', ...
'NumberTitle','off');
vspace = 0.1;
ncol = ceil(totCPU/10);
hspace = 0.9/ncol;
for j=1:totCPU,
jrow = mod(j-1,10)+1;
jcol = ceil(j/10);
hstatus(j) = axes('position',[0.05/ncol+(jcol-1)/ncol 0.92-vspace*(jrow-1) 0.9/ncol 0.03], ...
'box','on','xtick',[],'ytick',[],'xlim',[0 1],'ylim',[0 1]);
end
cumBlockPerCPU = cumsum(nBlockPerCPU);
end
pcerdone = NaN(1,totCPU);
while (1)
waitbarString = '';
statusString = '';
pause(1)
stax = dir(['comp_status_',fname,'*.mat']);
for j=1:length(stax),
try
load(stax(j).name)
pcerdone(j) = prtfrc;
if exist('OCTAVE_VERSION'),
statusString = [statusString, int2str(j), ' %3.f%% done! '];
else
status_String{j} = waitbarString;
status_Title{j} = waitbarTitle;
idCPU(j) = njob;
end
if prtfrc==1, delete(stax(j).name), end
catch
end
end
if exist('OCTAVE_VERSION'),
printf([statusString,'\r'], 100 .* pcerdone);
else
figure(hfigstatus),
try
for j=1:length(stax)
axes(hstatus(idCPU(j))),
hpat = findobj(hstatus(idCPU(j)),'Type','patch');
if ~isempty(hpat),
set(hpat,'XData',[0 0 pcerdone(j) pcerdone(j)])
else
patch([0 0 pcerdone(j) pcerdone(j)],[0 1 1 0],'r','EdgeColor','r')
end
title([status_Title{j},' - ',status_String{j}]);
end
catch
E='ERRORE in while cycle masterParallelMann!'
j
if j>1
j=j-1
end
j
end
end
if isempty(dir(['P_',fname,'_*End.txt']))
mydelete(['comp_status_',fname,'*.mat'])
if ~exist('OCTAVE_VERSION'),
close(hfigstatus),
else
printf('\n');
diary on;
end
break
end
end
% Create return value
for j=1:totCPU,
load([fname,'_output_',int2str(j),'.mat'],'fOutputVar');
delete([fname,'_output_',int2str(j),'.mat']);
fOutVar(j)=fOutputVar;
end
% Cleanup
delete([fname,'_input.mat'])
delete ConcurrentCommand1.bat

View File

@ -126,6 +126,7 @@ while (etime(clock,t0)<1200 && ~isempty(fslave)) || ~isempty(dir(['stayalive',in
fInputVar.Parallel = Parallel; fInputVar.Parallel = Parallel;
% Launch the routine to be run in parallel. % Launch the routine to be run in parallel.
try,
tic, tic,
fOutputVar = feval(fname, fInputVar ,fblck, nblck, whoiam, ThisMatlab); fOutputVar = feval(fname, fInputVar ,fblck, nblck, whoiam, ThisMatlab);
toc, toc,
@ -141,43 +142,35 @@ while (etime(clock,t0)<1200 && ~isempty(fslave)) || ~isempty(dir(['stayalive',in
save([ fname,'_output_',int2str(whoiam),'.mat'],'fOutputVar' ) save([ fname,'_output_',int2str(whoiam),'.mat'],'fOutputVar' )
% Inform the master that the job is finished, and transfer the output data % Inform the master that the job is finished, and transfer the output data
if Parallel(ThisMatlab).Local delete(['P_',fname,'_',int2str(whoiam),'End.txt']);
delete(['P_',fname,'_',int2str(whoiam),'End.txt']);
else
if isunix || (~matlab_ver_less_than('7.4') && ismac),
for j=1:size(OutputFileName,1),
system(['scp ',OutputFileName{j,1},OutputFileName{j,2},' ',Parallel(ThisMatlab).user,'@',fInputVar.MasterName,':',fInputVar.DyMo,'/',OutputFileName{j,1}]);
end
system(['scp ',fname,'_output_',int2str(whoiam),'.mat ',Parallel(ThisMatlab).user,'@',fInputVar.MasterName,':',fInputVar.DyMo]);
system(['ssh ',Parallel(ThisMatlab).user,'@',fInputVar.MasterName,' rm -f ',fInputVar.DyMo,'/P_',fname,'_',int2str(whoiam),'End.txt']);
% system(['fusermount -u ~/MasterRemoteMirror_',fname,'_',int2str(whoiam)]);
% system(['rm -r ~/MasterRemoteMirror_',fname,'_',int2str(whoiam)]);
else
for j=1:size(OutputFileName,1),
copyfile([OutputFileName{j,1},OutputFileName{j,2}],['\\',fInputVar.MasterName,'\',fInputVar.DyMo(1),'$\',fInputVar.DyMo(4:end),'\',OutputFileName{j,1}])
end
copyfile([fname,'_output_',int2str(whoiam),'.mat'],['\\',fInputVar.MasterName,'\',fInputVar.DyMo(1),'$\',fInputVar.DyMo(4:end)]);
delete(['\\',fInputVar.MasterName,'\',fInputVar.DyMo(1),'$\',fInputVar.DyMo(4:end),'\P_',fname,'_',int2str(whoiam),'End.txt']);
end
end
end end
disp(['Job ',fname,' on CPU ',int2str(whoiam),' completed.']) disp(['Job ',fname,' on CPU ',int2str(whoiam),' completed.'])
t0 =clock; % re-set waiting time of 20 mins t0 =clock; % Re-set waiting time of 20 mins
catch ME
disp(['Job ',fname,' on CPU ',int2str(whoiam),' crashed.'])
fOutputVar.error = ME;
save([ fname,'_output_',int2str(whoiam),'.mat'],'fOutputVar' )
waitbarString = fOutputVar.error.message;
if Parallel(ThisMatlab).Local,
waitbarTitle='Local ';
else
waitbarTitle=[Parallel(ThisMatlab).PcName];
end
fMessageStatus(NaN,whoiam,waitbarString, waitbarTitle, Parallel(ThisMatlab));
delete(['P_',fname,'_',int2str(whoiam),'End.txt']);
break
end
end end
fslave = dir( ['slaveParallel_input',int2str(whoiam),'.mat']); % check if Master asks to exit fslave = dir( ['slaveParallel_input',int2str(whoiam),'.mat']); % Check if Master asks to exit
end end
if Parallel(ThisMatlab).Local
delete(['P_slave_',int2str(whoiam),'End.txt']);
else
if isunix || (~matlab_ver_less_than('7.4') && ismac),
system(['ssh ',Parallel(ThisMatlab).user,'@',fInputVar.MasterName,' rm -f ',fInputVar.DyMo,'/P_slave_',int2str(whoiam),'End.txt']);
else
delete(['\\',fInputVar.MasterName,'\',fInputVar.DyMo(1),'$\',fInputVar.DyMo(4:end),'\P_slave_',int2str(whoiam),'End.txt']);
end
end
disp(['slaveParallel on CPU ',int2str(whoiam),' completed.']) disp(['slaveParallel on CPU ',int2str(whoiam),' completed.'])
diary off; diary off;
delete(['P_slave_',int2str(whoiam),'End.txt']);
exit; exit;