Commit Graph

175 Commits (fe503d3eabf52d9aeb1cf7d68f884e652b548d95)

Author SHA1 Message Date
Sébastien Villemot fe503d3eab
Remove confusing comment 2023-01-17 16:37:24 +01:00
Sébastien Villemot 4bba274f39
Block decomposition: drop unused max lead/lag fields
Note that DynamicModel::determineBlockDerivativesType(), it’s legitimate to
replace max_{lead,lag} by max_endo_{lead,lag}, because for exogenous
lag=lead=0, and we no longer compute derivatives w.r.t. to endogenous that do
not belong to the block (so-called “other” endogenous).
2023-01-17 14:42:29 +01:00
Sébastien Villemot 2e09df90e7
Bytecode w/ block decomposition: no longer output derivatives w.r.t. exogenous and endogenous outside the block 2023-01-17 14:23:40 +01:00
Sébastien Villemot 1e377f061a
Block decomposition: drop unused structure fields 2023-01-17 14:18:41 +01:00
Sébastien Villemot bbdbd0807b
Sparse representation: Octave compatibility fix
Octave does not support “private” subdir inside plus folders (“+namespace”).

See https://savannah.gnu.org/bugs/?45444
2023-01-16 17:12:10 +01:00
Sébastien Villemot 93b9ed6957
Drop the legacy representation of the block-decomposed model
As a consequence, and as a temporary measure, always output the
non-block-decomposed legacy representation.

Also drop the block kalman filter output, and drop now useless variables in
M_.block_structure.
2023-01-13 16:57:06 +01:00
Sébastien Villemot 35ac73fad8
Sparse representation: fix various bugs in the non-block MATLAB/Octave output 2023-01-10 15:58:45 +01:00
Sébastien Villemot bae04fa899
ModelTree::findGccOnMacOS() now returns a std::filesystem::path 2023-01-10 11:48:33 +01:00
Sébastien Villemot 253fbbe7d6
Use std::filesystem::path in more places 2023-01-05 17:21:28 +01:00
Sébastien Villemot e2c72a1b75
Drop ModelTree::getEquationTags(), and replace it by calls to better interfaces 2023-01-04 16:20:50 +01:00
Sébastien Villemot df3a153356
Simplify residuals output (MATLAB/Octave and C) by dropping lhs/rhs temporary variables 2023-01-04 14:49:07 +01:00
Sébastien Villemot 21fcfa7758
use_dll: fixes to parallel compilation
— No longer call std::exit() from threads when compilation fails, that function
  is marked as not thread-safe under GNU/Linux; and it leads to deadlocks under
  Windows. Rather store the list of failed objects, and exit with a message and
  an error code from the main thread when that list is not empty at the end of
  preprocessing.
– Fix the condition used for waiting until all compilation threads finish;
  checking that the queue is empty is not enough, since a compilation may be
  ongoing. So also track objects whose compilation is ongoing.
2022-12-20 16:52:47 +01:00
Sébastien Villemot 4aa1ff1f73
Sparse representation: fix bug in output of indices in driver and JSON files
Jacobian column numbers were incorrect (it would return internal derivation
IDs).

Ref. dynare#1859
2022-12-12 14:57:49 +01:00
Sébastien Villemot 4f7794a8f9
Sparse representation: compatibility fix with MATLAB < R2020a
For those older MATLABs, the “sparse” function does not accept vectors of
integer data type as indices.

Ref. dynare#1875
2022-12-08 14:35:23 +01:00
Sébastien Villemot 83bfc792af
Sparse representation: fix bug in output of indices in driver and JSON files
It would previously forget to write the indices for the highest derivation
order (e.g. if order=3, then it would only write sparce indices up to 2nd
order).

Ref. dynare#1859
2022-12-07 16:10:03 +01:00
Sébastien Villemot c48248fc0d
Implement time-recursive block decomposition tuned for purely backward/forward/static models
Such a decomposition has to be simulated with periods as the outer loop and
blocks as the inner loop.

It is enabled by default for purely backward/forward/static models, as long as
the “block” option is not given. In that case, “mfs” is also set to 3 by
default (until that value becomes the global default).

M_.time_recursive_block_decomposition is set to “true” when that decomposition
has been performed, “false” otherwise for the traditional decomposition (the
latter has to be simulated with blocks as the outer loop and periods as the
inner loop).
2022-11-30 14:43:44 +01:00
Sébastien Villemot 53add0b2fe
Block decomposition: when falling back to symbolic normalization, use contemporaneous symbolic Jacobian
Previously, it would use a symbolic Jacobian where leads and lags were also
taken into account.
2022-11-28 13:40:49 +01:00
Sébastien Villemot 2e171e28de
New files for helping a user to debug their model
The files are created under <basename>/+debug/dynamic_resid.m and
<basename>/+debug/static_resid.m.

Their purpose is to evaluate separately the LHS and RHS of each equation.
2022-11-16 11:18:09 +01:00
Sébastien Villemot 4807a6c880
use_dll: fix race condition with compilation of power_deriv.{c,h} 2022-11-14 13:45:15 +01:00
Sébastien Villemot 1430ab9cc2
Implement new sparse model representation in C
Ref. dynare#1859
2022-11-04 14:23:29 +01:00
Sébastien Villemot 4ab3e937ea
Implement new sparse model representation in MATLAB/Octave
Ref. dynare#1859
2022-11-04 14:23:29 +01:00
Sébastien Villemot 47290087f6
Provisions for new sparse representation of block-decomposed dynamic/static files
The stochastic mode in currently unsupported.

This commit adds new fields in M_.

This is a preliminary step for dynare#1859.
2022-11-04 14:23:29 +01:00
Sébastien Villemot 836351565d
Fix segfault of notmpterms option with block decomposition
By the way, ensure that temporary terms associated to external functions are
not removed, since they are not optional.
2022-11-04 14:23:29 +01:00
Sébastien Villemot 723fc4139b
Implement new sparse model representation in Julia
Ref. dynare#1859
2022-11-02 15:49:56 +01:00
Sébastien Villemot 0278c8577c
Provisions for new sparse representation of dynamic/static files
The new representation is only supported for MATLAB/Octave, C and Julia output
for the time being. Bytecode and JSON are unsupported.

This commit adds new fields in M_.

This is a preliminary step for dynare#1859.
2022-11-02 15:49:56 +01:00
Sébastien Villemot 9f96db89ba
use_dll: ensure proper cleanup of thread workers threads in case of early exit (e.g. upon failure) 2022-10-17 14:03:27 +02:00
Sébastien Villemot fd9902e87b
use_dll: rewrite the parallel compilation engine with a fixed number of threads
The previous system would spawn as many threads as there are object files to be
compiled (which could lead to hundreds of threads for large block-decomposed
models). This could pose a memory usage problem (even when not just waiting,
threads require memory for their own stack).
2022-10-14 15:33:52 +02:00
Sébastien Villemot 93054cf692
Various filesystem refactorings
– DataTree::packageDir() now takes a std::string_view, returns a
  std::filesystem::path, and no longer creates that directory
– DataTree::writeToFileIfModified() now takes a std::filesystem::path as
  argument
– Do not call DataTree::writeToFileIfModified() for generating MATLAB/Octave
  files, since it does not work (the directory inside which the file is written
  has been deleted by the preprocessor just before)
– Consistently use DataTree::packageDir() everywhere (for compatibility with
  planner_objective)
2022-10-11 16:28:17 +02:00
Sébastien Villemot 5b400b69f0
Use std::filesystem::path::string() when writing paths to std::cout/std::cerr
Otherwise they will be quoted, which is not desirable, especially under
Windows (backslashes will be duplicated).
2022-10-11 11:31:15 +02:00
Sébastien Villemot 3dd40c6c42
use_dll: split generated C file into smaller files that will be compiled in parallel
By the way, factorize the code between the dynamic and static versions.

Ref. #41
2022-10-07 18:04:18 +02:00
Sébastien Villemot dd66459e5f
use_dll: parallelize compilation of multiple object files within single MEX file
In particular, it implements dependency tracking in the thread scheduler, so
that multiple MEX files can share object files.

Ref. #41
2022-10-07 18:04:17 +02:00
Sébastien Villemot 5cf4729ab0
use_dll: dynamically limit the number of concurrently running GCC processes to the number of available logical processors
Ref. #41
2022-10-07 18:04:17 +02:00
Sébastien Villemot 49a530a775
use_dll: allow more flexible output directory in interface of ModelTree::compileMEX() 2022-10-07 18:04:17 +02:00
Sébastien Villemot 4c58451d83
Factorize computing pass for block decomposition
Also add “block_decomposed” data member for tracking whether the block
decomposition has been successful.
2022-10-04 16:00:30 +02:00
Sébastien Villemot 6e69eea3cf
Minor tightening of access specifiers 2022-10-04 16:00:30 +02:00
Sébastien Villemot f6053df754
use_dll: compile MEX files in parallel
Currently two threads are used (one for the dynamic MEX, one for the static
MEX). When the sparse representation is implemented, four threads will be used.

Closes: #41
2022-10-04 16:00:30 +02:00
Sébastien Villemot 3d9ac26aa6
Remove all instances of the “map.find(key)->second” pattern
This is unsafe since the find() method can return a past-the-end iterator,
which should be tested for.

Replace most instances by calls to the std::map::at() method (which throws if
the key is unknown), and which is incidentally more readable.
2022-09-27 12:56:16 +02:00
Sébastien Villemot 18037fd29a
Drop code for supporting temporary terms corresponding to model-local variables
Since model-local variables are now substituted out of the model at an early
stage (see cfb41d291c), such temporary terms are
no longer generated.
2022-09-26 17:34:20 +02:00
Sébastien Villemot 64157d9083
Fix bug in ModelTree::writeParamsDerivativesFileHelper()
Elements of params_derivatives could be accessed without them being defined,
thus causing illegal memory read.

Ensure that these elements always exist. By the way, use std::map::at() instead
of std::map::find() to trigger an exception instead of an illegal memory read
in that case.
2022-09-26 17:17:47 +02:00
Sébastien Villemot 98d4f922ca
Cosmetics 2022-09-20 15:29:19 +02:00
Sébastien Villemot 1088cc4242
Improve informative messages about derivatives and block decomposition
When computing the derivatives or block decomposition of the planner objective,
the epilogue or the original Ramsey model, the preprocessor would talk about
dynamic/static model, which was confusing. It now uses the right terminology.
2022-09-14 17:51:36 +02:00
Sébastien Villemot d67f569035
Always compute block decomposition, even if “block” option was not passed
If block decomposition fails, error out if “block” option was passed, but not
otherwise.

This commit does not modify the generated files.

This is a preliminary step for dynare#1859.
2022-09-13 16:16:00 +02:00
Sébastien Villemot ad40f1365c
Block decomposition: code factorization 2022-07-21 18:20:35 +02:00
Sébastien Villemot a97a41f6c0
Bugfix with temporary terms in block+bytecode
There were actually two distinct bugs, leading to incorrect results in some
corner cases:

– in the “evaluate” mode of the bytecode MEX, the temporary terms of the
  derivatives “evaluate” blocks were not evaluated at runtime; but these
  temporary terms may be needed for residuals of subsequent blocks;

– when the bytecode MEX was only computing residuals of the model (and not 1st
  order derivatives), the temporary terms of the derivatives were not evaluated
  at runtime; but these temporary terms may be needed for residuals of subsequent
  blocks.
2022-07-21 17:22:08 +02:00
Sébastien Villemot 1401c85d6a
Bytecode: drop FCUML instruction
It’s redundant with FBINARY{BinaryOpcode::plus}.
2022-07-20 16:02:24 +02:00
Sébastien Villemot a58109d094
Bytecode: refactor methods for writing .cod and .bin files in the block decomposition case 2022-07-20 16:02:24 +02:00
Sébastien Villemot 35dc7fcd81
Bytecode: fix treatment of temporary terms (in non-block mode)
The “temporary_terms_union.insert(it)” statement introduced in the previous
commit was in the wrong block.

By the way, replace the “switch” by an “if constexpr”.
2022-07-14 09:17:11 +02:00
Sébastien Villemot ae150d2b1f
Bytecode: refactor routines for creating .cod file in non-block mode 2022-07-13 18:51:01 +02:00
Sébastien Villemot 89debf429a
Factorize code for writing JSON output 2022-07-12 18:04:05 +02:00
Sébastien Villemot 157c67e04b
New helpers to simplify common operations with derivation IDs 2022-07-12 16:30:45 +02:00