diff --git a/matlab/PosteriorIRF.m b/matlab/PosteriorIRF.m index c78733e383101727c1ef345a16edc1ca3bdfcaa3..7f3bf0f8e8a6400f36d31a9e57e82272b15277e8 100644 --- a/matlab/PosteriorIRF.m +++ b/matlab/PosteriorIRF.m @@ -457,6 +457,8 @@ if ~exist('OCTAVE_VERSION') [fout] = masterParallel(options_.parallel, 1, M_.exo_nbr,NamFileInput,'PosteriorIRF_core2', localVars, globalVars, options_.parallel_info); end end +else + [fout] = PosteriorIRF_core2(localVars,1,M_.exo_nbr,0); end % END parallel code! diff --git a/matlab/dyn_saveas.m b/matlab/dyn_saveas.m index 7c14dd523c1a860ff373d6fcc162725c8531de91..12c580af9fc95a68d3018e42b53c98ce20132d55 100644 --- a/matlab/dyn_saveas.m +++ b/matlab/dyn_saveas.m @@ -31,6 +31,13 @@ function dyn_saveas(h,fname,DynareOptions) % along with Dynare. If not, see <http://www.gnu.org/licenses/>. if any(strcmp('eps',cellstr(DynareOptions.graph_format))) + if exist('OCTAVE_VERSION') + fname = strrep(fname,'/',filesep); + fname = strrep(fname,'\',filesep); + if DynareOptions.nodisplay && ispc, + set(h, 'Visible','on'); + end + end print(h,'-depsc2',[fname,'.eps']) end if any(strcmp('pdf',cellstr(DynareOptions.graph_format))) diff --git a/matlab/global_initialization.m b/matlab/global_initialization.m index ef312e8f8a61c6907328ec941ad4c2d6d589b61e..e351845cee610ef5d738dddadeb22bee6165663b 100644 --- a/matlab/global_initialization.m +++ b/matlab/global_initialization.m @@ -370,6 +370,7 @@ options_.mh_autocorrelation_function_size = 30; options_.plot_priors = 1; options_.cova_compute = 1; options_.parallel = 0; +options_.parallel_info.isHybridMatlabOctave = false; options_.parallel_info.leaveSlaveOpen = 0; options_.parallel_info.RemoteTmpFolder = ''; options_.number_of_grid_points_for_kde = 2^9; diff --git a/matlab/parallel/AnalyseComputationalEnvironment.m b/matlab/parallel/AnalyseComputationalEnvironment.m index ab8465a38f3daec0476cc01445d0e4bfa54e7dc9..f3bf88c36f8fc14daa69521655aab0a86d635c5f 100644 --- a/matlab/parallel/AnalyseComputationalEnvironment.m +++ b/matlab/parallel/AnalyseComputationalEnvironment.m @@ -189,13 +189,13 @@ for Node=1:length(DataInput) % To obtain a recoursive function remove the 'for' end if (si1) - disp(['It is impossibile to be connected to the computer with name "',DataInput(Node).ComputerName,'" using the network!']); + disp(['It is impossibile to ping to the computer with name "',DataInput(Node).ComputerName,'" using the network!']); disp(' '); disp('ErrorCode 3.'); ErrorCode=3; disp(' '); disp(' '); - return; +% return; else disp('Check on ComputerName Variable ..... Ok!'); disp(' '); @@ -609,13 +609,13 @@ for Node=1:length(DataInput) % To obtain a recoursive function remove the 'for' RealCPUnbr=''; % keyboard; - RealCPUnbr=GiveCPUnumber(de0); + RealCPUnbr=GiveCPUnumber(de0,Environment); % Questo controllo penso che si possa MIGLIORARE!!!!! if isempty (RealCPUnbr) && Environment==0, [si0 de0]=system(['psinfo \\',DataInput(Node).ComputerName]); end - RealCPUnbr=GiveCPUnumber(de0); + RealCPUnbr=GiveCPUnumber(de0,Environment); if isempty (RealCPUnbr) % An error occurred when we try to know the Cpu/Cores diff --git a/matlab/parallel/GiveCPUnumber.m b/matlab/parallel/GiveCPUnumber.m index 355d48506e5e465d02ab57b943832092c7ede367..c858d258fdd5ea6324ec341203a9ea5ccfebfe7b 100644 --- a/matlab/parallel/GiveCPUnumber.m +++ b/matlab/parallel/GiveCPUnumber.m @@ -1,4 +1,4 @@ -function [nCPU]= GiveCPUnumber (ComputerInformations) +function [nCPU]= GiveCPUnumber (ComputerInformations, Environment) % PARALLEL CONTEXT % In a parallel context this function return the CPUs or cores numer avaiable % on the computer used for run parallel code. @@ -33,13 +33,13 @@ function [nCPU]= GiveCPUnumber (ComputerInformations) nCPU=''; -Enviroment=-1; - +if nargin < 2, % Determine a specific operating system or software version when necessary % for different command (sintax, name, ...). -Enviroment=~ispc; %isunix || (~matlab_ver_less_than('7.4') && ismac); +Environment=~ispc; %isunix || (~matlab_ver_less_than('7.4') && ismac); +end -switch Enviroment +switch Environment case 0 %WINDOWS OPERATING SYSTEM OffSet=27; diff --git a/matlab/parallel/InitializeComputationalEnvironment.m b/matlab/parallel/InitializeComputationalEnvironment.m index 151869fad3a27ccd43fd479d885bb1468b3d9c6f..529ef60bad4e5be1a0782c8f6c28f9491caebe66 100644 --- a/matlab/parallel/InitializeComputationalEnvironment.m +++ b/matlab/parallel/InitializeComputationalEnvironment.m @@ -45,6 +45,7 @@ end global options_ +isHybridMatlabOctave = false; for j=1:length(options_.parallel), if isempty(options_.parallel(j).MatlabOctavePath), if exist('OCTAVE_VERSION') @@ -57,8 +58,14 @@ for j=1:length(options_.parallel), dynareroot = strrep(which('dynare'),'dynare.m',''); options_.parallel(j).DynarePath=dynareroot; end + isHybridMatlabOctave = isHybridMatlabOctave || any(regexpi([options_.parallel(j).MatlabOctavePath], 'octave')); +end +isHybridMatlabOctave = isHybridMatlabOctave && ~exist('OCTAVE_VERSION'); +options_.parallel_info.isHybridMatlabOctave = isHybridMatlabOctave; +if isHybridMatlabOctave, + % Reset dynare random generator and seed. + set_dynare_seed('default'); end - diff --git a/matlab/parallel/dynareParallelDir.m b/matlab/parallel/dynareParallelDir.m index 654db89f3c4439e1d389beb35bab6da1123db222..ac878071616eece5944a5e10b96b3e8a4fa6ab16 100644 --- a/matlab/parallel/dynareParallelDir.m +++ b/matlab/parallel/dynareParallelDir.m @@ -47,6 +47,12 @@ for indPC=1:length(Parallel), end if check ~= 0 || ~isempty(strfind(ax,'No such file or directory')); ax=[]; + else + indax=regexp(ax,'\n'); + colax=indax(1); + rowax=length(indax); + ax=reshape(ax',[colax rowax])'; + ax=ax(:,1:end-1); end else @@ -67,7 +73,6 @@ for indPC=1:length(Parallel), end end - dirlist = char(dirlist, ax); else if exist('OCTAVE_VERSION'), % Patch for peculiar behaviour of ls under Windows. if Parallel(indPC).Local==0, @@ -92,6 +97,10 @@ for indPC=1:length(Parallel), ax=ls(filename); end end + end + if isempty(dirlist), + dirlist=ax; + elseif ~isempty(ax), dirlist = char(dirlist, ax); end end diff --git a/matlab/parallel/dynareParallelGetNewFiles.m b/matlab/parallel/dynareParallelGetNewFiles.m index 6a4e6cec080a32eb3341f70219873fd32b1f5086..be9a08f8e80af39c5dd2b9083f49a770675784cf 100644 --- a/matlab/parallel/dynareParallelGetNewFiles.m +++ b/matlab/parallel/dynareParallelGetNewFiles.m @@ -47,6 +47,7 @@ for indPC=1:length(Parallel), end if ~isempty(NewFilesFromSlaves) + pause(1); for i=1:length(NewFilesFromSlaves) SlashNumberAndPosition=[]; diff --git a/matlab/parallel/masterParallel.m b/matlab/parallel/masterParallel.m index 7d7df87fe312c65e9cc249be494badd93b955adb..40a2f8157201a66e2a5118d2ddac30e2bf7f3fcd 100644 --- a/matlab/parallel/masterParallel.m +++ b/matlab/parallel/masterParallel.m @@ -81,6 +81,7 @@ persistent PRCDir Strategy=Parallel_info.leaveSlaveOpen; islocal = 1; +isHybridMatlabOctave = Parallel_info.isHybridMatlabOctave; for j=1:length(Parallel), islocal=islocal*Parallel(j).Local; end @@ -106,6 +107,29 @@ if exist('OCTAVE_VERSION'), warning('off'); end +% check if there are function_handles in the input or global vars when +% octave is used +if isHybridMatlabOctave || exist('OCTAVE_VERSION'), + fInputNames = fieldnames(fInputVar); + for j=1:length(fInputNames), + TargetVar = fInputVar.(fInputNames{j}); + if isa(TargetVar,'function_handle'), + TargetVar=func2str(TargetVar); + fInputVar.(fInputNames{j})=TargetVar; + end + end + + if exist('fGlobalVar') && ~isempty(fGlobalVar), + fInputNames = fieldnames(fGlobalVar); + for j=1:length(fInputNames), + TargetVar = fGlobalVar.(fInputNames{j}); + if isa(TargetVar,'function_handle'), + TargetVar=func2str(TargetVar); + fGlobalVar.(fInputNames{j})=TargetVar; + end + end + end +end if Strategy==1 totCPU=0; @@ -292,14 +316,14 @@ for j=1:totCPU, if Parallel(indPC).Local == 1, % 0.1 Run on the local machine (localhost). if ~ispc || strcmpi('unix',Parallel(indPC).OperatingSystem), % Hybrid computing Windows <-> Unix! - if strfind([Parallel(indPC).MatlabOctavePath], 'octave') % Hybrid computing Matlab(Master)->Octave(Slaves) and Vice Versa! - command1=['octave --eval "default_save_options(''-v7''); addpath(''',Parallel(indPC).DynarePath,'''), dynareroot = dynare_config(); fParallel(',int2str(offset+1),',',int2str(sum(nBlockPerCPU(1:j))),',',int2str(j),',',int2str(indPC),',''',fname,''')" &']; + if regexpi([Parallel(indPC).MatlabOctavePath], 'octave') % Hybrid computing Matlab(Master)->Octave(Slaves) and Vice Versa! + command1=[Parallel(indPC).MatlabOctavePath,' -f --eval "default_save_options(''-v7''); addpath(''',Parallel(indPC).DynarePath,'''), dynareroot = dynare_config(); fParallel(',int2str(offset+1),',',int2str(sum(nBlockPerCPU(1:j))),',',int2str(j),',',int2str(indPC),',''',fname,''')" &']; else command1=[Parallel(indPC).MatlabOctavePath,' -nosplash -nodesktop -minimize ',compThread,' -r "addpath(''',Parallel(indPC).DynarePath,'''), dynareroot = dynare_config(); fParallel(',int2str(offset+1),',',int2str(sum(nBlockPerCPU(1:j))),',',int2str(j),',',int2str(indPC),',''',fname,''')" &']; end else % Hybrid computing Matlab(Master)->Octave(Slaves) and Vice Versa! - if strfind([Parallel(indPC).MatlabOctavePath], 'octave') - command1=['psexec -d -W ',DyMo, ' -a ',int2str(Parallel(indPC).CPUnbr(j-nCPU0)),' -low octave -f --eval "default_save_options(''-v7''); addpath(''',Parallel(indPC).DynarePath,'''), dynareroot = dynare_config(); fParallel(',int2str(offset+1),',',int2str(sum(nBlockPerCPU(1:j))),',',int2str(j),',',int2str(indPC),',''',fname,''')"']; + if regexpi([Parallel(indPC).MatlabOctavePath], 'octave') + command1=['psexec -d -W ',DyMo, ' -a ',int2str(Parallel(indPC).CPUnbr(j-nCPU0)),' -low ',Parallel(indPC).MatlabOctavePath,' -f --eval "default_save_options(''-v7''); addpath(''',Parallel(indPC).DynarePath,'''), dynareroot = dynare_config(); fParallel(',int2str(offset+1),',',int2str(sum(nBlockPerCPU(1:j))),',',int2str(j),',',int2str(indPC),',''',fname,''')"']; else command1=['psexec -d -W ',DyMo, ' -a ',int2str(Parallel(indPC).CPUnbr(j-nCPU0)),' -low ',Parallel(indPC).MatlabOctavePath,' -nosplash -nodesktop -minimize ',compThread,' -r "addpath(''',Parallel(indPC).DynarePath,'''), dynareroot = dynare_config(); fParallel(',int2str(offset+1),',',int2str(sum(nBlockPerCPU(1:j))),',',int2str(j),',',int2str(indPC),',''',fname,''')"']; end @@ -322,9 +346,9 @@ for j=1:totCPU, % To manage the diferences in Unix/Windows OS syntax. remoteFile=['remoteDynare',int2str(j)]; fidRemote=fopen([remoteFile,'.m'],'w+'); - if strfind([Parallel(indPC).MatlabOctavePath], 'octave'),% Hybrid computing Matlab(Master)->Octave(Slaves) and Vice Versa! + if regexpi([Parallel(indPC).MatlabOctavePath], 'octave'),% Hybrid computing Matlab(Master)->Octave(Slaves) and Vice Versa! remoteString=['default_save_options(''-v7''); addpath(''',Parallel(indPC).DynarePath,'''), dynareroot = dynare_config(); fParallel(',int2str(offset+1),',',int2str(sum(nBlockPerCPU(1:j))),',',int2str(j),',',int2str(indPC),',''',fname,''')']; - command1=[token, 'ssh ',ssh_token,' ',Parallel(indPC).UserName,'@',Parallel(indPC).ComputerName,' "cd ',Parallel(indPC).RemoteDirectory,'/',PRCDir, '; octave --eval ',remoteFile,' " &']; + command1=[token, 'ssh ',ssh_token,' ',Parallel(indPC).UserName,'@',Parallel(indPC).ComputerName,' "cd ',Parallel(indPC).RemoteDirectory,'/',PRCDir, '; ',Parallel(indPC).MatlabOctavePath,' -f --eval ',remoteFile,' " &']; else remoteString=['addpath(''',Parallel(indPC).DynarePath,'''), dynareroot = dynare_config(); fParallel(',int2str(offset+1),',',int2str(sum(nBlockPerCPU(1:j))),',',int2str(j),',',int2str(indPC),',''',fname,''')']; command1=[token, 'ssh ',ssh_token,' ',Parallel(indPC).UserName,'@',Parallel(indPC).ComputerName,' "cd ',Parallel(indPC).RemoteDirectory,'/',PRCDir, '; ',Parallel(indPC).MatlabOctavePath,' -nosplash -nodesktop -minimize ',compThread,' -r ',remoteFile,';" &']; @@ -336,9 +360,9 @@ for j=1:totCPU, else if ~strcmp(Parallel(indPC).ComputerName,MasterName), % 0.3 Run on a remote machine! % Hybrid computing Matlab(Master)-> Octave(Slaves) and Vice Versa! - if strfind([Parallel(indPC).MatlabOctavePath], 'octave') + if regexpi([Parallel(indPC).MatlabOctavePath], 'octave') command1=['psexec \\',Parallel(indPC).ComputerName,' -d -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 -f --eval "default_save_options(''-v7''); 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,' -f --eval "default_save_options(''-v7''); addpath(''',Parallel(indPC).DynarePath,'''), dynareroot = dynare_config(); fParallel(',int2str(offset+1),',',int2str(sum(nBlockPerCPU(1:j))),',',int2str(j),',',int2str(indPC),',''',fname,''')"']; else command1=['psexec \\',Parallel(indPC).ComputerName,' -d -e -u ',Parallel(indPC).UserName,' -p ',Parallel(indPC).Password,' -W ',Parallel(indPC).RemoteDrive,':\',Parallel(indPC).RemoteDirectory,'\',PRCDir,'\ -a ',int2str(Parallel(indPC).CPUnbr(j-nCPU0)), ... @@ -346,9 +370,9 @@ for j=1:totCPU, end else % 0.4 Run on the local machine via the network % Hybrid computing Matlab(Master)->Octave(Slaves) and Vice Versa! - if strfind([Parallel(indPC).MatlabOctavePath], 'octave') + if regexpi([Parallel(indPC).MatlabOctavePath], 'octave') command1=['psexec \\',Parallel(indPC).ComputerName,' -d -e -W ',Parallel(indPC).RemoteDrive,':\',Parallel(indPC).RemoteDirectory,'\',PRCDir,'\ -a ',int2str(Parallel(indPC).CPUnbr(j-nCPU0)), ... - ' -low octave -f --eval "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,' -f --eval "default_save_options(''-v7''); addpath(''',Parallel(indPC).DynarePath,'''), dynareroot = dynare_config(); fParallel(',int2str(offset+1),',',int2str(sum(nBlockPerCPU(1:j))),',',int2str(j),',',int2str(indPC),',''',fname,''')"']; else command1=['psexec \\',Parallel(indPC).ComputerName,' -d -e -W ',Parallel(indPC).RemoteDrive,':\',Parallel(indPC).RemoteDirectory,'\',PRCDir,'\ -a ',int2str(Parallel(indPC).CPUnbr(j-nCPU0)), ... ' -low ',Parallel(indPC).MatlabOctavePath,' -nosplash -nodesktop -minimize ',compThread,' -r "addpath(''',Parallel(indPC).DynarePath,'''), dynareroot = dynare_config(); fParallel(',int2str(offset+1),',',int2str(sum(nBlockPerCPU(1:j))),',',int2str(j),',',int2str(indPC),',''',fname,''')"']; @@ -361,14 +385,14 @@ for j=1:totCPU, case 1 if Parallel(indPC).Local == 1 && newInstance, % 1.1 Run on the local machine. if (~ispc || strcmpi('unix',Parallel(indPC).OperatingSystem)), % Hybrid computing Windows <-> Unix! - if strfind([Parallel(indPC).MatlabOctavePath], 'octave') % Hybrid computing Matlab(Master)-> Octave(Slaves) and Vice Versa! - command1=['octave --eval "default_save_options(''-v7''); addpath(''',Parallel(indPC).DynarePath,'''), dynareroot = dynare_config(); slaveParallel(',int2str(j),',',int2str(indPC),')" &']; + if regexpi([Parallel(indPC).MatlabOctavePath], 'octave') % Hybrid computing Matlab(Master)-> Octave(Slaves) and Vice Versa! + command1=[Parallel(indPC).MatlabOctavePath,' -f --eval "default_save_options(''-v7''); addpath(''',Parallel(indPC).DynarePath,'''), dynareroot = dynare_config(); slaveParallel(',int2str(j),',',int2str(indPC),')" &']; else command1=[Parallel(indPC).MatlabOctavePath,' -nosplash -nodesktop -minimize ',compThread,' -r "addpath(''',Parallel(indPC).DynarePath,'''), dynareroot = dynare_config(); slaveParallel(',int2str(j),',',int2str(indPC),')" &']; end else % Hybrid computing Matlab(Master)->Octave(Slaves) and Vice Versa! - if strfind([Parallel(indPC).MatlabOctavePath], 'octave') - command1=['psexec -d -W ',DyMo, ' -a ',int2str(Parallel(indPC).CPUnbr(j-nCPU0)),' -low octave --eval "default_save_options(''-v7'');addpath(''',Parallel(indPC).DynarePath,'''), dynareroot = dynare_config(); slaveParallel(',int2str(j),',',int2str(indPC),')"']; + if regexpi([Parallel(indPC).MatlabOctavePath], 'octave') + command1=['psexec -d -W ',DyMo, ' -a ',int2str(Parallel(indPC).CPUnbr(j-nCPU0)),' -low ',Parallel(indPC).MatlabOctavePath,' -f --eval "default_save_options(''-v7'');addpath(''',Parallel(indPC).DynarePath,'''), dynareroot = dynare_config(); slaveParallel(',int2str(j),',',int2str(indPC),')"']; else command1=['psexec -d -W ',DyMo, ' -a ',int2str(Parallel(indPC).CPUnbr(j-nCPU0)),' -low ',Parallel(indPC).MatlabOctavePath,' -nosplash -nodesktop -minimize ',compThread,' -r "addpath(''',Parallel(indPC).DynarePath,'''), dynareroot = dynare_config(); slaveParallel(',int2str(j),',',int2str(indPC),')"']; end @@ -395,9 +419,9 @@ for j=1:totCPU, % To manage the diferences in Unix/Windows OS syntax. remoteFile=['remoteDynare',int2str(j)]; fidRemote=fopen([remoteFile,'.m'],'w+'); - if strfind([Parallel(indPC).MatlabOctavePath], 'octave') % Hybrid computing Matlab(Master)-> Octave(Slaves) and Vice Versa! + if regexpi([Parallel(indPC).MatlabOctavePath], 'octave') % Hybrid computing Matlab(Master)-> Octave(Slaves) and Vice Versa! remoteString=['default_save_options(''-v7''); addpath(''',Parallel(indPC).DynarePath,'''), dynareroot = dynare_config(); slaveParallel(',int2str(j),',',int2str(indPC),');']; - command1=[token, 'ssh ',ssh_token,' ',Parallel(indPC).UserName,'@',Parallel(indPC).ComputerName,' "cd ',Parallel(indPC).RemoteDirectory,'/',PRCDir '; octave --eval ',remoteFile,' " &']; + command1=[token, 'ssh ',ssh_token,' ',Parallel(indPC).UserName,'@',Parallel(indPC).ComputerName,' "cd ',Parallel(indPC).RemoteDirectory,'/',PRCDir '; ',Parallel(indPC).MatlabOctavePath,' -f --eval ',remoteFile,' " &']; else remoteString=['addpath(''',Parallel(indPC).DynarePath,'''), dynareroot = dynare_config(); slaveParallel(',int2str(j),',',int2str(indPC),');']; command1=[token, 'ssh ',ssh_token,' ',Parallel(indPC).UserName,'@',Parallel(indPC).ComputerName,' "cd ',Parallel(indPC).RemoteDirectory,'/',PRCDir '; ',Parallel(indPC).MatlabOctavePath,' -nosplash -nodesktop -minimize ',compThread,' -r ',remoteFile,';" &']; @@ -409,18 +433,18 @@ for j=1:totCPU, else if ~strcmp(Parallel(indPC).ComputerName,MasterName), % 1.3 Run on a remote machine. % Hybrid computing Matlab(Master)->Octave(Slaves) and Vice Versa! - if strfind([Parallel(indPC).MatlabOctavePath], 'octave') + if regexpi([Parallel(indPC).MatlabOctavePath], 'octave') command1=['psexec \\',Parallel(indPC).ComputerName,' -d -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 -f --eval "default_save_options(''-v7'');addpath(''',Parallel(indPC).DynarePath,'''), dynareroot = dynare_config(); slaveParallel(',int2str(j),',',int2str(indPC),')"']; + ' -low ',Parallel(indPC).MatlabOctavePath,' -f --eval "default_save_options(''-v7'');addpath(''',Parallel(indPC).DynarePath,'''), dynareroot = dynare_config(); slaveParallel(',int2str(j),',',int2str(indPC),')"']; else command1=['psexec \\',Parallel(indPC).ComputerName,' -d -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).MatlabOctavePath,' -nosplash -nodesktop -minimize ',compThread,' -r "addpath(''',Parallel(indPC).DynarePath,'''), dynareroot = dynare_config(); slaveParallel(',int2str(j),',',int2str(indPC),')"']; end else % 1.4 Run on the local machine via the network. % Hybrid computing Matlab(Master)->Octave(Slaves) and Vice Versa! - if strfind([Parallel(indPC).MatlabOctavePath], 'octave') + if regexpi([Parallel(indPC).MatlabOctavePath], 'octave') command1=['psexec \\',Parallel(indPC).ComputerName,' -d -e -W ',Parallel(indPC).RemoteDrive,':\',Parallel(indPC).RemoteDirectory,'\',PRCDir,'\ -a ',int2str(Parallel(indPC).CPUnbr(j-nCPU0)), ... - ' -low octave -f --eval "default_save_options(''-v7''); addpath(''',Parallel(indPC).DynarePath,'''), dynareroot = dynare_config(); slaveParallel(',int2str(j),',',int2str(indPC),')"']; + ' -low ',Parallel(indPC).MatlabOctavePath,' -f --eval "default_save_options(''-v7''); addpath(''',Parallel(indPC).DynarePath,'''), dynareroot = dynare_config(); slaveParallel(',int2str(j),',',int2str(indPC),')"']; else command1=['psexec \\',Parallel(indPC).ComputerName,' -d -e -W ',Parallel(indPC).RemoteDrive,':\',Parallel(indPC).RemoteDirectory,'\',PRCDir,'\ -a ',int2str(Parallel(indPC).CPUnbr(j-nCPU0)), ... ' -low ',Parallel(indPC).MatlabOctavePath,' -nosplash -nodesktop -minimize ',compThread,' -r "addpath(''',Parallel(indPC).DynarePath,'''), dynareroot = dynare_config(); slaveParallel(',int2str(j),',',int2str(indPC),')"']; @@ -674,7 +698,14 @@ while (ForEver) % 1. The files .log and .txt are not copied. % 2. The comp_status_*.mat files are managed separately. - PRCDirSnapshot=dynareParallelGetNewFiles(PRCDir,Parallel(1:totSlaves),PRCDirSnapshot); + if exist('OCTAVE_VERSION'), % to avoid synchronism problems + try + PRCDirSnapshot=dynareParallelGetNewFiles(PRCDir,Parallel(1:totSlaves),PRCDirSnapshot); + catch + end + else + PRCDirSnapshot=dynareParallelGetNewFiles(PRCDir,Parallel(1:totSlaves),PRCDirSnapshot); + end if isempty(dynareParallelDir(['P_',fname,'_*End.txt'],PRCDir,Parallel(1:totSlaves))); HoTuttiGliOutput=0; @@ -683,6 +714,9 @@ while (ForEver) % Checking if the remote computation is finished and if we copied all the output here. if ~isempty(dir([fname,'_output_',int2str(j),'.mat'])) HoTuttiGliOutput=HoTuttiGliOutput+1; + else + indPC=min(find(nCPU>=j)); + dynareParallelGetFiles([fname,'_output_',int2str(j),'.mat'],PRCDir,Parallel(indPC)); end end @@ -712,31 +746,65 @@ end % Load and format remote output. iscrash = 0; +PRCDirSnapshot=dynareParallelGetNewFiles(PRCDir,Parallel(1:totSlaves),PRCDirSnapshot); for j=1:totCPU, indPC=min(find(nCPU>=j)); - % Already done above. - % dynareParallelGetFiles([fname,'_output_',int2str(j),'.mat'],PRCDir,Parallel(indPC)); load([fname,'_output_',int2str(j),'.mat'],'fOutputVar'); delete([fname,'_output_',int2str(j),'.mat']); if isfield(fOutputVar,'OutputFileName'), % Check if input files have been updated! - OutputFileName=fOutputVar.OutputFileName; + OutputFileName=fOutputVar.OutputFileName; + tmp0=''; for i=1:size(NamFileInput,1), - if i==1, - tmp0=dynareParallelDir([NamFileInput{i,:}],PRCDir,Parallel(indPC)); - else - tmp0=char(tmp0,dynareParallelDir([NamFileInput{i,:}],PRCDir,Parallel(indPC))); + FileList = regexp(strrep(PRCDirSnapshot{indPC},'\','/'),strrep(strrep([NamFileInput{i,:}],'\','/'),'*','(\w*)'),'match'); + for k=1:length(FileList), + if ~isempty(FileList{k}), + if isempty(tmp0), + tmp0=FileList{k}{1}; + else + tmp0=char(tmp0,FileList{k}{1}); + end + end end end - for l=1:size(OutputFileName,1), - tmp1=dynareParallelDir([OutputFileName{l,:}],PRCDir,Parallel(indPC)); + for i=1:size(OutputFileName,1), + tmp1=''; + FileList = regexp(cellstr(tmp0),strrep(strrep([OutputFileName{i,:}],'\','/'),'*','(\w*)'),'match'); + FileList0 = regexp(cellstr(tmp0),strrep([OutputFileName{i,2}],'*','(\w*)'),'match'); + for k=1:length(FileList), + if ~isempty(FileList{k}), + if isempty(tmp1), + tmp1=FileList0{k}{1}; + else + tmp1=char(tmp1,FileList0{k}{1}); + end + end + end for k=1:size(tmp1,1), - if any(strcmp(tmp1(k,:),cellstr(tmp0))), - dynareParallelGetFiles([OutputFileName(l,1) {tmp1(k,:)}],PRCDir,Parallel(indPC)); + dynareParallelGetFiles([OutputFileName(i,1) {tmp1(k,:)}],PRCDir,Parallel(indPC)); + end + end + % check if some output file is missing! + for i=1:size(OutputFileName,1), + tmp1=dynareParallelDir([OutputFileName{i,:}],PRCDir,Parallel(indPC)); + tmp1 = regexp(cellstr(tmp1),strrep([OutputFileName{i,2}],'*','(\w*)'),'match'); + tmp1 = char(tmp1{:}); + tmp2=ls([OutputFileName{i,:}]); + for ij=1:size(tmp1,1), + icheck = regexp(cellstr(tmp2),tmp1(ij,:),'once'); + isOutputFileMissing=1; + for ik=1:size(tmp2,1), + if ~isempty(icheck{ik}), + isOutputFileMissing=0; + end + end + if isOutputFileMissing, + dynareParallelGetFiles([OutputFileName(i,1) {tmp1(ij,:)}],PRCDir,Parallel(indPC)); end end end + end if isfield(fOutputVar,'error'), disp(['Job number ',int2str(j),' crashed with error:']); @@ -767,7 +835,7 @@ dynareParallelGetFiles('*.log',PRCDir,Parallel(1:totSlaves)); switch Strategy case 0 - for indPC=1:length(Parallel) + for indPC=1:min(find(nCPU>=totCPU)), if Parallel(indPC).Local == 0 dynareParallelRmDir(PRCDir,Parallel(indPC)); end @@ -783,9 +851,6 @@ switch Strategy end mydelete(['*_core*_input*.mat']); - % if Parallel(indPC).Local == 1 - % delete(['slaveParallel_input*.mat']); - % end end @@ -803,7 +868,7 @@ switch Strategy delete ConcurrentCommand1.bat end dynareParallelDelete(['comp_status_',fname,'*.mat'],PRCDir,Parallel); - for indPC=1:length(Parallel) + for indPC=1:min(find(nCPU>=totCPU)), if Parallel(indPC).Local == 0, dynareParallelDeleteNewFiles(PRCDir,Parallel(indPC),PRCDirSnapshotInit(indPC),'.log'); for ifil=1:size(NamFileInput,1), diff --git a/matlab/set_dynare_seed.m b/matlab/set_dynare_seed.m index 944d11e509c357b62c2daf3411f43b25efdd6d91..0ebf223aa12cac250f72ad292d045ea48845891f 100644 --- a/matlab/set_dynare_seed.m +++ b/matlab/set_dynare_seed.m @@ -24,7 +24,7 @@ if ~nargin error('set_dynare_seed:: I need at least one input argument!') end -matlab_random_streams = ~(exist('OCTAVE_VERSION') || matlab_ver_less_than('7.7')); +matlab_random_streams = ~(exist('OCTAVE_VERSION') || matlab_ver_less_than('7.7') || options_.parallel_info.isHybridMatlabOctave); if matlab_random_streams% Use new matlab interface. if nargin==1