1) Renamed options according ti WiKi table;

2) get rid of MasterName and DyMo;
3) more comments;
time-shift
Marco Ratto 2010-10-22 11:27:26 +02:00
parent cab8941c29
commit d8121365dd
27 changed files with 330 additions and 295 deletions

View File

@ -54,8 +54,6 @@ M_=myinputs.M_;
if whoiam if whoiam
Parallel=myinputs.Parallel; Parallel=myinputs.Parallel;
MasterName=myinputs.MasterName;
DyMo=myinputs.DyMo;
end end
if ~exist('MhDirectoryName'), if ~exist('MhDirectoryName'),
MhDirectoryName = CheckPath('metropolis'); MhDirectoryName = CheckPath('metropolis');
@ -70,9 +68,9 @@ if whoiam
if Parallel(ThisMatlab).Local, if Parallel(ThisMatlab).Local,
waitbarTitle=['Local ']; waitbarTitle=['Local '];
else else
waitbarTitle=[Parallel(ThisMatlab).PcName]; waitbarTitle=[Parallel(ThisMatlab).ComputerName];
end end
fMessageStatus(0,whoiam,waitbarString, waitbarTitle, Parallel(ThisMatlab), MasterName, DyMo); fMessageStatus(0,whoiam,waitbarString, waitbarTitle, Parallel(ThisMatlab));
end end
for j=fpar:npar, for j=fpar:npar,
fprintf(' Parameter %d... ',j); fprintf(' Parameter %d... ',j);
@ -121,7 +119,7 @@ for j=fpar:npar,
fprintf('Done! \n'); fprintf('Done! \n');
if whoiam, if whoiam,
waitbarString = [ 'Parameter ' int2str(j) '/' int2str(npar) ' done.']; waitbarString = [ 'Parameter ' int2str(j) '/' int2str(npar) ' done.'];
fMessageStatus((j-fpar+1)/(npar-fpar+1),whoiam,waitbarString, waitbarTitle, Parallel(ThisMatlab), MasterName, DyMo) fMessageStatus((j-fpar+1)/(npar-fpar+1),whoiam,waitbarString, waitbarTitle, Parallel(ThisMatlab))
end end
end end

View File

@ -195,7 +195,7 @@ localVars.NumberOfIRFfiles_dsgevar=NumberOfIRFfiles_dsgevar;
localVars.ifil2=ifil2; localVars.ifil2=ifil2;
% Like sequential execution! % Like sequential execution!
if isnumeric(options_.parallel),% | isunix, % For the moment exclude unix platform from parallel implementation. if isnumeric(options_.parallel),
[fout] = PosteriorIRF_core1(localVars,1,B,0); [fout] = PosteriorIRF_core1(localVars,1,B,0);
else else
% Parallel execution! % Parallel execution!
@ -424,9 +424,9 @@ end
% The others file format are generated in parallel by PosteriorIRF_core2! % The others file format are generated in parallel by PosteriorIRF_core2!
% Comment for testing! % Comment for testing!
if ~exist('OCTAVE_VERSION') if ~exist('OCTAVE_VERSION')
if isnumeric(options_.parallel) % || (M_.exo_nbr*ceil(size(varlist,1)/MaxNumberOfPlotPerFigure))<8,% | isunix, % for the moment exclude unix platform from parallel implementation if isnumeric(options_.parallel) || (M_.exo_nbr*ceil(size(varlist,1)/MaxNumberOfPlotPerFigure))<8,
[fout] = PosteriorIRF_core2(localVars,1,M_.exo_nbr,0); [fout] = PosteriorIRF_core2(localVars,1,M_.exo_nbr,0);
else else
globalVars = struct('M_',M_, ... globalVars = struct('M_',M_, ...

View File

@ -49,7 +49,6 @@ end
% Reshape 'myinputs' for local computation. % Reshape 'myinputs' for local computation.
% In order to avoid confusion in the name space, the instruction struct2local(myinputs) is replaced by: % In order to avoid confusion in the name space, the instruction struct2local(myinputs) is replaced by:
% Da CONTROLLARE con MARCO!
IRUN = myinputs.IRUN; IRUN = myinputs.IRUN;
irun =myinputs.irun; irun =myinputs.irun;
irun2=myinputs.irun2; irun2=myinputs.irun2;
@ -77,12 +76,9 @@ MAX_nruns=myinputs.MAX_nruns;
NumberOfIRFfiles_dsge=myinputs.NumberOfIRFfiles_dsge; NumberOfIRFfiles_dsge=myinputs.NumberOfIRFfiles_dsge;
NumberOfIRFfiles_dsgevar=myinputs.NumberOfIRFfiles_dsgevar; NumberOfIRFfiles_dsgevar=myinputs.NumberOfIRFfiles_dsgevar;
ifil2=myinputs.ifil2; ifil2=myinputs.ifil2;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if whoiam if whoiam
Parallel=myinputs.Parallel; Parallel=myinputs.Parallel;
MasterName=myinputs.MasterName;
DyMo=myinputs.DyMo;
end end
@ -95,10 +91,10 @@ if whoiam
if Parallel(ThisMatlab).Local, if Parallel(ThisMatlab).Local,
waitbarTitle=['Local ']; waitbarTitle=['Local '];
else else
waitbarTitle=[Parallel(ThisMatlab).PcName]; waitbarTitle=[Parallel(ThisMatlab).ComputerName];
RemoteFlag =1; RemoteFlag =1;
end end
fMessageStatus(0,whoiam,waitbarString, waitbarTitle, Parallel(ThisMatlab), MasterName, DyMo); fMessageStatus(0,whoiam,waitbarString, waitbarTitle, Parallel(ThisMatlab));
else else
if exist('OCTAVE_VERSION') if exist('OCTAVE_VERSION')
diary off; diary off;
@ -130,7 +126,9 @@ if whoiam
NumberOfIRFfiles_dsgevar=NumberOfIRFfiles_dsgevar(whoiam); NumberOfIRFfiles_dsgevar=NumberOfIRFfiles_dsgevar(whoiam);
end end
while fpar<npar % Parallel 'while'!!! % Parallel 'while' very good!!!
while fpar<npar
fpar = fpar + 1; fpar = fpar + 1;
irun = irun+1; irun = irun+1;
irun2 = irun2+1; irun2 = irun2+1;
@ -273,11 +271,10 @@ while fpar<npar % Parallel 'while'!!!
elseif ~whoiam elseif ~whoiam
waitbar(fpar/npar,h); waitbar(fpar/npar,h);
end end
% if mod(fpar,10)==0 & whoiam,
if whoiam, if whoiam,
fprintf('Done! \n'); fprintf('Done! \n');
waitbarString = [ 'Subdraw ' int2str(fpar) '/' int2str(npar) ' done.']; waitbarString = [ 'Subdraw ' int2str(fpar) '/' int2str(npar) ' done.'];
fMessageStatus((fpar-fpar0)/(npar-fpar0),whoiam,waitbarString, waitbarTitle, Parallel(ThisMatlab), MasterName, DyMo); fMessageStatus((fpar-fpar0)/(npar-fpar0),whoiam,waitbarString, waitbarTitle, Parallel(ThisMatlab));
end end
end end

View File

@ -65,8 +65,6 @@ MaxNumberOfPlotPerFigure=myinputs.MaxNumberOfPlotPerFigure;
% Necessary only for remote computing! % Necessary only for remote computing!
if whoiam if whoiam
Parallel=myinputs.Parallel; Parallel=myinputs.Parallel;
MasterName=myinputs.MasterName;
DyMo=myinputs.DyMo;
end end
% To save the figures where the function is computed! % To save the figures where the function is computed!
@ -79,10 +77,10 @@ if whoiam,
if Parallel(ThisMatlab).Local, if Parallel(ThisMatlab).Local,
waitbarTitle=['Local ']; waitbarTitle=['Local '];
else else
waitbarTitle=[Parallel(ThisMatlab).PcName]; waitbarTitle=[Parallel(ThisMatlab).ComputerName];
RemoteFlag = 1; RemoteFlag = 1;
end end
fMessageStatus(0,whoiam,waitbarString, waitbarTitle, Parallel(ThisMatlab), MasterName, DyMo); fMessageStatus(0,whoiam,waitbarString, waitbarTitle, Parallel(ThisMatlab));
end end
OutputFileName={}; OutputFileName={};
@ -164,7 +162,7 @@ for i=fpar:npar,
if whoiam, if whoiam,
fprintf('Done! \n'); fprintf('Done! \n');
waitbarString = [ 'Exog. shocks ' int2str(i) '/' int2str(npar) ' done.']; waitbarString = [ 'Exog. shocks ' int2str(i) '/' int2str(npar) ' done.'];
fMessageStatus((i-fpar+1)/(npar-fpar+1),whoiam,waitbarString, waitbarTitle, Parallel(ThisMatlab), MasterName, DyMo); fMessageStatus((i-fpar+1)/(npar-fpar+1),whoiam,waitbarString, waitbarTitle, Parallel(ThisMatlab));
end end
end% loop over exo_var end% loop over exo_var

View File

@ -63,8 +63,6 @@ varargin=myinputs.varargin;
if whoiam if whoiam
Parallel=myinputs.Parallel; Parallel=myinputs.Parallel;
MasterName=myinputs.MasterName;
DyMo=myinputs.DyMo;
% initialize persistent variables in priordens() % initialize persistent variables in priordens()
priordens(xparam1,bayestopt_.pshape,bayestopt_.p6,bayestopt_.p7, ... priordens(xparam1,bayestopt_.pshape,bayestopt_.p6,bayestopt_.p7, ...
bayestopt_.p3,bayestopt_.p4,1); bayestopt_.p3,bayestopt_.p4,1);
@ -121,13 +119,13 @@ for b = fblck:nblck,
elseif whoiam elseif whoiam
% keyboard; % keyboard;
waitbarString = ['Please wait... Metropolis-Hastings (' int2str(b) '/' int2str(options_.mh_nblck) ')...']; waitbarString = ['Please wait... Metropolis-Hastings (' int2str(b) '/' int2str(options_.mh_nblck) ')...'];
% waitbarTitle=['Metropolis-Hastings ',options_.parallel(ThisMatlab).PcName]; % waitbarTitle=['Metropolis-Hastings ',options_.parallel(ThisMatlab).ComputerName];
if options_.parallel(ThisMatlab).Local, if options_.parallel(ThisMatlab).Local,
waitbarTitle=['Local ']; waitbarTitle=['Local '];
else else
waitbarTitle=[options_.parallel(ThisMatlab).PcName]; waitbarTitle=[options_.parallel(ThisMatlab).ComputerName];
end end
fMessageStatus(0,whoiam,waitbarString, waitbarTitle, options_.parallel(ThisMatlab), MasterName, DyMo); fMessageStatus(0,whoiam,waitbarString, waitbarTitle, options_.parallel(ThisMatlab));
else, else,
hh = waitbar(0,['Please wait... Metropolis-Hastings (' int2str(b) '/' int2str(options_.mh_nblck) ')...']); hh = waitbar(0,['Please wait... Metropolis-Hastings (' int2str(b) '/' int2str(options_.mh_nblck) ')...']);
set(hh,'Name','Metropolis-Hastings'); set(hh,'Name','Metropolis-Hastings');
@ -138,7 +136,7 @@ for b = fblck:nblck,
irun = fline(b); irun = fline(b);
j = 1; j = 1;
while j <= nruns(b) while j <= nruns(b)
par = feval(ProposalFun, xparam1, d * jscale, n); par = feval(ProposalFun, xparam1, proposal_covariance, n);
if all( par(:) > mh_bounds(:,1) ) & all( par(:) < mh_bounds(:,2) ) if all( par(:) > mh_bounds(:,1) ) & all( par(:) < mh_bounds(:,2) )
try try
logpost = - feval(TargetFun, par(:),varargin{:}); logpost = - feval(TargetFun, par(:),varargin{:});
@ -149,8 +147,8 @@ for b = fblck:nblck,
logpost = -inf; logpost = -inf;
end end
r = logpost - ilogpo2(b) + ... r = logpost - ilogpo2(b) + ...
log(feval(ProposalDensity, ix2(b,:), xparam1, d * jscale, n)) - ... log(feval(ProposalDensity, ix2(b,:), xparam1, proposal_covariance, n)) - ...
log(feval(ProposalDensity, par, xparam1, d * jscale, n)); log(feval(ProposalDensity, par, xparam1, proposal_covariance, n));
if (logpost > -inf) && (log(rand) < r) if (logpost > -inf) && (log(rand) < r)
x2(irun,:) = par; x2(irun,:) = par;
ix2(b,:) = par; ix2(b,:) = par;
@ -174,7 +172,7 @@ for b = fblck:nblck,
if mod(j,50)==0 & whoiam, if mod(j,50)==0 & whoiam,
% keyboard; % keyboard;
waitbarString = [ '(' int2str(b) '/' int2str(options_.mh_nblck) '), ' sprintf('accept. %3.f%%%%', 100 * isux/j)]; waitbarString = [ '(' int2str(b) '/' int2str(options_.mh_nblck) '), ' sprintf('accept. %3.f%%%%', 100 * isux/j)];
fMessageStatus(prtfrc,whoiam,waitbarString, '', options_.parallel(ThisMatlab), MasterName, DyMo) fMessageStatus(prtfrc,whoiam,waitbarString, '', options_.parallel(ThisMatlab))
end end
else else
if mod(j, 3)==0 & ~whoiam if mod(j, 3)==0 & ~whoiam
@ -182,7 +180,7 @@ for b = fblck:nblck,
elseif mod(j,50)==0 & whoiam, elseif mod(j,50)==0 & whoiam,
% keyboard; % keyboard;
waitbarString = [ '(' int2str(b) '/' int2str(options_.mh_nblck) ') ' sprintf('%f done, acceptation rate %f',prtfrc,isux/j)]; waitbarString = [ '(' int2str(b) '/' int2str(options_.mh_nblck) ') ' sprintf('%f done, acceptation rate %f',prtfrc,isux/j)];
fMessageStatus(prtfrc,whoiam,waitbarString, waitbarTitle, options_.parallel(ThisMatlab), MasterName, DyMo) fMessageStatus(prtfrc,whoiam,waitbarString, waitbarTitle, options_.parallel(ThisMatlab))
end end
end end

View File

@ -1,5 +1,6 @@
function [ErrorCode] = AnalyseComputationalEnviroment(DataInput) function [ErrorCode] = AnalyseComputationalEnviroment(DataInput)
% PARALLEL CONTEXT % PARALLEL CONTEXT
% In a parallel context, this function is used to check the user computational request. % In a parallel context, this function is used to check the user computational request.
% If no error happen the function return 0. % If no error happen the function return 0.
@ -9,19 +10,21 @@ function [ErrorCode] = AnalyseComputationalEnviroment(DataInput)
% DataInput is the strcture option_.parallel, with the follow fields: % DataInput is the strcture option_.parallel, with the follow fields:
% %
% Local Define the computation place: 1 is on local machine, 0 remote % Local Define the computation place: 1 is on local machine, 0 remote
% PcName Intuitive: contain the computer name. % ComputerName Intuitive: contain the computer name.
% NumCPU Intuitive: contain the CPU number. % CPUnbr Intuitive: contain the CPU number.
% user Intuitive: contain the use name for the PcName. % UserName Intuitive: contain the use name for the ComputerName.
% passwd Intuitive: contain the password for the user name in PcName. % passwd Intuitive: contain the password for the user name in ComputerName.
% RemoteDrive Drive used for Local/Remote computation (data exchange, etc) must be contain 'RemoteFolder'. % RemoteDrive Drive used for Local/Remote computation (data exchange, etc) must be contain 'RemoteFolder'.
% RemoteFolder Folder in RemoteDrive used for Local/Remote computation. % RemoteDirectory Folder in RemoteDrive used for Local/Remote computation.
% MatlabOctavePath []
% DynarePath []
% %
% This information is typed by the user using the *.mod file, % This information is typed by the user using the *.mod file,
% the goal of this function is to check if it correct. % the goal of this function is to check if it correct.
% %
% %
% The variable ErrorCode is initialized at 0. If there are non problems with % The variable ErrorCode is initialized at 0. If there are non problems with
% Local, PcName connections,... in general with parallel software execution, % Local, ComputerName connections,... in general with parallel software execution,
% the ErrorCode is unchanged, in the others cases 1, 2 , ... The values % the ErrorCode is unchanged, in the others cases 1, 2 , ... The values
% table is below. % table is below.
% %
@ -34,7 +37,7 @@ function [ErrorCode] = AnalyseComputationalEnviroment(DataInput)
% %
% Value 1: The variable 'Local' has a bad value! % Value 1: The variable 'Local' has a bad value!
% %
% Value 2: The variable 'NumCPU' has a bad value. Parallel Dynare % Value 2: The variable 'CPUnbr' has a bad value. Parallel Dynare
% require an input data like [s:d] with s<=d, in this case we % require an input data like [s:d] with s<=d, in this case we
% have s>d! % have s>d!
% 2.1 The user asks to use more CPU of those available. % 2.1 The user asks to use more CPU of those available.
@ -91,14 +94,14 @@ end
%%%%%%%%%% Local Machine %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%% Local Machine %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% In this case we need to check only the variable 'NumCPU'. % In this case we need to check only the variable 'CPUnbr'.
% We run the parallel code on local computer, so the others fields are automatically % We run the parallel code on local computer, so the others fields are automatically
% fixed by Dynare. Then the user can also fill them with wrong values. % fixed by Dynare. Then the user can also fill them with wrong values.
if (DataInput.Local == 1) if (DataInput.Local == 1)
yn=isempty(DataInput.NumCPU); yn=isempty(DataInput.CPUnbr);
if yn==1 if yn==1
ErrorCode=2; ErrorCode=2;
@ -112,23 +115,23 @@ if (DataInput.Local == 1)
[si0 de0]=system(['psinfo \\']); [si0 de0]=system(['psinfo \\']);
RealNumCPU=-1; RealCPUnbr=-1;
RealNumCPU=GiveCPUnumber(de0); RealCPUnbr=GiveCPUnumber(de0);
% Trasforming the input data provided in a form [n1:n2] in a single numerical % Trasforming the input data provided in a form [n1:n2] in a single numerical
% value. % value.
DataInput.NumCPU=length(DataInput.NumCPU); DataInput.CPUnbr=length(DataInput.CPUnbr);
if DataInput.NumCPU == RealNumCPU if DataInput.CPUnbr == RealCPUnbr
% It is Ok! % It is Ok!
end end
if DataInput.NumCPU > RealNumCPU if DataInput.CPUnbr > RealCPUnbr
ErrorCode=2.1; ErrorCode=2.1;
end end
if DataInput.NumCPU < RealNumCPU if DataInput.CPUnbr < RealCPUnbr
ErrorCode=2.2; ErrorCode=2.2;
end end
end end
@ -143,7 +146,7 @@ if (DataInput.Local == 0)
si1=[]; si1=[];
de1=[]; de1=[];
[si1 de1]=system(['ping ', DataInput.PcName]); [si1 de1]=system(['ping ', DataInput.ComputerName]);
if si1==1 if si1==1
% It is impossiblie to be connected to the % It is impossiblie to be connected to the
@ -160,7 +163,7 @@ if (DataInput.Local == 0)
% possible to exchange data with them. % possible to exchange data with them.
if (isempty(DataInput.user)) || (isempty(DataInput.passwd)) if (isempty(DataInput.UserName)) || (isempty(DataInput.Password))
% The fields user name and/or password are/is empty! % The fields user name and/or password are/is empty!
@ -170,13 +173,21 @@ if (DataInput.Local == 0)
end end
% Now we very if RemoteDrive and/or RemoteFolder exist on remote % Now we very if RemoteDrive and/or RemoteDirectory exist on remote
% computer % computer
StartPwd=pwd; StartPwd=pwd;
if (isempty(DataInput.RemoteDirectory))
disp 'Remote Drive and/or Remote Folder not exist!';
ErrorCode=5;
return
end
try try
cd(['\\',DataInput.PcName,'\',DataInput.RemoteDrive,'$\',DataInput.RemoteFolder]); cd(['\\',DataInput.ComputerName,'\',DataInput.RemoteDrive,'$\',DataInput.RemoteDirectory]);
catch catch
cd ([StartPwd]); cd ([StartPwd]);
@ -187,18 +198,28 @@ if (DataInput.Local == 0)
end end
cd ([StartPwd]); cd ([StartPwd]);
% Now we verify if it possible to exchange data with the remote % Now we verify if it possible to exchange data with the remote
% computer: % computer:
fT = fopen('WriteTest.txt', 'w+');
fclose(fT);
Status=copyfile('WriteTest.txt', ['\\',DataInput.ComputerName,'\',DataInput.RemoteDrive,'$\',DataInput.RemoteDirectory]);
Status=copyfile('Tracing.m', ['\\',DataInput.PcName,'\',DataInput.RemoteDrive,'$\',DataInput.RemoteFolder]);
if Status==1 if Status==1
% Remote Drive/Folder exist on Remote computer and % Remote Drive/Folder exist on Remote computer and
% it is possible to exchange data with him. % it is possible to exchange data with him.
%Delete Traces (local and remotely)
delete ('WriteTest.txt')
delete(['\\',DataInput.ComputerName,'\',DataInput.RemoteDrive,'$\',DataInput.RemoteDirectory,'\WriteTest.txt']);
else else
ErrorCode=6; ErrorCode=6;
@ -207,12 +228,12 @@ if (DataInput.Local == 0)
% Now we verify if it is possible execute a matlab section on remote % Now we verify if it is possible execute a matlab section on remote
% machine when the user is .user with password .passwd % machine when the user is .UserName with password .Password
si2=[]; si2=[];
de2=[]; de2=[];
[si2 de2]=system(['start /B /WAIT psexec \\',DataInput.PcName,' -e -u ',DataInput.user,' -p ',DataInput.passwd,' -W ',DataInput.RemoteDrive,':\',DataInput.RemoteFolder, ' -low matlab -nosplash -nodesktop -minimize -r Tracing']); [si2 de2]=system(['start /B /WAIT psexec \\',DataInput.ComputerName,' -e -u ',DataInput.UserName,' -p ',DataInput.Password,' -W ',DataInput.RemoteDrive,':\',DataInput.RemoteDirectory, ' -low matlab -nosplash -nodesktop -minimize -r Tracing']);
NoError='error code 0'; NoError='error code 0';
@ -228,34 +249,34 @@ if (DataInput.Local == 0)
else else
% No error it is possible execute a matlab section on remote % No error it is possible execute a matlab section on remote
% machine when the user is .user with password .passwd % machine when the user is .UserName with password .Password
end end
% At this point we can to analyze the remote computer hardware. % At this point we can to analyze the remote computer hardware.
RealNumCPU=-1; RealCPUnbr=-1;
[si0 de0]=system(['psinfo \\']); [si0 de0]=system(['psinfo \\']);
RealNumCPU=GiveCPUnumber(de0); RealCPUnbr=GiveCPUnumber(de0);
% Trasforming the input data provided in a form [n1:n2] in a single numerical % Trasforming the input data provided in a form [n1:n2] in a single numerical
% value. % value.
DataInput.NumCPU=length(DataInput.NumCPU); DataInput.CPUnbr=length(DataInput.CPUnbr);
if DataInput.NumCPU == RealNumCPU if DataInput.CPUnbr == RealCPUnbr
% It is Ok! % It is Ok!
end end
if DataInput.NumCPU > RealNumCPU if DataInput.CPUnbr > RealCPUnbr
ErrorCode=2.1; ErrorCode=2.1;
end end
if DataInput.NumCPU < RealNumCPU if DataInput.CPUnbr < RealCPUnbr
ErrorCode=2.2; ErrorCode=2.2;
end end

View File

@ -1,11 +1,12 @@
function [TiSt] = CreateTimeString() function [TiSt] = CreateTimeString()
% PARALLEL CONTEXT % PARALLEL CONTEXT
% In a parallel context, this is ... % In a parallel context, this is a specialized version of clock() function.
%
%
% INPUT/OUTPUT description:
% %
% INPUTS
% None
% %
% OUTPUTS
% o TiSt [] ...
% %
% Copyright (C) 2009-2010 Dynare Team % Copyright (C) 2009-2010 Dynare Team
% %

View File

@ -1,26 +1,15 @@
function [ErrorCode] = InitializeComputationalEnviroment(DataInput) function InitializeComputationalEnviroment(DataInput)
% PARALLEL CONTEXT % PARALLEL CONTEXT
% In a parallel context, this function is used to Initialize the computational enviroment according with % In a parallel context, this function is used to Initialize the computational enviroment according with
% the user request. % the user request.
% If no error happen the function return 0.
% %
% INPUT/OUTPUT description: % INPUTS
% o DataInput [] ...
% %
% OUTPUTS
% None
% %
%
%
% The variable ErrorCode is initialized at 0. If there are non problems
% the ErrorCode is unchanged, in the others cases is set equak to 1, 2 , ... The values
% table is below.
%
%
% Table for ErrorCode Values.
%
%
% Then at the point call of this function it is possible react in a best way, in accord
% with the ErrorCode.
% Copyright (C) 2009-2010 Dynare Team % Copyright (C) 2009-2010 Dynare Team
% %
% This file is part of Dynare. % This file is part of Dynare.
@ -38,13 +27,13 @@ function [ErrorCode] = InitializeComputationalEnviroment(DataInput)
% 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/>.
ErrorCode=0;
% Invoke masterParallel with 8 arguments and the last equal to 1. With this shape % Invoke masterParallel with 8 arguments and the last equal to 1. With this shape
% for input data, masterParallel only create a new directory for remote % for input data, masterParallel only create a new directory for remote
% computation. The name of this directory is time depending. For local % computation. The name of this directory is time depending. For local
% parallel computations with Strategy == 1 delete the traces (if exists) of % parallel computations with Strategy == 1 delete the traces (if exists) of
% previous computations. % previous computations.
delete(['P_slave_*End.txt']) delete(['P_slave_*End.txt'])
masterParallel(DataInput.parallel,[],[],[],[],[],[],DataInput.parallel_info,1); masterParallel(DataInput.parallel,[],[],[],[],[],[],DataInput.parallel_info,1);

View File

@ -1,11 +1,16 @@
function closeSlave(Parallel,TmpFolder), 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 when strategy (1) is active i.e. always open (which leaves
% open remote matlab instances). % open remote matlab instances).
% %
% INPUTS % INPUTS
% o Parallel [struct vector] copy of options_.parallel. % o Parallel [struct vector] copy of options_.parallel.
% o TmpFolder string if islocal==0, is the name of didectory devoted to remote computation.
% This directory is named using current date
% and is used only one time and then deleted.
% If islocal==1, TmpFolder=''.
%
% %
% OUTPUTS % OUTPUTS
% None % None
@ -27,15 +32,17 @@ function closeSlave(Parallel,TmpFolder),
% 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/>.
for indPC=1:length(Parallel), for indPC=1:length(Parallel),
if (Parallel(indPC).Local==0), if (Parallel(indPC).Local==0),
dynareParallelDelete( 'slaveParallel_input*.mat',TmpFolder,Parallel(indPC)); dynareParallelDelete( 'slaveParallel_input*.mat',TmpFolder,Parallel(indPC));
else end
%else
delete( 'slaveParallel_input*.mat'); delete( 'slaveParallel_input*.mat');
pause(1) pause(1)
delete(['slaveParallel_*.log']); delete(['slaveParallel_*.log']);
%end
end delete ConcurrentCommand1.bat;
end end
while(1) while(1)

View File

@ -14,8 +14,8 @@ function [nCPU, totCPU, nBlockPerCPU, totSLAVES] = distributeJobs(Parallel, fBlo
% threads run on that CPU % threads run on that CPU
% o 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!)
% o nCPU he number of CPU in user format. % o nCPU the number of CPU in user format.
% Copyright (C) 2010 Dynare Team % Copyright (C) 2010 Dynare Team
% %
@ -36,7 +36,7 @@ function [nCPU, totCPU, nBlockPerCPU, totSLAVES] = distributeJobs(Parallel, fBlo
totCPU=0; totCPU=0;
for j=1:length(Parallel), for j=1:length(Parallel),
nCPU(j)=length(Parallel(j).NumCPU); nCPU(j)=length(Parallel(j).CPUnbr);
totCPU=totCPU+nCPU(j); totCPU=totCPU+nCPU(j);
end end

View File

@ -2,10 +2,13 @@ function dynareParallelDelete(fname,pname,Parallel)
% PARALLEL CONTEXT % PARALLEL CONTEXT
% In a parallel context, this is a specialized version of delete() function. % In a parallel context, this is a specialized version of delete() function.
% %
% INPUTS
% o fname [] ...
% o pname [] ...
% o Parallel [] ...
% %
% INPUT/OUTPUT description: % OUTPUTS
% % None
%
% %
% %
% Copyright (C) 2009-2010 Dynare Team % Copyright (C) 2009-2010 Dynare Team
@ -38,9 +41,9 @@ end
for indPC=1:length(Parallel), for indPC=1:length(Parallel),
if isunix if isunix
system(['ssh ',Parallel(indPC).user,'@',Parallel(indPC).PcName,' rm -f ',Parallel(indPC).RemoteFolder,'/',pname,fname]); system(['ssh ',Parallel(indPC).UserName,'@',Parallel(indPC).ComputerName,' rm -f ',Parallel(indPC).RemoteDirectory,'/',pname,fname]);
else else
delete(['\\',Parallel(indPC).PcName,'\',Parallel(indPC).RemoteDrive,'$\',Parallel(indPC).RemoteFolder,'\',pname,fname]); delete(['\\',Parallel(indPC).ComputerName,'\',Parallel(indPC).RemoteDrive,'$\',Parallel(indPC).RemoteDirectory,'\',pname,fname]);
end end
end end

View File

@ -1,11 +1,14 @@
function dirlist = dynareParallelDir(filename,PRCDir,Parallel) function dirlist = dynareParallelDir(filename,PRCDir,Parallel)
% PARALLEL CONTEXT % PARALLEL CONTEXT
% In a parallel context, this is ... % In a parallel context, this is a specialized version of dir() function.
%
%
% INPUT/OUTPUT description:
% %
% INPUTS
% o filename [] ...
% o PRCDir [] ...
% o Parallel [] ...
% %
% OUTPUTS
% o dirlist [] ...
% %
% Copyright (C) 2009-2010 Dynare Team % Copyright (C) 2009-2010 Dynare Team
% %
@ -28,7 +31,7 @@ dirlist=[];
for indPC=1:length(Parallel), for indPC=1:length(Parallel),
if isunix || (~matlab_ver_less_than('7.4') && ismac), if isunix || (~matlab_ver_less_than('7.4') && ismac),
if Parallel(indPC).Local==0, if Parallel(indPC).Local==0,
[check, ax]=system(['ssh ',Parallel(indPC).user,'@',Parallel(indPC).PcName,' ls ',Parallel(indPC).RemoteFolder,'/',PRCDir,'/',filename]); [check, ax]=system(['ssh ',Parallel(indPC).UserName,'@',Parallel(indPC).ComputerName,' ls ',Parallel(indPC).RemoteDirectory,'/',PRCDir,'/',filename]);
if check ~ 0 if check ~ 0
ax=[]; ax=[];
end end
@ -43,7 +46,7 @@ for indPC=1:length(Parallel),
dirlist = [dirlist, ax]; dirlist = [dirlist, ax];
else else
if Parallel(indPC).Local==0, if Parallel(indPC).Local==0,
ax=ls(['\\',Parallel(indPC).PcName,'\',Parallel(indPC).RemoteDrive,'$\',Parallel(indPC).RemoteFolder,'\',PRCDir,'\',filename]); ax=ls(['\\',Parallel(indPC).ComputerName,'\',Parallel(indPC).RemoteDrive,'$\',Parallel(indPC).RemoteDirectory,'\',PRCDir,'\',filename]);
else else
ax=ls(filename); ax=ls(filename);
end end

View File

@ -1,9 +1,16 @@
function dynareParallelGetFiles(NamFileInput,PRCDir,Parallel) function dynareParallelGetFiles(NamFileInput,PRCDir,Parallel)
% PARALLEL CONTEXT % PARALLEL CONTEXT
% In a parallel context, this is ... % In a parallel context, this is a specialized mono-directional (Remote to Local) version of copy()
% function.
% %
% %
% INPUT/OUTPUT description: % INPUTS
% o NamFileInput [] ...
% o PRCDir [] ...
% o Parallel [] ...
%
% OUTPUTS
% None
% %
% %
% %
@ -37,13 +44,13 @@ for indPC=1:length(Parallel),
if isunix || (~matlab_ver_less_than('7.4') && ismac), if isunix || (~matlab_ver_less_than('7.4') && ismac),
for jfil=1:size(NamFileInput,1), for jfil=1:size(NamFileInput,1),
% if ~isempty(dynareParallelDir(NamFileInput{jfil,2},[PRCDir,filesep,NamFileInput{jfil,1}],Parallel(indPC))), % if ~isempty(dynareParallelDir(NamFileInput{jfil,2},[PRCDir,filesep,NamFileInput{jfil,1}],Parallel(indPC))),
system(['scp ',Parallel(indPC).user,'@',Parallel(indPC).PcName,':',Parallel(indPC).RemoteFolder,'/',PRCDir,'/',NamFileInput{jfil,1},NamFileInput{jfil,2},' ',NamFileInput{jfil,1}]); system(['scp ',Parallel(indPC).UserName,'@',Parallel(indPC).ComputerName,':',Parallel(indPC).RemoteDirectory,'/',PRCDir,'/',NamFileInput{jfil,1},NamFileInput{jfil,2},' ',NamFileInput{jfil,1}]);
% end % end
end end
else else
for jfil=1:size(NamFileInput,1), for jfil=1:size(NamFileInput,1),
if ~isempty(dynareParallelDir(NamFileInput{jfil,2},[PRCDir,filesep,NamFileInput{jfil,1}],Parallel(indPC))), if ~isempty(dynareParallelDir(NamFileInput{jfil,2},[PRCDir,filesep,NamFileInput{jfil,1}],Parallel(indPC))),
copyfile(['\\',Parallel(indPC).PcName,'\',Parallel(indPC).RemoteDrive,'$\',Parallel(indPC).RemoteFolder,'\',PRCDir,'\',NamFileInput{jfil,1},NamFileInput{jfil,2}],NamFileInput{jfil,1}) copyfile(['\\',Parallel(indPC).ComputerName,'\',Parallel(indPC).RemoteDrive,'$\',Parallel(indPC).RemoteDirectory,'\',PRCDir,'\',NamFileInput{jfil,1},NamFileInput{jfil,2}],NamFileInput{jfil,1})
end end
end end
end end

View File

@ -2,16 +2,14 @@ function dynareParallelMkDir(PRCDir,Parallel)
% PARALLEL CONTEXT % PARALLEL CONTEXT
% In a parallel context, this is a specialized version of rmdir() function. % In a parallel context, this is a specialized version of rmdir() function.
% %
% INPUTS
% o PRCDir [] ...
% o Parallel [] ...
% %
% INPUT/OUTPUT description: % OUTPUTS
% None
% %
% %
%
%
%
% Then at the point call of this function it is possible react in a best way, in accord
% with the ErrorCode.
% Copyright (C) 2009-2010 Dynare Team % Copyright (C) 2009-2010 Dynare Team
% %
% This file is part of Dynare. % This file is part of Dynare.
@ -39,9 +37,9 @@ end
for indPC=1:length(Parallel) for indPC=1:length(Parallel)
if Parallel(indPC).Local==0, if Parallel(indPC).Local==0,
if isunix || (~matlab_ver_less_than('7.4') && ismac), if isunix || (~matlab_ver_less_than('7.4') && ismac),
system(['ssh ',Parallel(indPC).user,'@',Parallel(indPC).PcName,' mkdir -p ',Parallel(indPC).RemoteFolder,'/',PRCDir]) system(['ssh ',Parallel(indPC).UserName,'@',Parallel(indPC).ComputerName,' mkdir -p ',Parallel(indPC).RemoteDirectory,'/',PRCDir])
else else
[NonServeS NonServeD]=mkdir(['\\',Parallel(indPC).PcName,'\',Parallel(indPC).RemoteDrive,'$\',Parallel(indPC).RemoteFolder,'\',PRCDir]); [NonServeS NonServeD]=mkdir(['\\',Parallel(indPC).ComputerName,'\',Parallel(indPC).RemoteDrive,'$\',Parallel(indPC).RemoteDirectory,'\',PRCDir]);
end end
end end
end end

View File

@ -2,16 +2,15 @@ function dynareParallelRmDir(PRCDir,Parallel)
% PARALLEL CONTEXT % PARALLEL CONTEXT
% In a parallel context, this is a specialized version of rmdir() function. % In a parallel context, this is a specialized version of rmdir() function.
% %
% INPUTS
% o PRCDir [] ...
% o Parallel [] ...
% %
% INPUT/OUTPUT description: % OUTPUTS
% None
% %
% %
% %
%
%
% Then at the point call of this function it is possible react in a best way, in accord
% with the ErrorCode.
% Copyright (C) 2009-2010 Dynare Team % Copyright (C) 2009-2010 Dynare Team
% %
% This file is part of Dynare. % This file is part of Dynare.
@ -38,12 +37,11 @@ end
for indPC=1:length(Parallel), for indPC=1:length(Parallel),
while (1) while (1)
% keyboard;
if isunix if isunix
stat = system(['ssh ',Parallel(indPC).user,'@',Parallel(indPC).PcName,' rm -fr ',Parallel(indPC).RemoteFolder,'/',PRCDir]); stat = system(['ssh ',Parallel(indPC).UserName,'@',Parallel(indPC).ComputerName,' rm -fr ',Parallel(indPC).RemoteDirectory,'/',PRCDir]);
break; break;
else else
[stat, mess, id] = rmdir(['\\',Parallel(indPC).PcName,'\',Parallel(indPC).RemoteDrive,'$\',Parallel(indPC).RemoteFolder,'\',PRCDir],'s'); [stat, mess, id] = rmdir(['\\',Parallel(indPC).ComputerName,'\',Parallel(indPC).RemoteDrive,'$\',Parallel(indPC).RemoteDirectory,'\',PRCDir],'s');
if stat==1, if stat==1,
break, break,
else else

View File

@ -1,9 +1,16 @@
function dynareParallelSendFiles(NamFileInput,PRCDir,Parallel) function dynareParallelSendFiles(NamFileInput,PRCDir,Parallel)
% PARALLEL CONTEXT % PARALLEL CONTEXT
% In a parallel context, this is ... % In a parallel context, this is a specialized mono-directional (Local to Remote) version of copy()
% function.
% %
% %
% INPUT/OUTPUT description: % INPUTS
% o NamFileInput [] ...
% o PRCDir [] ...
% o Parallel [] ...
%
% OUTPUTS
% None
% %
% %
% %
@ -37,18 +44,18 @@ for indPC=1:length(Parallel),
if isunix || (~matlab_ver_less_than('7.4') && ismac), if isunix || (~matlab_ver_less_than('7.4') && ismac),
for jfil=1:size(NamFileInput,1), for jfil=1:size(NamFileInput,1),
if ~isempty(NamFileInput{jfil,1}) if ~isempty(NamFileInput{jfil,1})
system(['ssh ',Parallel(indPC).user,'@',Parallel(indPC).PcName,' mkdir -p ',Parallel(indPC).RemoteFolder,'/',PRCDir,'/',NamFileInput{jfil,1}]) system(['ssh ',Parallel(indPC).UserName,'@',Parallel(indPC).ComputerName,' mkdir -p ',Parallel(indPC).RemoteDirectory,'/',PRCDir,'/',NamFileInput{jfil,1}])
end end
system(['scp ',NamFileInput{jfil,1},NamFileInput{jfil,2},' ',Parallel(indPC).user,'@',Parallel(indPC).PcName,':',Parallel(indPC).RemoteFolder,'/',PRCDir,'/',NamFileInput{jfil,1}]); system(['scp ',NamFileInput{jfil,1},NamFileInput{jfil,2},' ',Parallel(indPC).UserName,'@',Parallel(indPC).ComputerName,':',Parallel(indPC).RemoteDirectory,'/',PRCDir,'/',NamFileInput{jfil,1}]);
end end
else else
for jfil=1:size(NamFileInput,1) for jfil=1:size(NamFileInput,1)
if ~isempty(NamFileInput{jfil,1}) if ~isempty(NamFileInput{jfil,1})
if isempty(dynareParallelDir(NamFileInput{jfil,1},PRCDir,Parallel(indPC))) if isempty(dynareParallelDir(NamFileInput{jfil,1},PRCDir,Parallel(indPC)))
mkdir(['\\',Parallel(indPC).PcName,'\',Parallel(indPC).RemoteDrive,'$\',Parallel(indPC).RemoteFolder,'\',PRCDir,'\',NamFileInput{jfil,1}]); mkdir(['\\',Parallel(indPC).ComputerName,'\',Parallel(indPC).RemoteDrive,'$\',Parallel(indPC).RemoteDirectory,'\',PRCDir,'\',NamFileInput{jfil,1}]);
end end
end end
copyfile([NamFileInput{jfil,1},NamFileInput{jfil,2}],['\\',Parallel(indPC).PcName,'\',Parallel(indPC).RemoteDrive,'$\',Parallel(indPC).RemoteFolder,'\',PRCDir,'\',NamFileInput{jfil,1}]) copyfile([NamFileInput{jfil,1},NamFileInput{jfil,2}],['\\',Parallel(indPC).ComputerName,'\',Parallel(indPC).RemoteDrive,'$\',Parallel(indPC).RemoteDirectory,'\',PRCDir,'\',NamFileInput{jfil,1}])
end end
end end
end end

View File

@ -1,4 +1,4 @@
function fMessageStatus(prtfrc, njob, waitbarString, waitbarTitle, Parallel, MasterName, DyMo) function fMessageStatus(prtfrc, njob, waitbarString, waitbarTitle, Parallel)
% PARALLEL CONTEXT % PARALLEL CONTEXT
% In parallel context, this function is launched on slave % In parallel context, this function is launched on slave
% machines, and acts as a message passing device for the master machine. % machines, and acts as a message passing device for the master machine.
@ -9,9 +9,7 @@ function fMessageStatus(prtfrc, njob, waitbarString, waitbarTitle, Parallel, Mas
% cluster % cluster
% o waitbarString [char] running message string to be displayed in the monitor window on master machine % o waitbarString [char] running message string to be displayed in the monitor window on master machine
% o waitbarTitle [char] title to be displayed in the monitor window on master machine % o waitbarTitle [char] title to be displayed in the monitor window on master machine
% o Parallel [struct] options_.parallel(ThisMatlab), i.e. the paralle settings for this slave machine in the cluster % o Parallel [struct] options_.parallel(ThisMatlab), i.e. the parallel settings for this slave machine in the cluster.
% o MasterName [char] IP address or PC name of the master
% o DyMo [char] working directory of the master machine
% %
% OUTPUTS % OUTPUTS
% o None % o None

View File

@ -43,7 +43,6 @@ warning off;
diary off; diary off;
delete( [fname,'_',int2str(whoiam),'.log']); delete( [fname,'_',int2str(whoiam),'.log']);
diary( [fname,'_',int2str(whoiam),'.log']); diary( [fname,'_',int2str(whoiam),'.log']);
% Configure dynare environment. % Configure dynare environment.
@ -64,12 +63,10 @@ if exist('fGlobalVar') && ~isempty (fGlobalVar)
evalin('base','struct2local(fGlobalVar)'); evalin('base','struct2local(fGlobalVar)');
end end
fInputVar.Parallel = Parallel; fInputVar.Parallel = Parallel;
% Launch the routine to be run in parallel. % Launch the routine to be run in parallel.
try, try,
tic, tic,
@ -81,11 +78,8 @@ try,
OutputFileName = ''; OutputFileName = '';
end end
if(whoiam) if(whoiam)
% Save the output result. % Save the output result.
save([ fname,'_output_',int2str(whoiam),'.mat'],'fOutputVar' ) save([ fname,'_output_',int2str(whoiam),'.mat'],'fOutputVar' )
end end
disp(['fParallel ',int2str(whoiam),' completed.']) disp(['fParallel ',int2str(whoiam),' completed.'])
@ -94,11 +88,11 @@ catch ME
fOutputVar.error = ME; fOutputVar.error = ME;
save([ fname,'_output_',int2str(whoiam),'.mat'],'fOutputVar' ) save([ fname,'_output_',int2str(whoiam),'.mat'],'fOutputVar' )
waitbarString = fOutputVar.error.message; waitbarString = fOutputVar.error.message;
% waitbarTitle=['Metropolis-Hastings ',options_.parallel(ThisMatlab).PcName]; % waitbarTitle=['Metropolis-Hastings ',options_.parallel(ThisMatlab).ComputerName];
if Parallel(ThisMatlab).Local, if Parallel(ThisMatlab).Local,
waitbarTitle='Local '; waitbarTitle='Local ';
else else
waitbarTitle=[Parallel(ThisMatlab).PcName]; waitbarTitle=[Parallel(ThisMatlab).ComputerName];
end end
fMessageStatus(NaN,whoiam,waitbarString, waitbarTitle, Parallel(ThisMatlab)); fMessageStatus(NaN,whoiam,waitbarString, waitbarTitle, Parallel(ThisMatlab));

View File

@ -29,26 +29,28 @@ function [fOutVar,nBlockPerCPU, totCPU] = masterParallel(Parallel,fBlock,nBlock,
% INPUTS % INPUTS
% o Parallel [struct vector] copy of options_.parallel % o Parallel [struct vector] copy of options_.parallel
% o 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)
% o nBlock [int] index number of the last thread % o nBlock [int] index number of the last thread
% o 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
% o 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
% o 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
% o 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
% o Parallel_info []
% o initialize []
% %
% OUTPUT % OUTPUT
% o 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
% o 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
% o 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)
@ -76,7 +78,7 @@ function [fOutVar,nBlockPerCPU, totCPU] = masterParallel(Parallel,fBlock,nBlock,
% is used only one time and then deleted. % is used only one time and then deleted.
persistent PRCDir persistent PRCDir
% PRCDir= Present Remote Computational Directory! % PRCDir = Present Remote Computational Directory!
Strategy=Parallel_info.leaveSlaveOpen; Strategy=Parallel_info.leaveSlaveOpen;
@ -99,13 +101,21 @@ if nargin>8 && initialize==1
return return
end end
% The default value for the new field MatlabOctavePath now is 'matlab' or
% 'octave'.
for j=1:length(Parallel), for j=1:length(Parallel),
if isempty(Parallel(j).MatlabPath), if isempty(Parallel(j).MatlabOctavePath),
Parallel(j).MatlabPath = 'matlab'; Parallel(j).MatlabOctavePath = 'matlab';
end end
end end
% Only for testing!
% To test AnalyseComputationalEnviroment.m function
% save('Parallel.mat','-struct', 'Parallel');
% Only for testing!
% if Strategy==0 % if Strategy==0
% disp('User Strategy Now Is Open/Close (0)'); % disp('User Strategy Now Is Open/Close (0)');
% else % else
@ -129,7 +139,6 @@ end
MasterName=deblank(MasterName); MasterName=deblank(MasterName);
fInputVar.MasterName = MasterName; fInputVar.MasterName = MasterName;
% keyboard;
% Save input data for use by the slaves. % Save input data for use by the slaves.
switch Strategy switch Strategy
@ -163,11 +172,12 @@ mydelete(['comp_status_',fname,'*.mat'])
mydelete(['P_',fname,'*End.txt']) 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 ... % Create the directory devoted to remote computation.
if isempty(PRCDir) && ~islocal, if isempty(PRCDir) && ~islocal,
error('PRCDir not initialized!') error('PRCDir not initialized!')
else else
@ -190,9 +200,8 @@ for j=1:totCPU,
end end
offset = sum(nBlockPerCPU(1:j-1))+offset0; offset = sum(nBlockPerCPU(1:j-1))+offset0;
% Create a file used to monitoring if a parallel block (core)
% Creo un file che mi serve per sapere se la computazione di un % computation is finished or not.
% 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);
@ -230,9 +239,10 @@ for j=1:totCPU,
end end
else else
% Se la computazione è remota, lo creo in locale, lo copio directory remota (creata % If the computation is executed remotely all the necessary files
% sopra) e lo cancello in locale. Lo stesso vale per gli altri % are created localy, then copied in remote directory and then
% dati. % deleted (loacal)!
save( ['slaveParallel_input',int2str(j)],'Parallel'); save( ['slaveParallel_input',int2str(j)],'Parallel');
if Parallel(indPC).Local==0, if Parallel(indPC).Local==0,
@ -251,22 +261,22 @@ for j=1:totCPU,
switch Strategy switch Strategy
case 0 case 0
if Parallel(indPC).Local == 1, %Run on the local machine (localhost). if Parallel(indPC).Local == 1, % 0.1 Run on the local machine (localhost).
if isunix || (~matlab_ver_less_than('7.4') && ismac), if isunix || (~matlab_ver_less_than('7.4') && ismac),
if exist('OCTAVE_VERSION') if exist('OCTAVE_VERSION')
command1=['octave --eval "addpath(''',Parallel(indPC).DynarePath,'''), dynareroot = dynare_config(); fParallel(',int2str(offset+1),',',int2str(sum(nBlockPerCPU(1:j))),',',int2str(j),',',int2str(indPC),',''',fname,''')" &']; command1=['octave --eval "addpath(''',Parallel(indPC).DynarePath,'''), dynareroot = dynare_config(); fParallel(',int2str(offset+1),',',int2str(sum(nBlockPerCPU(1:j))),',',int2str(j),',',int2str(indPC),',''',fname,''')" &'];
else else
command1=[Parallel(indPC).MatlabPath,' -nosplash -nodesktop -minimize -r "addpath(''',Parallel(indPC).DynarePath,'''), dynareroot = dynare_config(); fParallel(',int2str(offset+1),',',int2str(sum(nBlockPerCPU(1:j))),',',int2str(j),',',int2str(indPC),',''',fname,''')" &']; command1=[Parallel(indPC).MatlabOctavePath,' -nosplash -nodesktop -minimize -r "addpath(''',Parallel(indPC).DynarePath,'''), dynareroot = dynare_config(); fParallel(',int2str(offset+1),',',int2str(sum(nBlockPerCPU(1:j))),',',int2str(j),',',int2str(indPC),',''',fname,''')" &'];
end end
else else
if exist('OCTAVE_VERSION') if exist('OCTAVE_VERSION')
command1=['start /B psexec -W ',DyMo, ' -a ',int2str(Parallel(indPC).NumCPU(j-nCPU0)),' -low octave --eval "addpath(''',Parallel(indPC).DynarePath,'''), dynareroot = dynare_config(); fParallel(',int2str(offset+1),',',int2str(sum(nBlockPerCPU(1:j))),',',int2str(j),',',int2str(indPC),',''',fname,''')"']; command1=['start /B psexec -W ',DyMo, ' -a ',int2str(Parallel(indPC).CPUnbr(j-nCPU0)),' -low octave --eval "addpath(''',Parallel(indPC).DynarePath,'''), dynareroot = dynare_config(); fParallel(',int2str(offset+1),',',int2str(sum(nBlockPerCPU(1:j))),',',int2str(j),',',int2str(indPC),',''',fname,''')"'];
else 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,'''), dynareroot = dynare_config(); fParallel(',int2str(offset+1),',',int2str(sum(nBlockPerCPU(1:j))),',',int2str(j),',',int2str(indPC),',''',fname,''')"']; command1=['start /B psexec -W ',DyMo, ' -a ',int2str(Parallel(indPC).CPUnbr(j-nCPU0)),' -low ',Parallel(indPC).MatlabOctavePath,' -nosplash -nodesktop -minimize -r "addpath(''',Parallel(indPC).DynarePath,'''), dynareroot = dynare_config(); fParallel(',int2str(offset+1),',',int2str(sum(nBlockPerCPU(1:j))),',',int2str(j),',',int2str(indPC),',''',fname,''')"'];
end end
end end
else % Parallel(indPC).Local==0: Run using network on remote machine or also on local machine. else % 0.2 Parallel(indPC).Local==0: Run using network on remote machine or also on local machine.
if j==nCPU0+1, if j==nCPU0+1,
dynareParallelSendFiles([fname,'_input.mat'],PRCDir,Parallel(indPC)); dynareParallelSendFiles([fname,'_input.mat'],PRCDir,Parallel(indPC));
dynareParallelSendFiles(NamFileInput,PRCDir,Parallel(indPC)); dynareParallelSendFiles(NamFileInput,PRCDir,Parallel(indPC));
@ -274,26 +284,26 @@ for j=1:totCPU,
if isunix || (~matlab_ver_less_than('7.4') && ismac), if isunix || (~matlab_ver_less_than('7.4') && ismac),
if exist('OCTAVE_VERSION'), if exist('OCTAVE_VERSION'),
command1=['ssh ',Parallel(indPC).user,'@',Parallel(indPC).PcName,' "cd ',Parallel(indPC).RemoteFolder,'/',PRCDir, '; octave --eval \"addpath(''',Parallel(indPC).DynarePath,'''), dynareroot = dynare_config(); fParallel(',int2str(offset+1),',',int2str(sum(nBlockPerCPU(1:j))),',',int2str(j),',',int2str(indPC),',''',fname,''');\" " &']; command1=['ssh ',Parallel(indPC).UserName,'@',Parallel(indPC).ComputerName,' "cd ',Parallel(indPC).RemoteDirectory,'/',PRCDir, '; octave --eval \"addpath(''',Parallel(indPC).DynarePath,'''), dynareroot = dynare_config(); fParallel(',int2str(offset+1),',',int2str(sum(nBlockPerCPU(1:j))),',',int2str(j),',',int2str(indPC),',''',fname,''');\" " &'];
else 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,'''), dynareroot = dynare_config(); fParallel(',int2str(offset+1),',',int2str(sum(nBlockPerCPU(1:j))),',',int2str(j),',',int2str(indPC),',''',fname,''');\" " &']; command1=['ssh ',Parallel(indPC).UserName,'@',Parallel(indPC).ComputerName,' "cd ',Parallel(indPC).RemoteDirectory,'/',PRCDir, '; ',Parallel(indPC).MatlabOctavePath,' -nosplash -nodesktop -minimize -r \"addpath(''',Parallel(indPC).DynarePath,'''), dynareroot = dynare_config(); 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).ComputerName,MasterName), % 0.3 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,'\',PRCDir,'\ -a ',int2str(Parallel(indPC).NumCPU(j-nCPU0)), ... command1=['start /B psexec \\',Parallel(indPC).ComputerName,' -e -u ',Parallel(indPC).UserName,' -p ',Parallel(indPC).Password,' -W ',Parallel(indPC).RemoteDrive,':\',Parallel(indPC).RemoteDirectory,'\',PRCDir,'\ -a ',int2str(Parallel(indPC).CPUnbr(j-nCPU0)), ...
' -low octave --eval "addpath(''',Parallel(indPC).DynarePath,'''), dynareroot = dynare_config(); fParallel(',int2str(offset+1),',',int2str(sum(nBlockPerCPU(1:j))),',',int2str(j),',',int2str(indPC),',''',fname,''')"']; ' -low octave --eval "addpath(''',Parallel(indPC).DynarePath,'''), dynareroot = dynare_config(); fParallel(',int2str(offset+1),',',int2str(sum(nBlockPerCPU(1:j))),',',int2str(j),',',int2str(indPC),',''',fname,''')"'];
else 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)), ... command1=['start /B psexec \\',Parallel(indPC).ComputerName,' -e -u ',Parallel(indPC).UserName,' -p ',Parallel(indPC).Password,' -W ',Parallel(indPC).RemoteDrive,':\',Parallel(indPC).RemoteDirectory,'\',PRCDir,'\ -a ',int2str(Parallel(indPC).CPUnbr(j-nCPU0)), ...
' -low ',Parallel(indPC).MatlabPath,' -nosplash -nodesktop -minimize -r "addpath(''',Parallel(indPC).DynarePath,'''), dynareroot = dynare_config(); fParallel(',int2str(offset+1),',',int2str(sum(nBlockPerCPU(1:j))),',',int2str(j),',',int2str(indPC),',''',fname,''')"']; ' -low ',Parallel(indPC).MatlabOctavePath,' -nosplash -nodesktop -minimize -r "addpath(''',Parallel(indPC).DynarePath,'''), dynareroot = dynare_config(); 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 % 0.4 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,'\',PRCDir,'\ -a ',int2str(Parallel(indPC).NumCPU(j-nCPU0)), ... command1=['start /B psexec \\',Parallel(indPC).ComputerName,' -e -W ',Parallel(indPC).RemoteDrive,':\',Parallel(indPC).RemoteDirectory,'\',PRCDir,'\ -a ',int2str(Parallel(indPC).CPUnbr(j-nCPU0)), ...
' -low octave --eval "addpath(''',Parallel(indPC).DynarePath,'''), dynareroot = dynare_config(); fParallel(',int2str(offset+1),',',int2str(sum(nBlockPerCPU(1:j))),',',int2str(j),',',int2str(indPC),',''',fname,''')"']; ' -low octave --eval "addpath(''',Parallel(indPC).DynarePath,'''), dynareroot = dynare_config(); fParallel(',int2str(offset+1),',',int2str(sum(nBlockPerCPU(1:j))),',',int2str(j),',',int2str(indPC),',''',fname,''')"'];
else else
command1=['start /B psexec \\',Parallel(indPC).PcName,' -e -W ',Parallel(indPC).RemoteDrive,':\',Parallel(indPC).RemoteFolder,'\',PRCDir,'\ -a ',int2str(Parallel(indPC).NumCPU(j-nCPU0)), ... command1=['start /B psexec \\',Parallel(indPC).ComputerName,' -e -W ',Parallel(indPC).RemoteDrive,':\',Parallel(indPC).RemoteDirectory,'\',PRCDir,'\ -a ',int2str(Parallel(indPC).CPUnbr(j-nCPU0)), ...
' -low ',Parallel(indPC).MatlabPath,' -nosplash -nodesktop -minimize -r "addpath(''',Parallel(indPC).DynarePath,'''), dynareroot = dynare_config(); fParallel(',int2str(offset+1),',',int2str(sum(nBlockPerCPU(1:j))),',',int2str(j),',',int2str(indPC),',''',fname,''')"']; ' -low ',Parallel(indPC).MatlabOctavePath,' -nosplash -nodesktop -minimize -r "addpath(''',Parallel(indPC).DynarePath,'''), dynareroot = dynare_config(); fParallel(',int2str(offset+1),',',int2str(sum(nBlockPerCPU(1:j))),',',int2str(j),',',int2str(indPC),',''',fname,''')"'];
end end
end end
end end
@ -301,25 +311,21 @@ for j=1:totCPU,
case 1 case 1
if Parallel(indPC).Local == 1 & newInstance, % Run on the local machine. if Parallel(indPC).Local == 1 & newInstance, % 1.1 Run on the local machine.
if isunix || (~matlab_ver_less_than('7.4') && ismac), if isunix || (~matlab_ver_less_than('7.4') && ismac),
if exist('OCTAVE_VERSION') 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,'''), dynareroot = dynare_config(); slaveParallel(',int2str(j),',',int2str(indPC),')" &']; command1=['octave --eval "addpath(''',Parallel(indPC).DynarePath,'''), dynareroot = dynare_config(); slaveParallel(',int2str(j),',',int2str(indPC),')" &'];
else 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).MatlabOctavePath,' -nosplash -nodesktop -minimize -r "addpath(''',Parallel(indPC).DynarePath,'''), dynareroot = dynare_config(); slaveParallel(',int2str(j),',',int2str(indPC),')" &'];
command1=[Parallel(indPC).MatlabPath,' -nosplash -nodesktop -minimize -r "addpath(''',Parallel(indPC).DynarePath,'''), dynareroot = dynare_config(); slaveParallel(',int2str(j),',',int2str(indPC),')" &'];
end end
else else
if exist('OCTAVE_VERSION') 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).CPUnbr(j-nCPU0)),' -low octave --eval "addpath(''',Parallel(indPC).DynarePath,'''), dynareroot = dynare_config(); slaveParallel(',int2str(j),',',int2str(indPC),')"'];
command1=['start /B psexec -W ',DyMo, ' -a ',int2str(Parallel(indPC).NumCPU(j-nCPU0)),' -low octave --eval "addpath(''',Parallel(indPC).DynarePath,'''), dynareroot = dynare_config(); slaveParallel(',int2str(j),',',int2str(indPC),')"'];
else 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).CPUnbr(j-nCPU0)),' -low ',Parallel(indPC).MatlabOctavePath,' -nosplash -nodesktop -minimize -r "addpath(''',Parallel(indPC).DynarePath,'''), dynareroot = dynare_config(); slaveParallel(',int2str(j),',',int2str(indPC),')"'];
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,'''), dynareroot = dynare_config(); slaveParallel(',int2str(j),',',int2str(indPC),')"'];
end end
end end
elseif Parallel(indPC).Local==0, % Run using network on remote machine or also on local machine. elseif Parallel(indPC).Local==0, % 1.2 Run using network on remote machine or also on local machine.
if j==nCPU0+1, if j==nCPU0+1,
dynareParallelSendFiles(NamFileInput,PRCDir,Parallel(indPC)); dynareParallelSendFiles(NamFileInput,PRCDir,Parallel(indPC));
end end
@ -331,26 +337,26 @@ for j=1:totCPU,
dynareParallelSendFiles(['slaveParallel_input',int2str(j),'.mat'],PRCDir,Parallel(indPC)) dynareParallelSendFiles(['slaveParallel_input',int2str(j),'.mat'],PRCDir,Parallel(indPC))
if isunix || (~matlab_ver_less_than('7.4') && ismac), if isunix || (~matlab_ver_less_than('7.4') && ismac),
if exist('OCTAVE_VERSION'), if exist('OCTAVE_VERSION'),
command1=['ssh ',Parallel(indPC).user,'@',Parallel(indPC).PcName,' "cd ',Parallel(indPC).RemoteFolder,'/',PRCDir '; octave --eval \"addpath(''',Parallel(indPC).DynarePath,'''), dynareroot = dynare_config(); slaveParallel(',int2str(j),',',int2str(indPC),');\" " &']; command1=['ssh ',Parallel(indPC).UserName,'@',Parallel(indPC).ComputerName,' "cd ',Parallel(indPC).RemoteDirectory,'/',PRCDir '; octave --eval \"addpath(''',Parallel(indPC).DynarePath,'''), dynareroot = dynare_config(); slaveParallel(',int2str(j),',',int2str(indPC),');\" " &'];
else 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,'''), dynareroot = dynare_config(); slaveParallel(',int2str(j),',',int2str(indPC),');\" " &']; command1=['ssh ',Parallel(indPC).UserName,'@',Parallel(indPC).ComputerName,' "cd ',Parallel(indPC).RemoteDirectory,'/',PRCDir '; ',Parallel(indPC).MatlabOctavePath,' -nosplash -nodesktop -minimize -r \"addpath(''',Parallel(indPC).DynarePath,'''), dynareroot = dynare_config(); slaveParallel(',int2str(j),',',int2str(indPC),');\" " &'];
end end
else else
if ~strcmp(Parallel(indPC).PcName,MasterName), % Run on a remote machine. if ~strcmp(Parallel(indPC).ComputerName,MasterName), % 1.3 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,'\',PRCDir,'\ -a ',int2str(Parallel(indPC).NumCPU(j-nCPU0)), ... command1=['start /B psexec \\',Parallel(indPC).ComputerName,' -e -u ',Parallel(indPC).UserName,' -p ',Parallel(indPC).Password,' -W ',Parallel(indPC).RemoteDrive,':\',Parallel(indPC).RemoteDirectory,'\',PRCDir,'\ -a ',int2str(Parallel(indPC).CPUnbr(j-nCPU0)), ...
' -low octave --eval "addpath(''',Parallel(indPC).DynarePath,'''), dynareroot = dynare_config(); slaveParallel(',int2str(j),',',int2str(indPC),')"']; ' -low octave --eval "addpath(''',Parallel(indPC).DynarePath,'''), dynareroot = dynare_config(); slaveParallel(',int2str(j),',',int2str(indPC),')"'];
else 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)), ... command1=['start /B psexec \\',Parallel(indPC).ComputerName,' -e -u ',Parallel(indPC).UserName,' -p ',Parallel(indPC).Password,' -W ',Parallel(indPC).RemoteDrive,':\',Parallel(indPC).RemoteDirectory,'\',PRCDir,'\ -a ',int2str(Parallel(indPC).CPUnbr(j-nCPU0)), ...
' -low ',Parallel(indPC).MatlabPath,' -nosplash -nodesktop -minimize -r "addpath(''',Parallel(indPC).DynarePath,'''), dynareroot = dynare_config(); slaveParallel(',int2str(j),',',int2str(indPC),')"']; ' -low ',Parallel(indPC).MatlabOctavePath,' -nosplash -nodesktop -minimize -r "addpath(''',Parallel(indPC).DynarePath,'''), dynareroot = dynare_config(); slaveParallel(',int2str(j),',',int2str(indPC),')"'];
end end
else % Run on the local machine via the network. else % 1.4 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,'\',PRCDir,'\ -a ',int2str(Parallel(indPC).NumCPU(j-nCPU0)), ... command1=['start /B psexec \\',Parallel(indPC).ComputerName,' -e -W ',Parallel(indPC).RemoteDrive,':\',Parallel(indPC).RemoteDirectory,'\',PRCDir,'\ -a ',int2str(Parallel(indPC).CPUnbr(j-nCPU0)), ...
' -low octave --eval "addpath(''',Parallel(indPC).DynarePath,'''), dynareroot = dynare_config(); slaveParallel(',int2str(j),',',int2str(indPC),')"']; ' -low octave --eval "addpath(''',Parallel(indPC).DynarePath,'''), dynareroot = dynare_config(); slaveParallel(',int2str(j),',',int2str(indPC),')"'];
else else
command1=['start /B psexec \\',Parallel(indPC).PcName,' -e -W ',Parallel(indPC).RemoteDrive,':\',Parallel(indPC).RemoteFolder,'\',PRCDir,'\ -a ',int2str(Parallel(indPC).NumCPU(j-nCPU0)), ... command1=['start /B psexec \\',Parallel(indPC).ComputerName,' -e -W ',Parallel(indPC).RemoteDrive,':\',Parallel(indPC).RemoteDirectory,'\',PRCDir,'\ -a ',int2str(Parallel(indPC).CPUnbr(j-nCPU0)), ...
' -low ',Parallel(indPC).MatlabPath,' -nosplash -nodesktop -minimize -r "addpath(''',Parallel(indPC).DynarePath,'''), dynareroot = dynare_config(); slaveParallel(',int2str(j),',',int2str(indPC),')"']; ' -low ',Parallel(indPC).MatlabOctavePath,' -nosplash -nodesktop -minimize -r "addpath(''',Parallel(indPC).DynarePath,'''), dynareroot = dynare_config(); slaveParallel(',int2str(j),',',int2str(indPC),')"'];
end end
end end
end end
@ -364,6 +370,14 @@ for j=1:totCPU,
end end
fclose(fid); fclose(fid);
% In This way we are sure that the file 'ConcurrentCommand1.bat' is
% closed and then it can be deleted!
while (1)
StatusOfCC1_bat = fclose(fid);
if StatusOfCC1_bat==0
break
end
end
% Run the slaves. % Run the slaves.
if isunix || (~matlab_ver_less_than('7.4') && ismac), if isunix || (~matlab_ver_less_than('7.4') && ismac),
@ -374,9 +388,7 @@ else
end end
% Wait for the slaves to finish their job, and display some progress % Create a parallel (local/remote) specialized computational status bars!
% information meanwhile.
if exist('OCTAVE_VERSION'), if exist('OCTAVE_VERSION'),
diary off; diary off;
@ -421,6 +433,11 @@ idCPU = NaN(1,totCPU);
delete(['comp_status_',fname,'*.mat']); delete(['comp_status_',fname,'*.mat']);
% Wait for the slaves to finish their job, and display some progress
% information meanwhile.
ForEver=1; ForEver=1;
while (ForEver) while (ForEver)
@ -428,9 +445,7 @@ while (ForEver)
waitbarString = ''; waitbarString = '';
statusString = ''; statusString = '';
pause(1)
pause(1)
try try
if islocal ==0, if islocal ==0,
@ -439,11 +454,10 @@ while (ForEver)
catch catch
end end
% stax = dir(['comp_status_',fname,'*.mat']); for j=1:totCPU,
for j=1:totCPU, %length(stax),
try try
if ~isempty(['comp_status_',fname,int2str(j),'.mat']) if ~isempty(['comp_status_',fname,int2str(j),'.mat'])
load(['comp_status_',fname,int2str(j),'.mat']);% (stax(j).name) load(['comp_status_',fname,int2str(j),'.mat']);
end end
pcerdone(j) = prtfrc; pcerdone(j) = prtfrc;
idCPU(j) = njob; idCPU(j) = njob;
@ -453,19 +467,14 @@ while (ForEver)
status_String{j} = waitbarString; status_String{j} = waitbarString;
status_Title{j} = waitbarTitle; status_Title{j} = waitbarTitle;
end end
% if prtfrc==1, delete(stax(j).name), end catch % ME
catch % To define!
% pcerdone(j) = NaN;
% idCPU(j) = NaN;
% 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
for j=1:totCPU, %length(stax) for j=1:totCPU,
try try
set(hpat(j),'XData',[0 0 pcerdone(j) pcerdone(j)]); set(hpat(j),'XData',[0 0 pcerdone(j) pcerdone(j)]);
set(htit(j),'String',[status_Title{j},' - ',status_String{j}]); set(htit(j),'String',[status_Title{j},' - ',status_String{j}]);
@ -475,8 +484,6 @@ while (ForEver)
end end
end end
if isempty(dynareParallelDir(['P_',fname,'_*End.txt'],PRCDir,Parallel(1:totSlaves))); if isempty(dynareParallelDir(['P_',fname,'_*End.txt'],PRCDir,Parallel(1:totSlaves)));
HoTuttiGliOutput=0; HoTuttiGliOutput=0;
for j=1:totCPU, for j=1:totCPU,
@ -502,9 +509,6 @@ while (ForEver)
end end
% keyboard;
% Create return value. % Create return value.
iscrash = 0; iscrash = 0;
for j=1:totCPU, for j=1:totCPU,
@ -528,19 +532,19 @@ for j=1:totCPU,
end end
end end
if iscrash, if iscrash,
error('Remote jobs crashed'); error('Remote jobs crashed');
end end
pause(1), % wait for all remote diary off completed pause(1), % Wait for all remote diary off completed
% Cleanup. (Only if the computing is executed remotly). % Cleanup.
dynareParallelGetFiles('*.log',PRCDir,Parallel(1:totSlaves)); dynareParallelGetFiles('*.log',PRCDir,Parallel(1:totSlaves));
switch Strategy switch Strategy
case 0 case 0
for indPC=1:length(Parallel) for indPC=1:length(Parallel)
if Parallel(indPC).Local == 0 if Parallel(indPC).Local == 0
dynareParallelRmDir(PRCDir,Parallel(indPC)); dynareParallelRmDir(PRCDir,Parallel(indPC));
end end
if isempty(dir('dynareParallelLogFiles')) if isempty(dir('dynareParallelLogFiles'))
@ -551,12 +555,10 @@ switch Strategy
copyfile('*.log','dynareParallelLogFiles'); copyfile('*.log','dynareParallelLogFiles');
delete([fname,'*.log']); delete([fname,'*.log']);
%%%%%%%% E' GIUSTO??? %%%%%%%%%%%%%
mydelete(['*_core*_input*.mat']); mydelete(['*_core*_input*.mat']);
if Parallel(indPC).Local == 1 % if Parallel(indPC).Local == 1
delete(['slaveParallel_input*.mat']); % delete(['slaveParallel_input*.mat']);
end % end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
end end

View File

@ -8,9 +8,9 @@ function slaveParallel(whoiam,ThisMatlab)
% %
% %
% INPUTS % INPUTS
% 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.
% %
% OUTPUTS % OUTPUTS
% None % None
@ -41,12 +41,11 @@ delete( ['slaveParallel_',int2str(whoiam),'.log']);
diary( ['slaveParallel_',int2str(whoiam),'.log']); diary( ['slaveParallel_',int2str(whoiam),'.log']);
% configure dynare environment % Configure dynare environment
dynareroot = dynare_config(); dynareroot = dynare_config();
% Load input data. % Load input data.
load( ['slaveParallel_input',int2str(whoiam)]) load( ['slaveParallel_input',int2str(whoiam)])
% keyboard;
%Loads fGlobalVar Parallel. %Loads fGlobalVar Parallel.
if exist('fGlobalVar'), if exist('fGlobalVar'),
@ -74,9 +73,6 @@ while (etime(clock,t0)<1200 && ~isempty(fslave)) || ~isempty(dir(['stayalive',in
% I wait for 20 min or while mater asks to exit (i.e. it cancels fslave file) % I wait for 20 min or while mater asks to exit (i.e. it cancels fslave file)
pause(1); pause(1);
% -> Da Sistemare!!!!!!!!!!!!!!!!
% Con testing su reti vere e con core reali!!!!
fjob = dir(['slaveJob',int2str(whoiam),'.mat']); fjob = dir(['slaveJob',int2str(whoiam),'.mat']);
if ~isempty(fjob), if ~isempty(fjob),
@ -95,13 +91,13 @@ while (etime(clock,t0)<1200 && ~isempty(fslave)) || ~isempty(dir(['stayalive',in
else else
% Only for testing, will be remouved! % Only for testing, will be remouved!
if isunix % if isunix
E1=fopen('/home/ivano/Works/Errore-slaveParallel.txt','w+'); % E1=fopen('/home/ivano/Works/Errore-slaveParallel.txt','w+');
fclose(E1); % fclose(E1);
else % else
E1=fopen('c:\dynare_calcs\Errore-slaveParallel.txt','w+'); % E1=fopen('c:\dynare_calcs\Errore-slaveParallel.txt','w+');
fclose(E1); % fclose(E1);
end % end
end end
end end
@ -155,7 +151,7 @@ while (etime(clock,t0)<1200 && ~isempty(fslave)) || ~isempty(dir(['stayalive',in
if Parallel(ThisMatlab).Local, if Parallel(ThisMatlab).Local,
waitbarTitle='Local '; waitbarTitle='Local ';
else else
waitbarTitle=[Parallel(ThisMatlab).PcName]; waitbarTitle=[Parallel(ThisMatlab).ComputerName];
end end
fMessageStatus(NaN,whoiam,waitbarString, waitbarTitle, Parallel(ThisMatlab)); fMessageStatus(NaN,whoiam,waitbarString, waitbarTitle, Parallel(ThisMatlab));
delete(['P_',fname,'_',int2str(whoiam),'End.txt']); delete(['P_',fname,'_',int2str(whoiam),'End.txt']);

View File

@ -1,10 +1,16 @@
function storeGlobalVars(fname,append) function storeGlobalVars(fname,append)
% Stores all global vars in structure fGlobalVar and saves it in the file fname.mat % PARALLEL CONTEXT
% In a parallel context, this function stores all global vars in structure
% fGlobalVar and saves it in the file fname.mat
% %
% INPUTS % INPUTS
% fname [str] name of the file % fname [str] name of the file
%
% Copyright (C) 2009 Dynare Team % OUTPUTS
% None
%
%
% Copyright (C) 2009-2010 Dynare Team
% %
% This file is part of Dynare. % This file is part of Dynare.
% %
@ -21,8 +27,9 @@ function storeGlobalVars(fname,append)
% 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/>.
GlobalNames = who('global'); GlobalNames = who('global');
varlist = ''; % varlist = '';
for j=1:length(GlobalNames); for j=1:length(GlobalNames);
eval(['global ',GlobalNames{j},';']); eval(['global ',GlobalNames{j},';']);
eval(['fGlobalVar.',GlobalNames{j},'=',GlobalNames{j},';']); eval(['fGlobalVar.',GlobalNames{j},'=',GlobalNames{j},';']);

View File

@ -1,10 +1,16 @@
function struct2local(S), function struct2local(S)
% The argument is a structure possibly containing several fields. % PARALLEL CONTEXT
% This function will create, in the workspace of the calling function, % In a parallel context, this function will create, in the workspace of the calling function,
% as many variables as there are fields in the structure, assigning % as many variables as there are fields in the structure, assigning
% them the value of the fields. % them the value of the fields.
%
% Copyright (C) 2009 Dynare Team % INPUTS
% o S [struc] This structure possibly containing several fields ...
%
% OUTPUTS
% None
%
% Copyright (C) 2009-2010 Dynare Team
% %
% This file is part of Dynare. % This file is part of Dynare.
% %
@ -21,6 +27,7 @@ function struct2local(S),
% 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/>.
vnam = fieldnames(S); vnam = fieldnames(S);
for j=1:length(vnam), for j=1:length(vnam),

View File

@ -4,7 +4,7 @@ function myoutput=pm3_core(myinputs,fpar,nvar,whoiam, ThisMatlab)
% Core functionality for pm3.m function, which can be parallelized. % Core functionality for pm3.m function, which can be parallelized.
% INPUTS % INPUTS
% See See the comment in random_walk_metropolis_hastings_core.m funtion. % See the comment in random_walk_metropolis_hastings_core.m funtion.
% OUTPUTS % OUTPUTS
% o myoutput [struc] % o myoutput [struc]
@ -52,8 +52,6 @@ Mean=myinputs.Mean;
if whoiam if whoiam
Parallel=myinputs.Parallel; Parallel=myinputs.Parallel;
MasterName=myinputs.MasterName;
DyMo=myinputs.DyMo;
end end
@ -65,9 +63,9 @@ if whoiam
if Parallel(ThisMatlab).Local, if Parallel(ThisMatlab).Local,
waitbarTitle=['Local ']; waitbarTitle=['Local '];
else else
waitbarTitle=[Parallel(ThisMatlab).PcName]; waitbarTitle=[Parallel(ThisMatlab).ComputerName];
end end
fMessageStatus(0,whoiam,waitbarString, waitbarTitle, Parallel(ThisMatlab), MasterName, DyMo); fMessageStatus(0,whoiam,waitbarString, waitbarTitle, Parallel(ThisMatlab));
end end
@ -126,7 +124,7 @@ for i=fpar:nvar
if whoiam, if whoiam,
waitbarString = [ 'Variable ' int2str(i) '/' int2str(nvar) ' done.']; waitbarString = [ 'Variable ' int2str(i) '/' int2str(nvar) ' done.'];
fMessageStatus((i-fpar+1)/(nvar-fpar+1),whoiam,waitbarString, waitbarTitle, Parallel(ThisMatlab), MasterName, DyMo); fMessageStatus((i-fpar+1)/(nvar-fpar+1),whoiam,waitbarString, waitbarTitle, Parallel(ThisMatlab));
end end

View File

@ -194,9 +194,9 @@ end
b=0; b=0;
% Like sequential execution! % Like sequential execution!
if isnumeric(options_.parallel),% | isunix, % For the moment exclude unix platform from parallel implementation! if isnumeric(options_.parallel),
[fout] = prior_posterior_statistics_core(localVars,1,B,0); [fout] = prior_posterior_statistics_core(localVars,1,B,0);
% Parallel execution! % Parallel execution!
else else
[nCPU, totCPU, nBlockPerCPU] = distributeJobs(options_.parallel, 1, B); [nCPU, totCPU, nBlockPerCPU] = distributeJobs(options_.parallel, 1, B);
for j=1:totCPU-1, for j=1:totCPU-1,
@ -214,8 +214,8 @@ else
ifil(6,j+1) =ifil(6,j)+nfiles; ifil(6,j+1) =ifil(6,j)+nfiles;
nfiles = ceil(nBlockPerCPU(j)/MAX_nforc2); nfiles = ceil(nBlockPerCPU(j)/MAX_nforc2);
ifil(7,j+1) =ifil(7,j)+nfiles; ifil(7,j+1) =ifil(7,j)+nfiles;
% nfiles = ceil(nBlockPerCPU(j)/MAX_momentsno); % nfiles = ceil(nBlockPerCPU(j)/MAX_momentsno);
% ifil(8,j+1) =ifil(8,j)+nfiles; % ifil(8,j+1) =ifil(8,j)+nfiles;
end end
localVars.ifil = ifil; localVars.ifil = ifil;
globalVars = struct('M_',M_, ... globalVars = struct('M_',M_, ...
@ -243,8 +243,8 @@ save([DirectoryName '/' M_.fname '_data.mat'],'stock_gend','stock_data');
if ~isnumeric(options_.parallel), if ~isnumeric(options_.parallel),
leaveSlaveOpen = options_.parallel_info.leaveSlaveOpen; leaveSlaveOpen = options_.parallel_info.leaveSlaveOpen;
if options_.parallel_info.leaveSlaveOpen == 0, if options_.parallel_info.leaveSlaveOpen == 0,
% Commenting for testing! % Commenting for testing!!!
% options_.parallel_info.leaveSlaveOpen = 1; % Force locally to leave open remote matlab sessions (repeated pm3 calls) % options_.parallel_info.leaveSlaveOpen = 1; % Force locally to leave open remote matlab sessions (repeated pm3 calls)
end end
end end

View File

@ -48,7 +48,6 @@ global options_ oo_ M_ bayestopt_ estim_params_
% Reshape 'myinputs' for local computation. % Reshape 'myinputs' for local computation.
% In order to avoid confusion in the name space, the instruction struct2local(myinputs) is replaced by: % In order to avoid confusion in the name space, the instruction struct2local(myinputs) is replaced by:
% Da CONTROLLARE con MARCO!
type=myinputs.type; type=myinputs.type;
run_smoother=myinputs.run_smoother; run_smoother=myinputs.run_smoother;
gend=myinputs.gend; gend=myinputs.gend;
@ -87,8 +86,6 @@ if ~strcmpi(type,'prior'),
end end
if whoiam if whoiam
Parallel=myinputs.Parallel; Parallel=myinputs.Parallel;
MasterName=myinputs.MasterName;
DyMo=myinputs.DyMo;
end end
DirectoryName = CheckPath('metropolis'); DirectoryName = CheckPath('metropolis');
@ -105,9 +102,9 @@ if whoiam
if Parallel(ThisMatlab).Local, if Parallel(ThisMatlab).Local,
waitbarTitle=['Local ']; waitbarTitle=['Local '];
else else
waitbarTitle=[Parallel(ThisMatlab).PcName]; waitbarTitle=[Parallel(ThisMatlab).ComputerName];
end end
fMessageStatus(0,whoiam,waitbarString, waitbarTitle, Parallel(ThisMatlab), MasterName, DyMo); fMessageStatus(0,whoiam,waitbarString, waitbarTitle, Parallel(ThisMatlab));
else else
if exist('OCTAVE_VERSION') if exist('OCTAVE_VERSION')
diary off; diary off;
@ -298,11 +295,11 @@ for b=fpar:B
elseif ~whoiam, elseif ~whoiam,
waitbar(b/B,h); waitbar(b/B,h);
end end
% if mod(b,10)==0 & whoiam,
if whoiam, if whoiam,
fprintf('Done! \n'); fprintf('Done! \n');
waitbarString = [ 'Subdraw ' int2str(b) '/' int2str(B) ' done.']; waitbarString = [ 'Subdraw ' int2str(b) '/' int2str(B) ' done.'];
fMessageStatus((b-fpar+1)/(B-fpar+1),whoiam,waitbarString, waitbarTitle, Parallel(ThisMatlab), MasterName, DyMo); fMessageStatus((b-fpar+1)/(B-fpar+1),whoiam,waitbarString, waitbarTitle, Parallel(ThisMatlab));
end end
end end

View File

@ -63,6 +63,19 @@ InitSizeArray = min([repmat(MAX_nruns,nblck,1) fline+nruns-1],[],2);
load([MhDirectoryName '/' ModelName '_mh_history.mat'],'record'); load([MhDirectoryName '/' ModelName '_mh_history.mat'],'record');
% Only for test parallel results!!!
% To check the equivalence between parallel and seria computation!
% First run in serial mode, and then comment the follow line.
% save('recordSerial.mat','-struct', 'record');
% For parllel runs after serial runs with the abobe line active.
% TempRecord=load('recordSerial.mat');
% record.Seeds=TempRecord.Seeds;
% Snapshot of the current state of computing. It necessary for the parallel % Snapshot of the current state of computing. It necessary for the parallel
% execution (i.e. to execute in a corretct way portion of code remotely or % execution (i.e. to execute in a corretct way portion of code remotely or
% on many core). The mandatory variables for local/remote parallel % on many core). The mandatory variables for local/remote parallel

View File

@ -95,8 +95,6 @@ varargin=myinputs.varargin;
% Necessary only for remote computing! % Necessary only for remote computing!
if whoiam if whoiam
Parallel=myinputs.Parallel; Parallel=myinputs.Parallel;
MasterName=myinputs.MasterName;
DyMo=myinputs.DyMo;
% initialize persistent variables in priordens() % initialize persistent variables in priordens()
priordens(xparam1,bayestopt_.pshape,bayestopt_.p6,bayestopt_.p7, ... priordens(xparam1,bayestopt_.pshape,bayestopt_.p6,bayestopt_.p7, ...
bayestopt_.p3,bayestopt_.p4,1); bayestopt_.p3,bayestopt_.p4,1);
@ -154,13 +152,13 @@ for b = fblck:nblck,
elseif whoiam elseif whoiam
% keyboard; % keyboard;
waitbarString = ['Please wait... Metropolis-Hastings (' int2str(b) '/' int2str(options_.mh_nblck) ')...']; waitbarString = ['Please wait... Metropolis-Hastings (' int2str(b) '/' int2str(options_.mh_nblck) ')...'];
% waitbarTitle=['Metropolis-Hastings ',options_.parallel(ThisMatlab).PcName]; % waitbarTitle=['Metropolis-Hastings ',options_.parallel(ThisMatlab).ComputerName];
if options_.parallel(ThisMatlab).Local, if options_.parallel(ThisMatlab).Local,
waitbarTitle=['Local ']; waitbarTitle=['Local '];
else else
waitbarTitle=[options_.parallel(ThisMatlab).PcName]; waitbarTitle=[options_.parallel(ThisMatlab).ComputerName];
end end
fMessageStatus(0,whoiam,waitbarString, waitbarTitle, options_.parallel(ThisMatlab), MasterName, DyMo); fMessageStatus(0,whoiam,waitbarString, waitbarTitle, options_.parallel(ThisMatlab));
else, else,
hh = waitbar(0,['Please wait... Metropolis-Hastings (' int2str(b) '/' int2str(options_.mh_nblck) ')...']); hh = waitbar(0,['Please wait... Metropolis-Hastings (' int2str(b) '/' int2str(options_.mh_nblck) ')...']);
set(hh,'Name','Metropolis-Hastings'); set(hh,'Name','Metropolis-Hastings');
@ -204,7 +202,7 @@ for b = fblck:nblck,
if mod(j,50)==0 & whoiam if mod(j,50)==0 & whoiam
% keyboard; % keyboard;
waitbarString = [ '(' int2str(b) '/' int2str(options_.mh_nblck) '), ' sprintf('accept. %3.f%%%%', 100 * isux/j)]; waitbarString = [ '(' int2str(b) '/' int2str(options_.mh_nblck) '), ' sprintf('accept. %3.f%%%%', 100 * isux/j)];
fMessageStatus(prtfrc,whoiam,waitbarString, '', options_.parallel(ThisMatlab), MasterName, DyMo); fMessageStatus(prtfrc,whoiam,waitbarString, '', options_.parallel(ThisMatlab));
end end
else else
if mod(j, 3)==0 & ~whoiam if mod(j, 3)==0 & ~whoiam
@ -212,7 +210,7 @@ for b = fblck:nblck,
elseif mod(j,50)==0 & whoiam, elseif mod(j,50)==0 & whoiam,
% keyboard; % keyboard;
waitbarString = [ '(' int2str(b) '/' int2str(options_.mh_nblck) ') ' sprintf('%f done, acceptation rate %f',prtfrc,isux/j)]; waitbarString = [ '(' int2str(b) '/' int2str(options_.mh_nblck) ') ' sprintf('%f done, acceptation rate %f',prtfrc,isux/j)];
fMessageStatus(prtfrc,whoiam,waitbarString, waitbarTitle, options_.parallel(ThisMatlab), MasterName, DyMo); fMessageStatus(prtfrc,whoiam,waitbarString, waitbarTitle, options_.parallel(ThisMatlab));
end end
end end