diff --git a/matlab/dynare_sensitivity.m b/matlab/dynare_sensitivity.m
index 56803fec0111371e1ff46bcf607c388eac3164b0..38a975d45214fc6238307d25530f62b73a80872a 100644
--- a/matlab/dynare_sensitivity.m
+++ b/matlab/dynare_sensitivity.m
@@ -289,24 +289,42 @@ if options_gsa.rmse,
                options_.filtered_vars=0;               
            end
 %             dynare_MC([],OutputDirectoryName,data,rawdata,data_info);
-            prior_posterior_statistics('gsa',dataset_);
-            if options_.bayesian_irf
-                PosteriorIRF('gsa');
+        if options_gsa.pprior
+            TmpDirectoryName = ([M_.dname filesep 'gsa' filesep 'prior']);
+        else
+            TmpDirectoryName = ([M_.dname filesep 'gsa' filesep 'mc']);
+        end
+        if exist(TmpDirectoryName,'dir');
+            mydelete([M_.fname '_filter_step_ahead*.mat'],[TmpDirectoryName filesep]);
+            mydelete([M_.fname '_inno*.mat'],[TmpDirectoryName filesep]);
+            mydelete([M_.fname '_smooth*.mat'],[TmpDirectoryName filesep]);
+            mydelete([M_.fname '_update*.mat'],[TmpDirectoryName filesep]);
+            filparam = dir([TmpDirectoryName filesep M_.fname '_param*.mat']);
+            for j=1:length(filparam),
+                if isempty(strmatch([M_.fname '_param_irf'],filparam(j).name))
+                    delete([TmpDirectoryName filesep filparam(j).name]);
+                end
             end
-            options_gsa.load_rmse=0;
-            %   else
-            %     if options_gsa.load_rmse==0,
-            %       disp('You already saved a MC filter/smoother analysis ')
-            %       disp('Do you want to overwrite ?')
-            %       pause;
-            %       if options_gsa.pprior
-            %         delete([OutputDirectoryName,'/',fname_,'_prior_*.mat'])
-            %       else
-            %         delete([OutputDirectoryName,'/',fname_,'_mc_*.mat'])
-            %       end
-            %       dynare_MC([],OutputDirectoryName);
-            %       options_gsa.load_rmse=0;
-            %     end    
+            
+        end
+        prior_posterior_statistics('gsa',dataset_);
+        if options_.bayesian_irf
+            PosteriorIRF('gsa');
+        end
+        options_gsa.load_rmse=0;
+        %   else
+        %     if options_gsa.load_rmse==0,
+        %       disp('You already saved a MC filter/smoother analysis ')
+        %       disp('Do you want to overwrite ?')
+        %       pause;
+        %       if options_gsa.pprior
+        %         delete([OutputDirectoryName,'/',fname_,'_prior_*.mat'])
+        %       else
+        %         delete([OutputDirectoryName,'/',fname_,'_mc_*.mat'])
+        %       end
+        %       dynare_MC([],OutputDirectoryName);
+        %       options_gsa.load_rmse=0;
+        %     end
             
         end
     end
diff --git a/matlab/gsa/filt_mc_.m b/matlab/gsa/filt_mc_.m
index 00a4ecbd4f6f836b2011733207d892a26a33184a..04ebe0bfd3dff093673792d7bef8c29ae4087244 100644
--- a/matlab/gsa/filt_mc_.m
+++ b/matlab/gsa/filt_mc_.m
@@ -310,9 +310,6 @@ else
                     dyn_saveas(hh,[OutDir '/' fname_ '_rmse_mc_lnprior',int2str(ifig) ],options_);
                 end
             end
-            if ~options_.nodisplay
-                close(hh);
-            end
         end
     end
     ifig=0;
@@ -341,9 +338,6 @@ else
                     dyn_saveas(hh,[OutDir '/' fname_ '_rmse_mc_lnlik',int2str(ifig) ],options_);
                 end
             end
-            if ~options_.nodisplay
-                close(hh);
-            end
         end
     end
     ifig=0;
@@ -372,9 +366,6 @@ else
                     dyn_saveas(hh,[OutDir '/' fname_ '_rmse_mc_lnpost',int2str(ifig)],options_);
                 end
             end
-            if ~options_.nodisplay
-                close(hh);
-            end
         end
     end
     end
@@ -524,7 +515,6 @@ else
             end
         end
     end
-    close all
     end
     
     for j=1:size(SP,2),
diff --git a/matlab/gsa/map_ident_.m b/matlab/gsa/map_ident_.m
index 49b737935c7c95dd615ec316e0f5b5e2fe515d08..1b848ba71b06a70401f1c03107420bcd48617191 100644
--- a/matlab/gsa/map_ident_.m
+++ b/matlab/gsa/map_ident_.m
@@ -100,9 +100,6 @@ if opt_gsa.load_ident_files==0,
       title(M_.exo_names(j,:),'interpreter','none')
       if mod(j,6)==0 | j==M_.exo_nbr,
         dyn_saveas(hh,[OutputDirectoryName,'/',fname_,'_vdec_exo_',int2str(ifig)],options_);  
-        if ~options_.nodisplay
-            close(hh);
-        end      
       end
     end
   end
@@ -226,9 +223,6 @@ if opt_gsa.morris==1,
   xlabel(' ')
   title('All variance decomposition')
   dyn_saveas(hh,[OutputDirectoryName,'/',fname_,'_morris_vdec'],options_);
-  if ~options_.nodisplay
-    close(hh);
-  end
   else
   save([OutputDirectoryName,'/',fname_,'_morris_IDE'],'vdec')
     
@@ -745,9 +739,6 @@ if opt_gsa.morris==1,
   xlabel(' ')
   title('\mu in the model')
   dyn_saveas(hh,[OutputDirectoryName,'/',fname_,'_morrismu_par'],options_);
-  if ~options_.nodisplay
-    close(hh);
-  end
 
   hh=dyn_figure(options_); %bar(SAsignorm(:,irel))
 %   boxplot(SAsignorm','whis',10,'symbol','r.')
@@ -763,9 +754,6 @@ if opt_gsa.morris==1,
   xlabel(' ')
   title('\sigma in the model')
   dyn_saveas(hh,[OutputDirectoryName,'/',fname_,'_morrissig_par'],options_);
-  if ~options_.nodisplay
-    close(hh);
-  end
 
   %     figure, bar(SAnorm(:,irel)')
   %     set(gca,'xtick',[1:j0])
diff --git a/matlab/gsa/redform_map.m b/matlab/gsa/redform_map.m
index 5ec41de81641c9dce4fdf45e441445edee6269fd..35e7421e95493b50ca2f3d9c74975f059a33073b 100644
--- a/matlab/gsa/redform_map.m
+++ b/matlab/gsa/redform_map.m
@@ -141,9 +141,6 @@ for j=1:size(anamendo,1)
                         if ~options_.nograph,
                             hf=dyn_figure(options_); hist(y0,30), title([namendo,' vs. ', namexo])
                             dyn_saveas(hf,[xdir,'/', namendo,'_vs_', namexo],options_);
-                            if ~options_.nodisplay
-                                close(hf);
-                            end
                         end
                         %             if ~isempty(iy),
                         %               si(:,js) = redform_private(x0(iy,:), y0(iy), pshape, pd, iload, pnames, namendo, namexo, xdir, options_gsa_);
@@ -198,9 +195,6 @@ for j=1:size(anamendo,1)
                     title([logflag,' ',namendo,' vs. ',namexo],'interpreter','none')
                     if iplo==9,
                         dyn_saveas(hfig,[dirname,'/',M_.fname,'_redform_', namendo,'_vs_shocks_',logflag,num2str(ifig)],options_);
-                        if ~options_.nodisplay
-                            close(hfig);
-                        end
                     end
                 end
                 
@@ -209,9 +203,6 @@ for j=1:size(anamendo,1)
     end
     if iplo<9 && iplo>0 && ifig && ~options_.nograph,
         dyn_saveas(hfig,[dirname,'/',M_.fname,'_redform_', namendo,'_vs_shocks_',logflag,num2str(ifig)],options_);
-        if ~options_.nodisplay
-            close(hfig);
-        end
     end
     ifig=0;
     iplo=0;
@@ -252,9 +243,6 @@ for j=1:size(anamendo,1)
                         if ~options_.nograph,
                             hf=dyn_figure(options_); hist(y0,30), title([namendo,' vs. ', namlagendo])
                             dyn_saveas(hf,[xdir,'/', namendo,'_vs_', namlagendo],options_);
-                            if ~options_.nodisplay
-                                close(hf);
-                            end
                         end
                         if ~isempty(iy) && ~isempty(iyc),
                             delete([xdir, '/*cut*.*'])
@@ -305,9 +293,6 @@ for j=1:size(anamendo,1)
                     title([logflag,' ',namendo,' vs. ',namlagendo,'(-1)'],'interpreter','none')
                     if iplo==9,
                         dyn_saveas(hfig,[dirname,'/',M_.fname,'_redform_', namendo,'_vs_lags_',logflag,num2str(ifig)],options_);
-                        if ~options_.nodisplay
-                            close(hfig);
-                        end
                     end
                 end
                 
@@ -316,9 +301,6 @@ for j=1:size(anamendo,1)
     end
     if iplo<9 && iplo>0 && ifig && ~options_.nograph,
         dyn_saveas(hfig,[dirname,'/',M_.fname,'_redform_', namendo,'_vs_lags_',logflag,num2str(ifig)],options_);
-        if ~options_.nodisplay
-            close(hfig);
-        end
     end
 end
 
@@ -378,9 +360,6 @@ if iload==0,
     if ~options_.nograph,
         hfig=dyn_figure(options_); hist(y0,30), title([namy,' vs. ', namx])
         dyn_saveas(hfig,[xdir,'/', namy,'_vs_', namx],options_);
-        if ~options_.nodisplay
-            close(hfig);
-        end
     end
     %   gsa_ = gsa_sdp_dyn(y0, x0, -2, [],[],[],1,fname, pnames);
     nrun=length(y0);
@@ -396,7 +375,9 @@ if iload==0,
     gsa_.x0=x00(1:nfit,:);
     if ~options_.nograph,
         hfig=gsa_sdp_plot(gsa_,fname,pnames,iii(1:min(12,np)));
-        close(hfig);
+        if options_.nodisplay
+            close(hfig);
+        end
     end
     gsa_.x0=x0(1:nfit,:);
     %   copyfile([fname,'_est.mat'],[fname,'.mat'])
@@ -405,9 +386,6 @@ if iload==0,
         plot(y0(1:nfit),[gsa_.fit y0(1:nfit)],'.'),
         title([namy,' vs. ', namx,' fit'])
         dyn_saveas(hfig,[xdir,'/', namy,'_vs_', namx,'_fit'],options_);
-        if ~options_.nodisplay
-            close(hfig);
-        end
         if nfit<nrun,
             npred=[nfit+1:nrun];
             yf = ss_anova_fcast(x0(npred,:), gsa_);
@@ -415,9 +393,6 @@ if iload==0,
             plot(y0(npred),[yf y0(npred)],'.'),
             title([namy,' vs. ', namx,' pred'])
             dyn_saveas(hfig,[xdir,'/', namy,'_vs_', namx,'_pred'],options_);
-            if ~options_.nodisplay
-                close(hfig);
-            end
         end
         
     end
@@ -430,9 +405,6 @@ else
         plot(y0,[yf y0],'.'),
         title([namy,' vs. ', namx,' pred'])
         dyn_saveas(hfig,[xdir,'/', namy,'_vs_', namx,'_pred'],options_);
-        if ~options_.nodisplay
-            close(hfig);
-        end
     end
 end
 % si = gsa_.multivariate.si;
diff --git a/matlab/gsa/redform_screen.m b/matlab/gsa/redform_screen.m
index d907c244408b39c4ef79f861c9588f4a151a30d4..f218f26dc8c3936c0699ad5ba3c38d669e6e2d4b 100644
--- a/matlab/gsa/redform_screen.m
+++ b/matlab/gsa/redform_screen.m
@@ -91,9 +91,6 @@ for j=1:size(anamendo,1),
         title([namendo,' vs. ',namexo],'interpreter','none')
         if iplo==9,
           dyn_saveas(hh,[dirname,'/',M_.fname,'_', namendo,'_vs_shock_',num2str(ifig)],options_);  
-          if ~options_.nodisplay
-            close(hh);
-          end
         end
 
       end
@@ -101,9 +98,6 @@ for j=1:size(anamendo,1),
   end
   if iplo<9 && iplo>0 && ifig,
     dyn_saveas(hh,[dirname,'/',M_.fname,'_', namendo,'_vs_shocks_',num2str(ifig)],options_);
-    if ~options_.nodisplay
-      close(hh);
-    end
   end
 
   iplo=0;
@@ -138,9 +132,6 @@ for j=1:size(anamendo,1),
         title([namendo,' vs. ',namlagendo,'(-1)'],'interpreter','none')
         if iplo==9,
           dyn_saveas(hh,[dirname,'/',M_.fname,'_', namendo,'_vs_lags_',num2str(ifig)],options_);  
-          if ~options_.nodisplay
-            close(hh);
-          end
         end
       end
     end
diff --git a/matlab/gsa/stab_map_1.m b/matlab/gsa/stab_map_1.m
index 85df2d838b603da9c5e6c4786453eab6418adf90..77ff464d71247277a0a67b011318611c2da4a663 100644
--- a/matlab/gsa/stab_map_1.m
+++ b/matlab/gsa/stab_map_1.m
@@ -98,8 +98,5 @@ for i=1:ceil(nparplot/12),
     title([ftit{j},'. p-value ', num2str(proba(ipar(j)),2)],'interpreter','none')
   end
   dyn_saveas(hh,[dirname,'/',fname_,'_',aname,'_SA_',int2str(i)],options_);
-  if ~options_.nodisplay
-    close(hh);
-  end
 end
 end
diff --git a/matlab/gsa/stab_map_2.m b/matlab/gsa/stab_map_2.m
index 594fe91fa8e7d248f0c87ce079241a189481938d..402e1ba3058ac1b2975bdd0b09668a4c46fbd71e 100644
--- a/matlab/gsa/stab_map_2.m
+++ b/matlab/gsa/stab_map_2.m
@@ -110,9 +110,6 @@ for j=1:npar,
                 title(['cc = ',num2str(c0(i2(jx),j))])
                 if (mod(j2,12)==0) && j2>0,
                     dyn_saveas(hh,[dirname,'/',fig_nam_,int2str(ifig)],options_);
-                    if ~options_.nodisplay
-                        close(hh);
-                    end
                 end
                 end
             end
@@ -121,9 +118,6 @@ for j=1:npar,
     end
     if ~options_.nograph && (j==(npar)) && j2>0 && (mod(j2,12)~=0),
         dyn_saveas(hh,[dirname,'/',fig_nam_,int2str(ifig)],options_);
-        if ~options_.nodisplay
-            close(hh);
-        end
     end
     
 end
diff --git a/matlab/parallel/AnalyseComputationalEnvironment.m b/matlab/parallel/AnalyseComputationalEnvironment.m
index 2a8887df74c1abef86bf5b499c74d9d37e1eb844..ab8465a38f3daec0476cc01445d0e4bfa54e7dc9 100644
--- a/matlab/parallel/AnalyseComputationalEnvironment.m
+++ b/matlab/parallel/AnalyseComputationalEnvironment.m
@@ -31,6 +31,10 @@ function [ErrorCode] = AnalyseComputationalEnvironment(DataInput, DataInputAdd)
 %   field RemoteTmpFolder (the temporary directory created/destroyed on remote
 %   computer) is used.
 
+if ispc, 
+    [tempo, MasterName]=system('hostname');
+    MasterName=deblank(MasterName);
+end
 
 RemoteTmpFolder=DataInputAdd.RemoteTmpFolder;
 dynareParallelMkDir(RemoteTmpFolder,DataInput);
@@ -295,8 +299,13 @@ for Node=1:length(DataInput) % To obtain a recoursive function remove the 'for'
             
             si2=[];
             de2=[];
+            if ~isempty(DataInput(Node).Port),
+                ssh_token = ['-p ',DataInput(Node).Port];
+            else
+                ssh_token = '';
+            end
             
-            [si2 de2]=system(['ssh ',DataInput(Node).UserName,'@',DataInput(Node).ComputerName,' ls ',DataInput(Node).RemoteDirectory,'/',RemoteTmpFolder,'/']);
+            [si2 de2]=system(['ssh ',ssh_token,' ',DataInput(Node).UserName,'@',DataInput(Node).ComputerName,' ls ',DataInput(Node).RemoteDirectory,'/',RemoteTmpFolder,'/']);
             
             if (si2)
                 disp ('Remote Directory does not exist or is not reachable!');
@@ -332,7 +341,7 @@ for Node=1:length(DataInput) % To obtain a recoursive function remove the 'for'
             
             si2=[];
             de2=[];
-            [s12 de2]=system(['dir \\',DataInput(Node).ComputerName,'\',DataInput(Node).RemoteDrive,'$\',DataInput(Node).RemoteDirectory,'\',RemoteTmpFolder]);
+            [si2 de2]=system(['dir \\',DataInput(Node).ComputerName,'\',DataInput(Node).RemoteDrive,'$\',DataInput(Node).RemoteDirectory,'\',RemoteTmpFolder]);
             
             if (si2)
                 disp ('Remote Directory does not exist or it is not reachable!');
@@ -416,18 +425,32 @@ for Node=1:length(DataInput) % To obtain a recoursive function remove the 'for'
         % machine when the user is .UserName with password .Password and
         % the path is MatlabOctavePath.
         
-        if Environment
+        if Environment,
+            if ~isempty(DataInput(Node).Port),
+                ssh_token = ['-p ',DataInput(Node).Port];
+            else
+                ssh_token = '';
+            end
             if strfind([DataInput(Node).MatlabOctavePath], 'octave') % Hybrid computing Matlab(Master)->Octave(Slaves) and Vice Versa!
-                system(['ssh ',DataInput(Node).UserName,'@',DataInput(Node).ComputerName,' "cd ',DataInput(Node).RemoteDirectory,'/',RemoteTmpFolder,  '; ', DataInput(Node).MatlabOctavePath, ' Tracing.m;" &']);
+                system(['ssh ',ssh_token,' ',DataInput(Node).UserName,'@',DataInput(Node).ComputerName,' "cd ',DataInput(Node).RemoteDirectory,'/',RemoteTmpFolder,  '; ', DataInput(Node).MatlabOctavePath, ' Tracing.m;" &']);
             else
-                system(['ssh ',DataInput(Node).UserName,'@',DataInput(Node).ComputerName,' "cd ',DataInput(Node).RemoteDirectory,'/',RemoteTmpFolder,  '; ', DataInput(Node).MatlabOctavePath, ' -nosplash -nodesktop -minimize -r Tracing;" &']);
+                system(['ssh ',ssh_token,' ',DataInput(Node).UserName,'@',DataInput(Node).ComputerName,' "cd ',DataInput(Node).RemoteDirectory,'/',RemoteTmpFolder,  '; ', DataInput(Node).MatlabOctavePath, ' -nosplash -nodesktop -minimize -r Tracing;" &']);
             end
         else
-            if  strfind([DataInput(Node).MatlabOctavePath], 'octave') % Hybrid computing Matlab(Master)->Octave(Slaves) and Vice Versa!
-                [NonServeS NenServeD]=system(['start /B psexec \\',DataInput(Node).ComputerName,' -e -u ',DataInput(Node).UserName,' -p ',DataInput(Node).Password,' -W ',DataInput(Node).RemoteDrive,':\',DataInput(Node).RemoteDirectory,'\',RemoteTmpFolder ' -low   ',DataInput(Node).MatlabOctavePath,' Tracing.m']);
-            else
-                [NonServeS NenServeD]=system(['start /B psexec \\',DataInput(Node).ComputerName,' -e -u ',DataInput(Node).UserName,' -p ',DataInput(Node).Password,' -W ',DataInput(Node).RemoteDrive,':\',DataInput(Node).RemoteDirectory,'\',RemoteTmpFolder ' -low   ',DataInput(Node).MatlabOctavePath,' -nosplash -nodesktop -minimize -r Tracing']);
+            if ~strcmp(DataInput(Node).ComputerName,MasterName), % run on remote machine
+                if  strfind([DataInput(Node).MatlabOctavePath], 'octave') % Hybrid computing Matlab(Master)->Octave(Slaves) and Vice Versa!
+                    [NonServeS NenServeD]=system(['start /B psexec \\',DataInput(Node).ComputerName,' -e -u ',DataInput(Node).UserName,' -p ',DataInput(Node).Password,' -W ',DataInput(Node).RemoteDrive,':\',DataInput(Node).RemoteDirectory,'\',RemoteTmpFolder ' -low   ',DataInput(Node).MatlabOctavePath,' Tracing.m']);
+                else
+                    [NonServeS NenServeD]=system(['start /B psexec \\',DataInput(Node).ComputerName,' -e -u ',DataInput(Node).UserName,' -p ',DataInput(Node).Password,' -W ',DataInput(Node).RemoteDrive,':\',DataInput(Node).RemoteDirectory,'\',RemoteTmpFolder ' -low   ',DataInput(Node).MatlabOctavePath,' -nosplash -nodesktop -minimize -r Tracing']);
+                end
+            else % run on local machine via the network: user and passwd cannot be used!
+                if  strfind([DataInput(Node).MatlabOctavePath], 'octave') % Hybrid computing Matlab(Master)->Octave(Slaves) and Vice Versa!
+                    [NonServeS NenServeD]=system(['start /B psexec \\',DataInput(Node).ComputerName,' -e ',' -W ',DataInput(Node).RemoteDrive,':\',DataInput(Node).RemoteDirectory,'\',RemoteTmpFolder ' -low   ',DataInput(Node).MatlabOctavePath,' Tracing.m']);
+                else
+                    [NonServeS NenServeD]=system(['start /B psexec \\',DataInput(Node).ComputerName,' -e ',' -W ',DataInput(Node).RemoteDrive,':\',DataInput(Node).RemoteDirectory,'\',RemoteTmpFolder ' -low   ',DataInput(Node).MatlabOctavePath,' -nosplash -nodesktop -minimize -r Tracing']);
+                end
             end
+                
         end
         
         % Timer da fissare, nei valori di attesa!
@@ -568,10 +591,15 @@ for Node=1:length(DataInput) % To obtain a recoursive function remove the 'for'
         end
     else
         if Environment,
+            if ~isempty(DataInput(Node).Port),
+                ssh_token = ['-p ',DataInput(Node).Port];
+            else
+                ssh_token = '';
+            end
             if OStargetUnix,
-                [si0 de0]=system(['ssh ',DataInput(Node).UserName,'@',DataInput(Node).ComputerName,' grep processor /proc/cpuinfo']);
+                [si0 de0]=system(['ssh ',ssh_token,' ',DataInput(Node).UserName,'@',DataInput(Node).ComputerName,' grep processor /proc/cpuinfo']);
             else
-                [si0 de0]=system(['ssh ',DataInput(Node).UserName,'@',DataInput(Node).ComputerName,' psinfo']);
+                [si0 de0]=system(['ssh ',ssh_token,' ',DataInput(Node).UserName,'@',DataInput(Node).ComputerName,' psinfo']);
             end
         else
             [si0 de0]=system(['psinfo \\',DataInput(Node).ComputerName,' -u ',DataInput(Node).UserName,' -p ',DataInput(Node).Password]);
diff --git a/matlab/parallel/closeSlave.m b/matlab/parallel/closeSlave.m
index 01c4ee13f519afe3f8ca6d40e45f2044cf0e83ff..cb3c84ae4be27c9ea26a8010df9c6b3d5f02ae62 100644
--- a/matlab/parallel/closeSlave.m
+++ b/matlab/parallel/closeSlave.m
@@ -39,7 +39,7 @@ end
 s=warning('off');
 
 if partial==1
-    save('slaveParallel_break','partial')
+    save('slaveParallel_break.mat','partial')
     for indPC=1:length(Parallel),
         if (Parallel(indPC).Local==0),
             dynareParallelSendFiles('slaveParallel_break.mat',TmpFolder,Parallel(indPC));
@@ -63,12 +63,14 @@ for indPC=1:length(Parallel),
     if (Parallel(indPC).Local==0),
         dynareParallelDelete( 'slaveParallel_input*.mat',TmpFolder,Parallel(indPC));
     end
-    %else
+    
+   
     delete( 'slaveParallel_input*.mat');
+    delete( 'slaveJob*.mat');
     pause(1)
     delete(['slaveParallel_*.log']);
-    %end
     delete ConcurrentCommand1.bat;
+    
 end
 
 while(1)
@@ -76,7 +78,6 @@ while(1)
         for indPC=1:length(Parallel),
             if (Parallel(indPC).Local==0),
                 dynareParallelRmDir(TmpFolder,Parallel(indPC)),
-                
             end
         end
         break
diff --git a/matlab/parallel/dynareParallelDelete.m b/matlab/parallel/dynareParallelDelete.m
index 221bd62a638ec1b1b762b7dcc3c506308d19d26d..403e40e29eeb8fd0318c31513a3461314157a896 100644
--- a/matlab/parallel/dynareParallelDelete.m
+++ b/matlab/parallel/dynareParallelDelete.m
@@ -41,7 +41,12 @@ end
 
 for indPC=1:length(Parallel),
     if ~ispc || strcmpi('unix',Parallel(indPC).OperatingSystem),
-        [NonServeS NonServeD]=system(['ssh ',Parallel(indPC).UserName,'@',Parallel(indPC).ComputerName,' rm -f ',Parallel(indPC).RemoteDirectory,'/',pname,fname]);
+        if ~isempty(Parallel(indPC).Port),
+            ssh_token = ['-p ',Parallel(indPC).Port];
+        else
+            ssh_token = '';
+        end
+        [NonServeS NonServeD]=system(['ssh ',ssh_token,' ',Parallel(indPC).UserName,'@',Parallel(indPC).ComputerName,' rm -f ',Parallel(indPC).RemoteDirectory,'/',pname,fname]);
     else
         delete(['\\',Parallel(indPC).ComputerName,'\',Parallel(indPC).RemoteDrive,'$\',Parallel(indPC).RemoteDirectory,'\',pname,fname]);
     end
diff --git a/matlab/parallel/dynareParallelDeleteNewFiles.m b/matlab/parallel/dynareParallelDeleteNewFiles.m
index 797c8f841643c12313e62a2f53ba6d7efd258ff5..fc0975b133c8f38ff646ea7e70b871a61b9fb15b 100644
--- a/matlab/parallel/dynareParallelDeleteNewFiles.m
+++ b/matlab/parallel/dynareParallelDeleteNewFiles.m
@@ -1,4 +1,4 @@
-function dynareParallelDeleteNewFiles(PRCDir,Parallel,PRCDirSnapshot)
+function dynareParallelDeleteNewFiles(PRCDir,Parallel,PRCDirSnapshot,varargin)
 % PARALLEL CONTEXT
 % In a parallel context, this is a specialized function able to ...
 %
@@ -55,11 +55,17 @@ for indPC=1:length(Parallel),
                 sT(1)='.';
                 SlashNumberAndPosition=findstr(sT,fS);
                 fileaddress={sT(1:SlashNumberAndPosition(end)),sT(SlashNumberAndPosition(end)+1:end)};
+                exception_flag=0;
+                for indexc=1:length(varargin)
+                    exception_flag=exception_flag+(~isempty(strfind(fileaddress{2},varargin{indexc})));
+                end
+                if exception_flag==0,
                 dynareParallelDelete(fileaddress{2},[PRCDir,fS,fileaddress{1}],Parallel(indPC));
 
                 disp('New file deleted in remote -->');
                 disp(fileaddress{2});
                 disp('<--');
+                end
 
             end
         else
diff --git a/matlab/parallel/dynareParallelDir.m b/matlab/parallel/dynareParallelDir.m
index 08cb0706eeca5fb6bcd1171404ecafe8e314ae2f..654db89f3c4439e1d389beb35bab6da1123db222 100644
--- a/matlab/parallel/dynareParallelDir.m
+++ b/matlab/parallel/dynareParallelDir.m
@@ -31,14 +31,19 @@ dirlist=[];
 for indPC=1:length(Parallel),
     if ~ispc || strcmpi('unix',Parallel(indPC).OperatingSystem), %isunix || (~matlab_ver_less_than('7.4') && ismac),
         if Parallel(indPC).Local==0,
+            if ~isempty(Parallel(indPC).Port),
+                ssh_token = ['-p ',Parallel(indPC).Port];
+            else
+                ssh_token = '';
+            end
             if exist('OCTAVE_VERSION') % Patch for peculiar behaviour of ssh-ls under Linux.
                 % It is necessary to capture the ls warning message.
                 % To do it under the ssh protocol it is necessary to redirect the ls message in a text file.
                 % The file is 'OctaveStandardOutputMessage.txt' and it is
                 % saved in the Model directory.
-                [check, ax]=system(['ssh ',Parallel(indPC).UserName,'@',Parallel(indPC).ComputerName,' ls ',Parallel(indPC).RemoteDirectory,'/',PRCDir,'/',filename, ' 2> OctaveStandardOutputMessage.txt']);
+                [check, ax]=system(['ssh ',ssh_token,' ',Parallel(indPC).UserName,'@',Parallel(indPC).ComputerName,' ls ',Parallel(indPC).RemoteDirectory,'/',PRCDir,'/',filename, ' 2> OctaveStandardOutputMessage.txt']);
             else
-                [check, ax]=system(['ssh ',Parallel(indPC).UserName,'@',Parallel(indPC).ComputerName,' ls ',Parallel(indPC).RemoteDirectory,'/',PRCDir,'/',filename]);
+                [check, ax]=system(['ssh ',ssh_token,' ',Parallel(indPC).UserName,'@',Parallel(indPC).ComputerName,' ls ',Parallel(indPC).RemoteDirectory,'/',PRCDir,'/',filename]);
             end
             if check ~= 0 || ~isempty(strfind(ax,'No such file or directory'));
                 ax=[];
@@ -62,7 +67,7 @@ for indPC=1:length(Parallel),
             end
 
         end
-        dirlist = [dirlist, ax];
+        dirlist = char(dirlist, ax);
     else
         if exist('OCTAVE_VERSION'),     % Patch for peculiar behaviour of ls under Windows.
             if Parallel(indPC).Local==0,
@@ -87,6 +92,6 @@ for indPC=1:length(Parallel),
                 ax=ls(filename);
             end
         end
-        dirlist = [dirlist; ax];
+        dirlist = char(dirlist, ax);
     end
 end
diff --git a/matlab/parallel/dynareParallelGetFiles.m b/matlab/parallel/dynareParallelGetFiles.m
index 9c580d46e1e34e33a1cb75a4479f2170e5c5afd9..531594beed4a8d467d892d2d48a7f95562873c9f 100644
--- a/matlab/parallel/dynareParallelGetFiles.m
+++ b/matlab/parallel/dynareParallelGetFiles.m
@@ -36,6 +36,16 @@ NamFileInput0=NamFileInput;
 for indPC=1:length(Parallel),
     if Parallel(indPC).Local==0,
         if ~ispc || strcmpi('unix',Parallel(indPC).OperatingSystem), %isunix || (~matlab_ver_less_than('7.4') && ismac),
+            if ~isempty(Parallel(indPC).Port),
+                ssh_token = ['-p ',Parallel(indPC).Port];
+            else
+                ssh_token = '';
+            end
+            if ~isempty(Parallel(indPC).Port),
+                scp_token = ['-P ',Parallel(indPC).Port];
+            else
+                scp_token = '';
+            end
             if ischar(NamFileInput0),
                 for j=1:size(NamFileInput0,1),
                     NamFile(j,:)={['./'],deblank(NamFileInput0(j,:))};
@@ -51,13 +61,13 @@ for indPC=1:length(Parallel),
                     
                     if isempty (FindAst)
 
-                        [NonServeL NonServeR]= system(['scp ',Parallel(indPC).UserName,'@',Parallel(indPC).ComputerName,':',Parallel(indPC).RemoteDirectory,'/',PRCDir,'/',NamFileInput{jfil,1},NamFileInput{jfil,2},' ',NamFileInput{jfil,1}]);
+                        [NonServeL NonServeR]= system(['scp ',scp_token,' ',Parallel(indPC).UserName,'@',Parallel(indPC).ComputerName,':',Parallel(indPC).RemoteDirectory,'/',PRCDir,'/',NamFileInput{jfil,1},NamFileInput{jfil,2},' ',NamFileInput{jfil,1}]);
 
                     else
 
                         filenameTemp=NamFileInput{jfil,2};
                         
-                        [NotUsed FlI]=system(['ssh ',Parallel(indPC).UserName,'@',Parallel(indPC).ComputerName,' ls ',Parallel(indPC).RemoteDirectory,'/',PRCDir,'/',filenameTemp, ' 2> OctaveStandardOutputMessage.txt']);
+                        [NotUsed FlI]=system(['ssh ',ssh_token,' ',Parallel(indPC).UserName,'@',Parallel(indPC).ComputerName,' ls ',Parallel(indPC).RemoteDirectory,'/',PRCDir,'/',filenameTemp, ' 2> OctaveStandardOutputMessage.txt']);
                         
                         if isempty (FlI)
                             return
@@ -71,13 +81,13 @@ for indPC=1:length(Parallel),
                         for i=1: NumFileToCopy
                             Ni=num2str(i);
                             filenameTemp(1,AstPos)=Ni;
-                            [NonServeL NonServeR]= system(['scp ',Parallel(indPC).UserName,'@',Parallel(indPC).ComputerName,':',Parallel(indPC).RemoteDirectory,'/',PRCDir,'/',NamFileInput{jfil,1},filenameTemp,' ',NamFileInput{jfil,1}]);
+                            [NonServeL NonServeR]= system(['scp ',scp_token,' ',Parallel(indPC).UserName,'@',Parallel(indPC).ComputerName,':',Parallel(indPC).RemoteDirectory,'/',PRCDir,'/',NamFileInput{jfil,1},filenameTemp,' ',NamFileInput{jfil,1}]);
                         end
                     end
 
                 else
 
-                    [NonServeL NonServeR]= system(['scp ',Parallel(indPC).UserName,'@',Parallel(indPC).ComputerName,':',Parallel(indPC).RemoteDirectory,'/',PRCDir,'/',NamFileInput{jfil,1},NamFileInput{jfil,2},' ',NamFileInput{jfil,1}]);
+                    [NonServeL NonServeR]= system(['scp ',scp_token,' ',Parallel(indPC).UserName,'@',Parallel(indPC).ComputerName,':',Parallel(indPC).RemoteDirectory,'/',PRCDir,'/',NamFileInput{jfil,1},NamFileInput{jfil,2},' ',NamFileInput{jfil,1}]);
                 end
 
             end
diff --git a/matlab/parallel/dynareParallelListAllFiles.m b/matlab/parallel/dynareParallelListAllFiles.m
index 56b8911ed882c62334dd63ee5c6cd6fc8305d2dd..8a51b13c6f5a9cbe8afe1c6448b0d89e771b75c6 100644
--- a/matlab/parallel/dynareParallelListAllFiles.m
+++ b/matlab/parallel/dynareParallelListAllFiles.m
@@ -37,9 +37,14 @@ if (~ispc || strcmpi('unix',Parallel.OperatingSystem))
    
     fileList={};
     currentPath=[];
+    if ~isempty(Parallel.Port),
+        ssh_token = ['-p ',Parallel.Port];
+    else
+        ssh_token = '';
+    end
 
      % Get the data for the current remote directory.
-    [Flag fL]=system(['ssh ',Parallel.UserName,'@',Parallel.ComputerName,' ls ',Parallel.RemoteDirectory,'/',PRCDir, ' -R -p -1']);
+    [Flag fL]=system(['ssh ',ssh_token,' ',' ',Parallel.UserName,'@',Parallel.ComputerName,' ls ',Parallel.RemoteDirectory,'/',PRCDir, ' -R -p -1']);
 
     % Format the return value fL.
     
diff --git a/matlab/parallel/dynareParallelMkDir.m b/matlab/parallel/dynareParallelMkDir.m
index ecb86e34aef2b45d7b5442f31ecc84d73ef224ce..1698113a77d36dcdc05bcd3617a549a962847ef3 100644
--- a/matlab/parallel/dynareParallelMkDir.m
+++ b/matlab/parallel/dynareParallelMkDir.m
@@ -37,7 +37,12 @@ end
 for indPC=1:length(Parallel)
     if Parallel(indPC).Local==0,
         if ~ispc || strcmpi('unix',Parallel(indPC).OperatingSystem), %isunix || (~matlab_ver_less_than('7.4') && ismac),
-            [NonServeS NonServeD]=system(['ssh ',Parallel(indPC).UserName,'@',Parallel(indPC).ComputerName,' mkdir -p ',Parallel(indPC).RemoteDirectory,'/',PRCDir]);
+            if ~isempty(Parallel(indPC).Port),
+                ssh_token = ['-p ',Parallel(indPC).Port];
+            else
+                ssh_token = '';
+            end
+            [NonServeS NonServeD]=system(['ssh ',ssh_token,' ',Parallel(indPC).UserName,'@',Parallel(indPC).ComputerName,' mkdir -p ',Parallel(indPC).RemoteDirectory,'/',PRCDir]);
         else
             [NonServeS NonServeD]=mkdir(['\\',Parallel(indPC).ComputerName,'\',Parallel(indPC).RemoteDrive,'$\',Parallel(indPC).RemoteDirectory,'\',PRCDir]);
         end
diff --git a/matlab/parallel/dynareParallelRmDir.m b/matlab/parallel/dynareParallelRmDir.m
index 1a84986a1db2c3dbf9898426514d987b732b209d..2bba6bc5c7be9756a75356b30b0d799d1fc77c24 100644
--- a/matlab/parallel/dynareParallelRmDir.m
+++ b/matlab/parallel/dynareParallelRmDir.m
@@ -36,13 +36,13 @@ if nargin ==0,
 end
 
 % security check of remote folder delete
-ok(1)=isempty(strfind(Parallel_info.RemoteTmpFolder,'..'));
-tmp1=strfind(Parallel_info.RemoteTmpFolder,'2');
+ok(1)=isempty(strfind(PRCDir,'..'));
+tmp1=strfind(PRCDir,'2');
 ok(2)=tmp1(1)==1;
-ok(3)=~isempty(strfind(Parallel_info.RemoteTmpFolder,'-'));
-ok(4)=~isempty(strfind(Parallel_info.RemoteTmpFolder,'h'));
-ok(5)=~isempty(strfind(Parallel_info.RemoteTmpFolder,'m'));
-ok(6)=~isempty(strfind(Parallel_info.RemoteTmpFolder,'s'));
+ok(3)=~isempty(strfind(PRCDir,'-'));
+ok(4)=~isempty(strfind(PRCDir,'h'));
+ok(5)=~isempty(strfind(PRCDir,'m'));
+ok(6)=~isempty(strfind(PRCDir,'s'));
 ok(7)=~isempty(PRCDir);
 
 if sum(ok)<7,
@@ -55,8 +55,13 @@ for indPC=1:length(Parallel),
         error('The remote folder path structure does not comply the security standards!'),
     end
     while (1)
-        if ~ispc || strcmpi('unix',Parallel(indPC).OperatingSystem)
-            [stat NonServe] = system(['ssh ',Parallel(indPC).UserName,'@',Parallel(indPC).ComputerName,' rm -fr ',Parallel(indPC).RemoteDirectory,'/',PRCDir,]);
+        if ~ispc || strcmpi('unix',Parallel(indPC).OperatingSystem),
+            if ~isempty(Parallel(indPC).Port),
+                ssh_token = ['-p ',Parallel(indPC).Port];
+            else
+                ssh_token = '';
+            end
+            [stat NonServe] = system(['ssh ',ssh_token,' ',Parallel(indPC).UserName,'@',Parallel(indPC).ComputerName,' rm -fr ',Parallel(indPC).RemoteDirectory,'/',PRCDir,]);
             break;
         else
             if exist('OCTAVE_VERSION'), % Patch for peculiar behaviour of rmdir under Windows.
diff --git a/matlab/parallel/dynareParallelSendFiles.m b/matlab/parallel/dynareParallelSendFiles.m
index e4a69f4d3c9c2f6df5fe2de032127e771cf12df2..a1a857ae40f38f189c2071fff4e57b92983f74eb 100644
--- a/matlab/parallel/dynareParallelSendFiles.m
+++ b/matlab/parallel/dynareParallelSendFiles.m
@@ -42,11 +42,21 @@ end
 for indPC=1:length(Parallel),
     if Parallel(indPC).Local==0,
         if ~ispc || strcmpi('unix',Parallel(indPC).OperatingSystem), %isunix || (~matlab_ver_less_than('7.4') && ismac),
+            if ~isempty(Parallel(indPC).Port),
+                ssh_token = ['-p ',Parallel(indPC).Port];
+            else
+                ssh_token = '';
+            end
+            if ~isempty(Parallel(indPC).Port),
+                scp_token = ['-P ',Parallel(indPC).Port];
+            else
+                scp_token = '';
+            end
             for jfil=1:size(NamFileInput,1),
                 if ~isempty(NamFileInput{jfil,1})
-                    [NonServeL NonServeR]=system(['ssh ',Parallel(indPC).UserName,'@',Parallel(indPC).ComputerName,' mkdir -p ',Parallel(indPC).RemoteDirectory,'/',PRCDir,'/',NamFileInput{jfil,1}]);
+                    [NonServeL NonServeR]=system(['ssh ',ssh_token,' ',Parallel(indPC).UserName,'@',Parallel(indPC).ComputerName,' mkdir -p ',Parallel(indPC).RemoteDirectory,'/',PRCDir,'/',NamFileInput{jfil,1}]);
                 end
-                [NonServeL NonServeR]=system(['scp ',NamFileInput{jfil,1},NamFileInput{jfil,2},' ',Parallel(indPC).UserName,'@',Parallel(indPC).ComputerName,':',Parallel(indPC).RemoteDirectory,'/',PRCDir,'/',NamFileInput{jfil,1}]);
+                [NonServeL NonServeR]=system(['scp ',scp_token,' ',NamFileInput{jfil,1},NamFileInput{jfil,2},' ',Parallel(indPC).UserName,'@',Parallel(indPC).ComputerName,':',Parallel(indPC).RemoteDirectory,'/',PRCDir,'/',NamFileInput{jfil,1}]);
             end
         else
             for jfil=1:size(NamFileInput,1)
diff --git a/matlab/parallel/masterParallel.m b/matlab/parallel/masterParallel.m
index 40255976917319ed9d30936d01e7225a96192fff..7d7df87fe312c65e9cc249be494badd93b955adb 100644
--- a/matlab/parallel/masterParallel.m
+++ b/matlab/parallel/masterParallel.m
@@ -10,7 +10,7 @@ function [fOutVar,nBlockPerCPU, totCPU] = masterParallel(Parallel,fBlock,nBlock,
 % necessary and then closed. This can happen many times during the
 % simulation of a model.
 
-% 1 Alway Open Stategy:
+% 1 Always Open Strategy:
 % In this case we have a more sophisticated management of slave processes,
 % which are no longer closed at the end of each job. The slave processes
 % waits for a new job (if exist). If a slave do not receives a new job after a
@@ -153,6 +153,11 @@ offset0 = fBlock-1;
 mydelete(['comp_status_',fname,'*.mat']);
 mydelete(['P_',fname,'*End.txt']);
 mydelete([fname,'_output_*.mat']);
+mydelete('slaveParallel_break.mat');
+
+dynareParallelDelete([fname,'_output_*.mat'],PRCDir,Parallel);
+dynareParallelDelete(['comp_status_',fname,'*.mat'],PRCDir,Parallel);
+dynareParallelDelete('slaveParallel_break.mat',PRCDir,Parallel);
 
 
 % Create a shell script containing the commands to launch the required
@@ -294,9 +299,9 @@ for j=1:totCPU,
                     end
                 else    % Hybrid computing Matlab(Master)->Octave(Slaves) and Vice Versa!
                     if  strfind([Parallel(indPC).MatlabOctavePath], 'octave')
-                        command1=['start /B psexec -W ',DyMo, ' -a ',int2str(Parallel(indPC).CPUnbr(j-nCPU0)),' -low  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,''')"'];
+                        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,''')"'];
                     else
-                        command1=['start /B psexec -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,''')"'];
+                        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
                 end
             else                                                            % 0.2 Parallel(indPC).Local==0: Run using network on remote machine or also on local machine.
@@ -309,15 +314,20 @@ for j=1:totCPU,
                     if ispc, token='start /B ';
                     else token = '';
                     end
+                    if ~isempty(Parallel(indPC).Port),
+                        ssh_token = ['-p ',Parallel(indPC).Port];
+                    else
+                        ssh_token = '';
+                    end
                     % 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!
                         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 ',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, '; octave --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 ',Parallel(indPC).UserName,'@',Parallel(indPC).ComputerName,' "cd ',Parallel(indPC).RemoteDirectory,'/',PRCDir, '; ',Parallel(indPC).MatlabOctavePath,' -nosplash -nodesktop -minimize ',compThread,' -r ',remoteFile,';" &'];
+                        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,';" &'];
                     end
                     fprintf(fidRemote,'%s\n',remoteString);
                     fclose(fidRemote);
@@ -327,19 +337,20 @@ for j=1:totCPU,
                     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')
-                            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 "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=['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,''')"'];
                         else
-                            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)), ...
+             
+                            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(); fParallel(',int2str(offset+1),',',int2str(sum(nBlockPerCPU(1:j))),',',int2str(j),',',int2str(indPC),',''',fname,''')"'];
                         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')
-                            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,''')"'];
+                            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,''')"'];
                         else
-                            command1=['start /B psexec \\',Parallel(indPC).ComputerName,' -e -W ',Parallel(indPC).RemoteDrive,':\',Parallel(indPC).RemoteDirectory,'\',PRCDir,'\ -a ',int2str(Parallel(indPC).CPUnbr(j-nCPU0)), ...
+                            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,''')"'];
                         end
                     end
@@ -357,9 +368,9 @@ for j=1:totCPU,
                     end
                 else    % Hybrid computing Matlab(Master)->Octave(Slaves) and Vice Versa!
                     if  strfind([Parallel(indPC).MatlabOctavePath], 'octave')
-                        command1=['start /B psexec -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),')"'];
+                        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),')"'];
                     else
-                        command1=['start /B psexec -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),')"'];
+                        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
                 end
             elseif Parallel(indPC).Local==0,                                % 1.2 Run using network on remote machine or also on local machine.
@@ -376,15 +387,20 @@ for j=1:totCPU,
                         if ispc, token='start /B ';
                         else token = '';
                         end
+                        if ~isempty(Parallel(indPC).Port),
+                            ssh_token = ['-p ',Parallel(indPC).Port];
+                        else
+                            ssh_token = '';
+                        end
                         % 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!
                             remoteString=['default_save_options(''-v7''); addpath(''',Parallel(indPC).DynarePath,'''), dynareroot = dynare_config(); slaveParallel(',int2str(j),',',int2str(indPC),');'];
-                            command1=[token, 'ssh ',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 '; octave --eval ',remoteFile,' " &'];
                         else
                             remoteString=['addpath(''',Parallel(indPC).DynarePath,'''), dynareroot = dynare_config(); slaveParallel(',int2str(j),',',int2str(indPC),');'];
-                            command1=[token, 'ssh ',Parallel(indPC).UserName,'@',Parallel(indPC).ComputerName,' "cd ',Parallel(indPC).RemoteDirectory,'/',PRCDir '; ',Parallel(indPC).MatlabOctavePath,' -nosplash -nodesktop -minimize ',compThread,' -r ',remoteFile,';" &'];
+                            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,';" &'];
                         end
                         fprintf(fidRemote,'%s\n',remoteString);
                         fclose(fidRemote);
@@ -394,19 +410,19 @@ for j=1:totCPU,
                         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')
-                                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 "default_save_options(''-v7'');addpath(''',Parallel(indPC).DynarePath,'''), dynareroot = dynare_config(); slaveParallel(',int2str(j),',',int2str(indPC),')"'];
+                                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),')"'];
                             else
-                                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)), ...
+                                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')
-                                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 "default_save_options(''-v7''); addpath(''',Parallel(indPC).DynarePath,'''), dynareroot = dynare_config(); slaveParallel(',int2str(j),',',int2str(indPC),')"'];
+                                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),')"'];
                             else
-                                command1=['start /B psexec \\',Parallel(indPC).ComputerName,' -e -W ',Parallel(indPC).RemoteDrive,':\',Parallel(indPC).RemoteDirectory,'\',PRCDir,'\ -a ',int2str(Parallel(indPC).CPUnbr(j-nCPU0)), ...
+                                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),')"'];
                             end
                         end
@@ -521,7 +537,6 @@ end
 pcerdone = NaN(1,totCPU);
 idCPU = NaN(1,totCPU);
 
-delete(['comp_status_',fname,'*.mat']);
 
 
 % Wait for the slaves to finish their job, and display some progress
@@ -705,8 +720,23 @@ for j=1:totCPU,
     load([fname,'_output_',int2str(j),'.mat'],'fOutputVar');
     delete([fname,'_output_',int2str(j),'.mat']);
     if isfield(fOutputVar,'OutputFileName'),
-        %   Already done above
-        %   dynareParallelGetFiles([fOutputVar.OutputFileName],PRCDir,Parallel(indPC));
+        %   Check if input files have been updated!
+        OutputFileName=fOutputVar.OutputFileName;
+        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)));
+            end
+        end
+        for l=1:size(OutputFileName,1),
+            tmp1=dynareParallelDir([OutputFileName{l,:}],PRCDir,Parallel(indPC));
+            for k=1:size(tmp1,1),
+                if any(strcmp(tmp1(k,:),cellstr(tmp0))),
+                    dynareParallelGetFiles([OutputFileName(l,1) {tmp1(k,:)}],PRCDir,Parallel(indPC));
+                end
+            end
+        end
     end
     if isfield(fOutputVar,'error'),
         disp(['Job number ',int2str(j),' crashed with error:']);
@@ -751,6 +781,7 @@ switch Strategy
                 mydelete([fname,'*.log']);
             catch
             end
+            
             mydelete(['*_core*_input*.mat']);
             %             if Parallel(indPC).Local == 1
             %                 delete(['slaveParallel_input*.mat']);
@@ -771,6 +802,15 @@ switch Strategy
         if newInstance,
             delete ConcurrentCommand1.bat
         end
+        dynareParallelDelete(['comp_status_',fname,'*.mat'],PRCDir,Parallel);
+        for indPC=1:length(Parallel)
+            if Parallel(indPC).Local == 0,
+                dynareParallelDeleteNewFiles(PRCDir,Parallel(indPC),PRCDirSnapshotInit(indPC),'.log');
+                for ifil=1:size(NamFileInput,1),
+                    dynareParallelDelete([NamFileInput{ifil,:}],PRCDir,Parallel(indPC));
+                end
+            end
+        end
 end