2009-12-16 18:17:34 +01:00
|
|
|
function fParallel(fblck,nblck,whoiam,ThisMatlab,fname)
|
2010-05-31 11:26:45 +02:00
|
|
|
% PARALLEL CONTEXT
|
|
|
|
% In a parallel context, this function is launched on slave
|
2009-12-16 18:17:34 +01:00
|
|
|
% machines, and acts as a wrapper around the function containing the
|
|
|
|
% computing task itself.
|
|
|
|
%
|
|
|
|
% INPUTS
|
2010-10-08 16:15:50 +02:00
|
|
|
% o fblck [int] index number of the first thread to run in this
|
2009-12-16 18:17:34 +01:00
|
|
|
% MATLAB instance
|
2010-10-08 16:15:50 +02:00
|
|
|
% o nblck [int] number of threads to run in this
|
2009-12-16 18:17:34 +01:00
|
|
|
% MATLAB instance
|
2010-10-08 16:15:50 +02:00
|
|
|
% o whoiam [int] index number of this CPU among all CPUs in the
|
2009-12-16 18:17:34 +01:00
|
|
|
% cluster
|
2010-10-08 16:15:50 +02:00
|
|
|
% o ThisMatlab [int] index number of this slave machine in the cluster
|
2009-12-16 18:17:34 +01:00
|
|
|
% (entry in options_.parallel)
|
2010-10-08 16:15:50 +02:00
|
|
|
% o fname [string] function to be run, containing the computing task
|
2010-05-31 11:26:45 +02:00
|
|
|
%
|
2010-10-22 11:27:26 +02:00
|
|
|
% OUTPUTS
|
|
|
|
% None
|
2010-05-31 11:26:45 +02:00
|
|
|
%
|
2022-04-13 13:15:19 +02:00
|
|
|
% Copyright © 2006-2017 Dynare Team
|
2009-12-16 18:17:34 +01:00
|
|
|
%
|
|
|
|
% This file is part of Dynare.
|
|
|
|
%
|
|
|
|
% Dynare is free software: you can redistribute it and/or modify
|
|
|
|
% it under the terms of the GNU General Public License as published by
|
|
|
|
% the Free Software Foundation, either version 3 of the License, or
|
|
|
|
% (at your option) any later version.
|
|
|
|
%
|
|
|
|
% Dynare is distributed in the hope that it will be useful,
|
|
|
|
% but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
% GNU General Public License for more details.
|
|
|
|
%
|
|
|
|
% You should have received a copy of the GNU General Public License
|
2021-06-09 17:33:48 +02:00
|
|
|
% along with Dynare. If not, see <https://www.gnu.org/licenses/>.
|
2009-12-16 18:17:34 +01:00
|
|
|
|
|
|
|
global funcName
|
|
|
|
|
|
|
|
funcName=fname;
|
|
|
|
|
|
|
|
warning off;
|
|
|
|
diary off;
|
|
|
|
|
|
|
|
delete( [fname,'_',int2str(whoiam),'.log']);
|
|
|
|
diary( [fname,'_',int2str(whoiam),'.log']);
|
|
|
|
|
2010-10-08 16:15:50 +02:00
|
|
|
% Configure dynare environment.
|
2009-12-16 18:17:34 +01:00
|
|
|
dynareroot = dynare_config();
|
|
|
|
|
2010-10-08 16:15:50 +02:00
|
|
|
% Load input data.
|
2010-10-22 11:27:26 +02:00
|
|
|
load( [fname,'_input'])
|
2010-09-06 17:24:16 +02:00
|
|
|
|
2010-05-31 11:26:45 +02:00
|
|
|
if exist('fGlobalVar') && ~isempty (fGlobalVar)
|
2009-12-16 18:17:34 +01:00
|
|
|
globalVars = fieldnames(fGlobalVar);
|
2017-05-16 12:42:01 +02:00
|
|
|
for j=1:length(globalVars)
|
2009-12-16 18:17:34 +01:00
|
|
|
eval(['global ',globalVars{j},';'])
|
2010-08-25 15:18:58 +02:00
|
|
|
evalin('base',['global ',globalVars{j},';'])
|
2009-12-16 18:17:34 +01:00
|
|
|
end
|
|
|
|
struct2local(fGlobalVar);
|
2010-10-08 16:15:50 +02:00
|
|
|
% Create global variables in the base workspace as well.
|
|
|
|
evalin('base',['load( [''',fname,'_input''],''fGlobalVar'')'])
|
2010-08-25 15:18:58 +02:00
|
|
|
evalin('base','struct2local(fGlobalVar)');
|
2009-12-16 18:17:34 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
fInputVar.Parallel = Parallel;
|
|
|
|
|
2010-10-08 16:15:50 +02:00
|
|
|
|
|
|
|
% Launch the routine to be run in parallel.
|
2017-05-16 12:42:01 +02:00
|
|
|
try
|
|
|
|
tic
|
2017-05-16 15:10:20 +02:00
|
|
|
|
2010-10-08 16:15:50 +02:00
|
|
|
fOutputVar = feval(fname, fInputVar ,fblck, nblck, whoiam, ThisMatlab);
|
2017-05-16 12:42:01 +02:00
|
|
|
toc
|
|
|
|
if isfield(fOutputVar,'OutputFileName')
|
2010-10-08 16:15:50 +02:00
|
|
|
OutputFileName = fOutputVar.OutputFileName;
|
|
|
|
else
|
|
|
|
OutputFileName = '';
|
|
|
|
end
|
|
|
|
if(whoiam)
|
|
|
|
% Save the output result.
|
|
|
|
save([ fname,'_output_',int2str(whoiam),'.mat'],'fOutputVar' )
|
|
|
|
end
|
2017-05-16 12:42:01 +02:00
|
|
|
if isfield(fOutputVar,'CloseAllSlaves')
|
2012-02-10 22:41:54 +01:00
|
|
|
CloseAllSlaves = 1;
|
|
|
|
fOutputVar = rmfield(fOutputVar,'CloseAllSlaves');
|
|
|
|
save([ fname,'_output_',int2str(whoiam),'.mat'],'fOutputVar' )
|
|
|
|
save(['comp_status_',funcName,int2str(whoiam),'.mat'],'CloseAllSlaves');
|
|
|
|
end
|
2017-05-16 15:10:20 +02:00
|
|
|
|
2010-10-08 16:15:50 +02:00
|
|
|
disp(['fParallel ',int2str(whoiam),' completed.'])
|
2017-05-16 12:42:01 +02:00
|
|
|
catch
|
2012-02-10 22:41:54 +01:00
|
|
|
theerror = lasterror;
|
|
|
|
if strfind(theerror.message,'Master asked to break the job')
|
|
|
|
fOutputVar.message = theerror;
|
|
|
|
save([ fname,'_output_',int2str(whoiam),'.mat'],'fOutputVar' )
|
|
|
|
waitbarString = theerror.message;
|
2009-12-16 18:17:34 +01:00
|
|
|
else
|
2012-02-10 22:41:54 +01:00
|
|
|
disp(['fParallel ',int2str(whoiam),' crashed.'])
|
|
|
|
fOutputVar.error = theerror;
|
|
|
|
save([ fname,'_output_',int2str(whoiam),'.mat'],'fOutputVar' )
|
|
|
|
waitbarString = theerror.message;
|
|
|
|
% waitbarTitle=['Metropolis-Hastings ',options_.parallel(ThisMatlab).ComputerName];
|
2017-05-16 12:42:01 +02:00
|
|
|
if Parallel(ThisMatlab).Local
|
2012-02-10 22:41:54 +01:00
|
|
|
waitbarTitle='Local ';
|
|
|
|
else
|
|
|
|
waitbarTitle=[Parallel(ThisMatlab).ComputerName];
|
|
|
|
end
|
|
|
|
fMessageStatus(NaN,whoiam,waitbarString, waitbarTitle, Parallel(ThisMatlab));
|
2009-12-16 18:17:34 +01:00
|
|
|
end
|
2017-05-16 15:10:20 +02:00
|
|
|
|
2009-12-16 18:17:34 +01:00
|
|
|
end
|
|
|
|
diary off;
|
2010-10-08 16:15:50 +02:00
|
|
|
delete(['P_',fname,'_',int2str(whoiam),'End.txt']);
|
|
|
|
|
2009-12-16 18:17:34 +01:00
|
|
|
|
|
|
|
exit;
|