parallelized pm3.

time-shift
Marco Ratto 2010-02-10 18:47:20 +01:00
parent e2c38b4028
commit 837399182c
2 changed files with 118 additions and 51 deletions

View File

@ -77,77 +77,81 @@ for i = 1:nvar
eval(['oo_.' name3 '.HPDsup.' name ' = HPD(2,:,i);']);
end
%%
%% Finally I build the plots.
%% Finally I build the plots.
%%
% %%%%%%%%% PARALLEL BLOCK % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% %%% The file .TeX! are not saved in parallel.
subplotnum = 0;
if options_.TeX
fidTeX = fopen([M_.dname '/Output/' M_.fname '_' name3 '.TeX'],'w');
fprintf(fidTeX,'%% TeX eps-loader file generated by Dynare.\n');
fprintf(fidTeX,['%% ' datestr(now,0) '\n']);
fprintf(fidTeX,' \n');
end
%%
figunumber = 0;
subplotnum = 0;
hh = figure('Name',[tit1 ' ' int2str(figunumber+1)]);
for i=1:nvar
NAMES = [];
if options_.TeX
TEXNAMES = [];
end
if max(abs(Mean(:,i))) > 10^(-6)
subplotnum = subplotnum+1;
set(0,'CurrentFigure',hh)
subplot(nn,nn,subplotnum);
plot([1 n2],[0 0],'-r','linewidth',0.5);
hold on
for k = 1:9
plot(1:n2,squeeze(Distrib(k,:,i)),'-g','linewidth',0.5)
end
plot(1:n2,Mean(:,i),'-k','linewidth',1)
xlim([1 n2]);
hold off
name = deblank(varlist(i,:));
NAMES = strvcat(NAMES,name);
if options_.TeX
for i=1:nvar
NAMES = [];
TEXNAMES = [];
if max(abs(Mean(:,i))) > 10^(-6)
subplotnum = subplotnum+1;
name = deblank(varlist(i,:));
NAMES = strvcat(NAMES,name);
texname = deblank(varlist_TeX(i,:));
TEXNAMES = strvcat(TEXNAMES,['$' texname '$']);
end
title(name,'Interpreter','none')
end
if subplotnum == MaxNumberOfPlotsPerFigure | i == nvar
eval(['print -depsc2 ' M_.dname '/Output/' M_.fname '_' name3 '_' deblank(tit3(i,:)) '.eps' ]);
if ~exist('OCTAVE_VERSION')
eval(['print -dpdf ' M_.dname '/Output/' M_.fname '_' name3 '_' deblank(tit3(i,:))]);
saveas(hh,[M_.dname '/Output/' M_.fname '_' name3 '_' deblank(tit3(i,:)) '.fig']);
end
if options_.nograph, close(hh), end
if options_.TeX
if subplotnum == MaxNumberOfPlotsPerFigure | i == nvar
fprintf(fidTeX,'\\begin{figure}[H]\n');
for jj = 1:size(TEXNAMES,1)
fprintf(fidTeX,['\\psfrag{%s}[1][][0.5][0]{%s}\n'],deblank(NAMES(jj,:)),deblank(TEXNAMES(jj,:)));
end
end
fprintf(fidTeX,'\\centering \n');
fprintf(fidTeX,['\\includegraphics[scale=0.5]{%s_' name3 '_%s}\n'],M_.fname,deblank(tit3(i,:)));
if options_.relative_irf
fprintf(fidTeX,['\\caption{' caption '.}']);
else
fprintf(fidTeX,['\\caption{' caption '.}']);
end
fprintf(fidTeX,'\\label{Fig:%s:%s}\n',name3,deblank(tit3(i,:)));
fprintf(fidTeX,'\\end{figure}\n');
fprintf(fidTeX,' \n');
end
subplotnum = 0;
figunumber = figunumber+1;
if (i ~= nvar)
hh = figure('Name',[name3 ' ' int2str(figunumber+1)]);
subplotnum = 0;
end
end
end
%%
if options_.TeX
fprintf(fidTeX,'%% End of TeX file.\n');
fclose(fidTeX);
end
% Store the variable mandatory for local/remote parallel computing.
localVars=[];
localVars.nvar=nvar;
localVars.tit1=tit1;
localVars.nn=nn;
localVars.n2=n2;
localVars.Distrib=Distrib;
localVars.varlist=varlist;
localVars.MaxNumberOfPlotsPerFigure=MaxNumberOfPlotsPerFigure;
localVars.name3=name3;
localVars.tit3=tit3;
localVars.Mean=Mean;
if isnumeric(options_.parallel) || ceil(size(varlist,1)/MaxNumberOfPlotsPerFigure)<4,
fout = pm3_core(localVars,1,nvar,0);
else
globalVars = struct('M_',M_, ...
'options_', options_, ...
'oo_', oo_);
[fout, nBlockPerCPU, totCPU] = masterParallel(options_.parallel, 1, nvar, [],'pm3_core', localVars,globalVars);
end
%%%%%%%%% END PARALLEL BLOCK %% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
fprintf(['MH: ' tit1 ', done!\n']);

63
matlab/pm3_core.m Normal file
View File

@ -0,0 +1,63 @@
function myoutput=pm3_core(myinputs,fpar,B,whoiam, ThisMatlab)
if nargin<4,
whoiam=0;
end
struct2local(myinputs);
global options_ M_ oo_
figunumber = 0;
subplotnum = 0;
hh = figure('Name',[tit1 ' ' int2str(figunumber+1)]);
RemoteFlag = 0;
if whoiam,
if Parallel(ThisMatlab).Local ==0
RemoteFlag=1;
end
end
OutputFileName = {};
for i=1:nvar
NAMES = [];
if max(abs(Mean(:,i))) > 10^(-6)
subplotnum = subplotnum+1;
set(0,'CurrentFigure',hh)
subplot(nn,nn,subplotnum);
plot([1 n2],[0 0],'-r','linewidth',0.5);
hold on
for k = 1:9
plot(1:n2,squeeze(Distrib(k,:,i)),'-g','linewidth',0.5)
end
plot(1:n2,Mean(:,i),'-k','linewidth',1)
xlim([1 n2]);
hold off
name = deblank(varlist(i,:));
NAMES = strvcat(NAMES,name);
title(name,'Interpreter','none')
end
if subplotnum == MaxNumberOfPlotsPerFigure | i == nvar
eval(['print -depsc2 ' M_.dname '/Output/' M_.fname '_' name3 '_' deblank(tit3(i,:)) '.eps' ]);
if ~exist('OCTAVE_VERSION')
eval(['print -dpdf ' M_.dname '/Output/' M_.fname '_' name3 '_' deblank(tit3(i,:))]);
saveas(hh,[M_.dname '/Output/' M_.fname '_' name3 '_' deblank(tit3(i,:)) '.fig']);
end
if RemoteFlag==1,
OutputFileName = [OutputFileName; {[M_.dname, filesep, 'Output',filesep], [M_.fname '_' name3 '_' deblank(tit3(i,:)) '.*']}];
end
if options_.nograph, close(hh), end
subplotnum = 0;
figunumber = figunumber+1;
if (i ~= nvar)
hh = figure('Name',[name3 ' ' int2str(figunumber+1)]);
end
end
end
myoutput.OutputFileName=OutputFileName;