diff --git a/matlab/run_all_simulations.m b/matlab/run_all_simulations.m new file mode 100644 index 0000000000000000000000000000000000000000..2f8c5450de2c3df51c217888490b35a6261139b3 --- /dev/null +++ b/matlab/run_all_simulations.m @@ -0,0 +1,69 @@ +% Copyright (C) 2024 Dynare Team + +%{ +stack_solve_algo = +0 : Use a Newton algorithm with a direct sparse LU solver at each iteration, + applied on the stacked system of all the equations at every period (Default). +1 : Use the Laffargue-Boucekkine-Juillard (LBJ) algorithm proposed in Juillard (1996). + It is slower than stack_solve_algo=0, but may be less memory consuming on big models. + Note that if the block option is used (see Model declaration), a simple Newton + algorithm with sparse matrices is used for blocks which are purely backward or + forward (of type SOLVE BACKWARD or SOLVE FORWARD, see model_info), since LBJ only + makes sense on blocks with both leads and lags (of type SOLVE TWO BOUNDARIES). +2 : Use a Newton algorithm with a Generalized Minimal Residual (GMRES) solver + at each iteration (requires bytecode and/or block option, see Model declaration) +3 : Use a Newton algorithm with a Stabilized Bi-Conjugate Gradient (BICGSTAB) + solver at each iteration (requires bytecode and/or block option, see Model declaration). +4 : Use a Newton algorithm with an optimal path length at each iteration (requires + bytecode and/or block option, see Model declaration). +5 : Use a Newton algorithm with a sparse Gaussian elimination (SPE) solver at + each iteration (requires bytecode option, see Model declaration). +6 : Synonymous for stack_solve_algo=1. Kept for historical reasons. +7 : Allows the user to solve the perfect foresight model with the solvers available + through option solve_algo (See solve_algo for a list of possible values, + note that values 5, 6, 7 and 8, which require bytecode and/or block options, + are not allowed). +%} + +nopng = false; + +stack_solve_algo = [0, 1, 2, 3, 4, 5]; + +static_solve_algo = [0, 1, 2, 3, 4, 9, 13]; + +if ~exist('niter', 'var') + % Set default for the number of iterations. + niter = 1; +end + +if ~exist('ccrit', 'var') + % Set default precision. + ccrit = 1e-5; +end + +if ~exist('MODEL', 'var') + error('Unspecified model. Please set variable MODEL (name of a mod file, without extension).'); +end + +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); + +texname = sprintf('%s-%s', MODEL, lower(regexprep(char(java.net.InetAddress.getLocalHost.getHostName),'.local\>',''))); % TODO: Check if we need a trap for Octave. + +write_table_short(sprintf('simulations-%s.mat', MODEL), texname, nopng) + +% Delete files and subfolders +delete(sprintf('%s.log', MODEL)) +rmdir(sprintf('%s', MODEL), 's') +rmdir(sprintf('+%s', MODEL), 's') + +% Move generated table in the current folder +p = strrep(which('run_all_simulations'), sprintf('matlab%srun_all_simulations.m', filesep), sprintf('tables%s', filesep)); +movefile(sprintf('%s%s.pdf', p, texname), pwd) +movefile(sprintf('%s%s.tex', p, texname), pwd) +if ~nopng + movefile(sprintf('%s%s.png', p, texname), pwd) +end diff --git a/run.sh b/run.sh index 1188619ece109def2a5a9b9f850ccdf7fafb7251..2bc2f3da19a100782815ba2d950002a5d1ea3045 100755 --- a/run.sh +++ b/run.sh @@ -1,8 +1,19 @@ #!/usr/bin/env bash -SCRIPT=$(realpath "$0") -SCRIPTPATH=$(dirname "$SCRIPT") -echo "$SCRIPTPATH" +WHEREAMI=$(dirname $(realpath "$0")) + +if [ ! -v ITERATIONS ] +then + echo "Set default number of iterations (niter=1)." + ITERATIONS=1 +else + echo "Number of iterations is niter=$ITERATIONS." +fi + +if [ ! -v DYNARE ] +then + echo "Path to dynare must be provided." +fi if [ $# -eq 0 ] then @@ -27,7 +38,7 @@ do then while [ ! -f $model-done.info ] do - matlab -batch "addpath $MATLAB_PATH; MODEL='$model'; compute_all_transitions;" |& tee -a $model-all.log + matlab -batch "addpath $DYNARE; addpath $WHEREAMI/matlab; MODEL='$model'; niter=$ITERATIONS; run_all_simulations;" |& tee -a $model-all.log done printf " \u2714 $model\n" else