0001 function slaveParallel(whoiam,ThisMatlab)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035 global funcName
0036
0037 warning off;
0038 diary off;
0039
0040 delete( ['slaveParallel_',int2str(whoiam),'.log']);
0041 diary( ['slaveParallel_',int2str(whoiam),'.log']);
0042
0043
0044
0045 dynareroot = dynare_config();
0046
0047
0048 load( ['slaveParallel_input',int2str(whoiam)]);
0049
0050
0051 if exist('fGlobalVar'),
0052 globalVars = fieldnames(fGlobalVar);
0053 for j=1:length(globalVars),
0054 eval(['global ',globalVars{j},';']);
0055 evalin('base',['global ',globalVars{j},';']);
0056 end
0057 struct2local(fGlobalVar);
0058 clear fGlobalVar
0059
0060 evalin('base',['load( [''slaveParallel_input',int2str(whoiam),'''],''fGlobalVar'')']) ;
0061 evalin('base','struct2local(fGlobalVar)');
0062 evalin('base','clear fGlobalVar');
0063 end
0064
0065 t0=clock;
0066 fslave = dir( ['slaveParallel_input',int2str(whoiam),'.mat']);
0067
0068 while (etime(clock,t0)<1200 && ~isempty(fslave)) || ~isempty(dir(['stayalive',int2str(whoiam),'.txt'])),
0069 if ~isempty(dir(['stayalive',int2str(whoiam),'.txt'])),
0070 t0=clock;
0071 delete(['stayalive',int2str(whoiam),'.txt']);
0072 end
0073
0074 pause(1);
0075
0076 fjob = dir(['slaveJob',int2str(whoiam),'.mat']);
0077
0078 if ~isempty(fjob),
0079 clear fGlobalVar fInputVar fblck nblck fname
0080
0081 while(1)
0082 Go=0;
0083
0084 Go=fopen(['slaveJob',int2str(whoiam),'.mat']);
0085
0086 if Go>0
0087 fclose(Go);
0088 pause(1);
0089 load(['slaveJob',int2str(whoiam),'.mat']);
0090 break
0091 else
0092
0093
0094
0095
0096
0097
0098
0099
0100
0101
0102 end
0103 end
0104
0105 funcName=fname;
0106
0107 if exist('fGlobalVar') && ~isempty (fGlobalVar)
0108 globalVars = fieldnames(fGlobalVar);
0109 for j=1:length(globalVars),
0110 info_whos = whos(globalVars{j});
0111 if isempty(info_whos) || ~info_whos.global,
0112 eval(['global ',globalVars{j},';']);
0113 evalin('base',['global ',globalVars{j},';']);
0114 end
0115 end
0116 struct2local(fGlobalVar);
0117 evalin('base',['load( [''slaveJob',int2str(whoiam),'''],''fGlobalVar'')']);
0118 evalin('base','struct2local(fGlobalVar)');
0119 evalin('base','clear fGlobalVar');
0120 end
0121 delete(['slaveJob',int2str(whoiam),'.mat']);
0122 fInputVar.Parallel = Parallel;
0123
0124
0125 try,
0126 tic,
0127 fOutputVar = feval(fname, fInputVar ,fblck, nblck, whoiam, ThisMatlab);
0128 toc,
0129 if isfield(fOutputVar,'OutputFileName'),
0130 OutputFileName = fOutputVar.OutputFileName;
0131 else
0132 OutputFileName = '';
0133 end
0134
0135 if(whoiam)
0136
0137
0138 save([ fname,'_output_',int2str(whoiam),'.mat'],'fOutputVar' );
0139
0140 if isfield(fOutputVar,'CloseAllSlaves'),
0141 CloseAllSlaves = 1;
0142 fOutputVar = rmfield(fOutputVar,'CloseAllSlaves');
0143 save([ fname,'_output_',int2str(whoiam),'.mat'],'fOutputVar' )
0144 save(['comp_status_',funcName,int2str(whoiam),'.mat'],'CloseAllSlaves');
0145 end
0146
0147
0148 delete(['P_',fname,'_',int2str(whoiam),'End.txt']);
0149 end
0150
0151 disp(['Job ',fname,' on CPU ',int2str(whoiam),' completed.']);
0152 t0 =clock;
0153 catch,
0154 theerror = lasterror;
0155 if strfind(theerror.message,'Master asked to break the job')
0156 disp(['Job ',fname,' on CPU ',int2str(whoiam),' broken from master.']);
0157 fOutputVar.message = theerror;
0158 save([ fname,'_output_',int2str(whoiam),'.mat'],'fOutputVar' )
0159 delete(['P_',fname,'_',int2str(whoiam),'End.txt']);
0160 else
0161 disp(['Job ',fname,' on CPU ',int2str(whoiam),' crashed.']);
0162 fOutputVar.error = lasterror;
0163 save([ fname,'_output_',int2str(whoiam),'.mat'],'fOutputVar' );
0164 waitbarString = fOutputVar.error.message;
0165 if Parallel(ThisMatlab).Local,
0166 waitbarTitle='Local ';
0167 else
0168 waitbarTitle=[Parallel(ThisMatlab).ComputerName];
0169 end
0170 fMessageStatus(NaN,whoiam,waitbarString, waitbarTitle, Parallel(ThisMatlab));
0171 delete(['P_',fname,'_',int2str(whoiam),'End.txt']);
0172 break
0173 end
0174
0175 end
0176 end
0177 fslave = dir( ['slaveParallel_input',int2str(whoiam),'.mat']);
0178 end
0179
0180
0181 disp(['slaveParallel on CPU ',int2str(whoiam),' completed.']);
0182 diary off;
0183
0184 delete(['P_slave_',int2str(whoiam),'End.txt']);
0185
0186
0187 exit;