diff --git a/matlab/run_all_simulations.m b/matlab/run_all_simulations.m index af09ce31bfd700bc547cb1331e421cc63c736c62..5cbafe840744f2bdab995debe6e610fd84355daa 100644 --- a/matlab/run_all_simulations.m +++ b/matlab/run_all_simulations.m @@ -41,6 +41,11 @@ if ~exist('ccrit', 'var') ccrit = 1e-5; end +if ~exist('nofast', 'var') + % Set default precision. + nofast = false; +end + if ~exist('MODEL', 'var') error('Unspecified model. Please set variable MODEL (name of a mod file, without extension).'); end @@ -49,7 +54,7 @@ if ~exist(sprintf('%s.mod', MODEL), 'file') error('File %s.mod is not in the current directory.', MODEL); end -run_simulations(MODEL, stack_solve_algo, static_solve_algo, niter, ccrit); +run_simulations(MODEL, stack_solve_algo, static_solve_algo, niter, ccrit, nofast); texname = sprintf('%s-%s', MODEL, lower(regexprep(char(java.net.InetAddress.getLocalHost.getHostName),'.local\>',''))); % TODO: Check if we need a trap for Octave. diff --git a/matlab/run_simulations.m b/matlab/run_simulations.m index 4966512bcbc238396cd8c66d617017c4535b6c3a..c76a3b6d208941595061c608173c4f01d6e5b5c3 100644 --- a/matlab/run_simulations.m +++ b/matlab/run_simulations.m @@ -1,4 +1,4 @@ -function run_simulations(model, stack_solve_algo, static_solve_algo, niter, ccrit) +function run_simulations(model, stack_solve_algo, static_solve_algo, niter, ccrit, nofast) % Run perfect foresight model with different options and algorithms. % @@ -8,6 +8,7 @@ function run_simulations(model, stack_solve_algo, static_solve_algo, niter, ccri % - static_solve_algo [integer] 1×q array, identifiers for the solver of the static model (only used with stack_solve_algo==7) % - niter [integer] scalar, number of simulation of each configuration. % - ccrit [double] scalar, precision threshold. +% - nofast [logical] scalar, do not use fast option if true. % % OUTPUTS % None @@ -29,6 +30,10 @@ end weight = @(n) (n<0) + (n>0)*(1/n); +if nargin<6 + nofast = false; +end + id = 1:length(stack_solve_algo); jd = 1:length(static_solve_algo); @@ -68,10 +73,10 @@ end % for algo = stack_solve_algo if ismember(algo, [4 5]) || (ismember(algo, [2 3]) && dynare_version_major <= 6) - % These algorithms are not available - Timings.MATLAB_preprocessing(id(stack_solve_algo==algo), 1) = -10; - Timings.MATLAB_computing(id(stack_solve_algo==algo), 1) = -10; - continue + % These algorithms are not available + Timings.MATLAB_preprocessing(id(stack_solve_algo==algo), 1) = -10; + Timings.MATLAB_computing(id(stack_solve_algo==algo), 1) = -10; + continue end if algo<7 if isnan(Timings.MATLAB_computing(id(stack_solve_algo==algo), 1)) @@ -126,19 +131,27 @@ end % for algo = stack_solve_algo if ismember(algo, [4 5]) || (ismember(algo, [2 3]) && dynare_version_major <= 6) - % These algorithms are not available - Timings.USE_DLL_preprocessing(id(stack_solve_algo==algo), 1) = -10; - Timings.USE_DLL_computing(id(stack_solve_algo==algo), 1) = -10; - continue + % These algorithms are not available + Timings.USE_DLL_preprocessing(id(stack_solve_algo==algo), 1) = -10; + Timings.USE_DLL_computing(id(stack_solve_algo==algo), 1) = -10; + continue end if algo<7 try if isnan(Timings.USE_DLL_computing(id(stack_solve_algo==algo), 1)) disp_title(sprintf('| USE_DLL (solve_algo=%u, no blocks, model=%s) |', algo, model)); - dprintf('dynare %s onlyclearglobals fast -DUSE_DLL=true -DITERATIONS=%u -DSTACK_SOLVE_ALGO_VALUE=%u', model, abs(niter), algo); + if nofast + dprintf('dynare %s onlyclearglobals -DUSE_DLL=true -DITERATIONS=%u -DSTACK_SOLVE_ALGO_VALUE=%u', model, abs(niter), algo); + else + dprintf('dynare %s onlyclearglobals fast -DUSE_DLL=true -DITERATIONS=%u -DSTACK_SOLVE_ALGO_VALUE=%u', model, abs(niter), algo); + end skipline() Timings.USE_DLL_computing(id(stack_solve_algo==algo), 1) = -3; % Provision for MATLAB crash - info = dynare(sprintf('%s', model), 'onlyclearglobals', 'fast', '-DUSE_DLL=true', sprintf('-DITERATIONS=%u', abs(niter)), sprintf('-DSTACK_SOLVE_ALGO_VALUE=%u', algo)); + if nofast + info = dynare(sprintf('%s', model), 'onlyclearglobals', '-DUSE_DLL=true', sprintf('-DITERATIONS=%u', abs(niter)), sprintf('-DSTACK_SOLVE_ALGO_VALUE=%u', algo)); + else + info = dynare(sprintf('%s', model), 'onlyclearglobals', 'fast', '-DUSE_DLL=true', sprintf('-DITERATIONS=%u', abs(niter)), sprintf('-DSTACK_SOLVE_ALGO_VALUE=%u', algo)); + end if oo_.deterministic_simulation.error<ccrit Timings.USE_DLL_preprocessing(id(stack_solve_algo==algo), 1) = info.time.preprocessor; Timings.USE_DLL_computing(id(stack_solve_algo==algo), 1) = info.time.compute*weight(niter); @@ -157,10 +170,18 @@ for algo = stack_solve_algo try if isnan(Timings.USE_DLL_computing(id(stack_solve_algo==algo), jd(solver==static_solve_algo))) disp_title(sprintf('| USE_DLL (solve_algo=%u, no blocks, model=%s) |', algo, model)); - dprintf('dynare %s onlyclearglobals fast -DUSE_DLL=true -DITERATIONS=%u -DSTACK_SOLVE_ALGO_VALUE=%u -DSTEADY_SOLVE_ALGO_VALUE=%u', model, abs(niter), algo, solver); + if nofast + dprintf('dynare %s onlyclearglobals -DUSE_DLL=true -DITERATIONS=%u -DSTACK_SOLVE_ALGO_VALUE=%u -DSTEADY_SOLVE_ALGO_VALUE=%u', model, abs(niter), algo, solver); + else + dprintf('dynare %s onlyclearglobals fast -DUSE_DLL=true -DITERATIONS=%u -DSTACK_SOLVE_ALGO_VALUE=%u -DSTEADY_SOLVE_ALGO_VALUE=%u', model, abs(niter), algo, solver); + end skipline() Timings.USE_DLL_computing(id(stack_solve_algo==algo), jd(solver==static_solve_algo)) = -3; % Provision for MATLAB crash - info = dynare(sprintf('%s', model), 'onlyclearglobals', 'fast', '-DUSE_DLL=true', sprintf('-DITERATIONS=%u', abs(niter)), sprintf('-DSTACK_SOLVE_ALGO_VALUE=%u', algo), sprintf('-DSTEADY_SOLVE_ALGO_VALUE=%u', solver)); + if nofast + info = dynare(sprintf('%s', model), 'onlyclearglobals', '-DUSE_DLL=true', sprintf('-DITERATIONS=%u', abs(niter)), sprintf('-DSTACK_SOLVE_ALGO_VALUE=%u', algo), sprintf('-DSTEADY_SOLVE_ALGO_VALUE=%u', solver)); + else + info = dynare(sprintf('%s', model), 'onlyclearglobals', 'fast', '-DUSE_DLL=true', sprintf('-DITERATIONS=%u', abs(niter)), sprintf('-DSTACK_SOLVE_ALGO_VALUE=%u', algo), sprintf('-DSTEADY_SOLVE_ALGO_VALUE=%u', solver)); + end if oo_.deterministic_simulation.error<ccrit Timings.USE_DLL_preprocessing(id(stack_solve_algo==algo), jd(solver==static_solve_algo)) = info.time.preprocessor; Timings.USE_DLL_computing(id(stack_solve_algo==algo), jd(solver==static_solve_algo)) = info.time.compute*weight(niter); @@ -208,10 +229,10 @@ end for mfs = 0:3 for algo = stack_solve_algo if algo == 5 - % Algorithm not available - Timings.MATLAB_WITH_BLOCKS_preprocessing(id(stack_solve_algo==algo), mfs+1) = -10; - Timings.MATLAB_WITH_BLOCKS_computing(id(stack_solve_algo==algo), mfs+1) = -10; - continue + % Algorithm not available + Timings.MATLAB_WITH_BLOCKS_preprocessing(id(stack_solve_algo==algo), mfs+1) = -10; + Timings.MATLAB_WITH_BLOCKS_computing(id(stack_solve_algo==algo), mfs+1) = -10; + continue end if isnan(Timings.MATLAB_WITH_BLOCKS_computing(id(stack_solve_algo==algo), mfs+1)) try @@ -241,18 +262,26 @@ end for mfs = 0:3 for algo = stack_solve_algo if algo == 5 - % Algorithm not available - Timings.USE_DLL_WITH_BLOCKS_preprocessing(id(stack_solve_algo==algo), mfs+1) = -10; - Timings.USE_DLL_WITH_BLOCKS_computing(id(stack_solve_algo==algo), mfs+1) = -10; - continue + % Algorithm not available + Timings.USE_DLL_WITH_BLOCKS_preprocessing(id(stack_solve_algo==algo), mfs+1) = -10; + Timings.USE_DLL_WITH_BLOCKS_computing(id(stack_solve_algo==algo), mfs+1) = -10; + continue end if isnan(Timings.USE_DLL_WITH_BLOCKS_computing(id(stack_solve_algo==algo), mfs+1)) try disp_title(sprintf('| USE_DLL (solve_algo=%u, with blocks, mfs=%u, model=%s) |', algo, mfs, model)); - dprintf('dynare %s onlyclearglobals fast -DUSE_DLL=true -DITERATIONS=%u -DSTACK_SOLVE_ALGO_VALUE=%u -DMFS_VALUE=%u -DBLOCKS=true', model, abs(niter), algo, mfs); + if nofast + dprintf('dynare %s onlyclearglobals -DUSE_DLL=true -DITERATIONS=%u -DSTACK_SOLVE_ALGO_VALUE=%u -DMFS_VALUE=%u -DBLOCKS=true', model, abs(niter), algo, mfs); + else + dprintf('dynare %s onlyclearglobals fast -DUSE_DLL=true -DITERATIONS=%u -DSTACK_SOLVE_ALGO_VALUE=%u -DMFS_VALUE=%u -DBLOCKS=true', model, abs(niter), algo, mfs); + end skipline() Timings.USE_DLL_WITH_BLOCKS_computing(id(stack_solve_algo==algo), mfs+1) = -3; % Provision for MATLAB crash - info = dynare(sprintf('%s', model), 'onlyclearglobals', 'fast', sprintf('-DITERATIONS=%u', abs(niter)), '-DBLOCKS=true', sprintf('-DMFS_VALUE=%u', mfs), '-DUSE_DLL=true', sprintf('-DSTACK_SOLVE_ALGO_VALUE=%u', algo)); + if nofast + info = dynare(sprintf('%s', model), 'onlyclearglobals', sprintf('-DITERATIONS=%u', abs(niter)), '-DBLOCKS=true', sprintf('-DMFS_VALUE=%u', mfs), '-DUSE_DLL=true', sprintf('-DSTACK_SOLVE_ALGO_VALUE=%u', algo)); + else + info = dynare(sprintf('%s', model), 'onlyclearglobals', 'fast', sprintf('-DITERATIONS=%u', abs(niter)), '-DBLOCKS=true', sprintf('-DMFS_VALUE=%u', mfs), '-DUSE_DLL=true', sprintf('-DSTACK_SOLVE_ALGO_VALUE=%u', algo)); + end if oo_.deterministic_simulation.error<ccrit Timings.USE_DLL_WITH_BLOCKS_preprocessing(id(stack_solve_algo==algo), mfs+1) = info.time.preprocessor; Timings.USE_DLL_WITH_BLOCKS_computing(id(stack_solve_algo==algo), mfs+1) = info.time.compute*weight(niter);