From 7bec234f7f4b2e4227b975fd7ae9bb8716f39716 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= <sebastien@dynare.org>
Date: Mon, 15 Jun 2020 18:13:51 +0200
Subject: [PATCH] Block decomposition: for evaluate blocks, move the iteration
 loop outside the dynamic file

---
 .../solve_block_decomposed_problem.m                     | 9 ++++++++-
 preprocessor                                             | 2 +-
 2 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/matlab/perfect-foresight-models/solve_block_decomposed_problem.m b/matlab/perfect-foresight-models/solve_block_decomposed_problem.m
index 716c4ac8aa..393e00b492 100644
--- a/matlab/perfect-foresight-models/solve_block_decomposed_problem.m
+++ b/matlab/perfect-foresight-models/solve_block_decomposed_problem.m
@@ -57,7 +57,14 @@ for blk = 1:length(M_.block_structure.block)
         oo_.deterministic_simulation.block(blk).status = true;
         oo_.deterministic_simulation.block(blk).error = 0;
         oo_.deterministic_simulation.block(blk).iterations = 0;
-        [y, T] = feval(funcname, y, oo_.exo_simul, M_.params, oo_.steady_state, T, false, M_.maximum_lag, options_.periods);
+        if M_.block_structure.block(blk).Simulation_Type == 1
+            range = M_.maximum_lag+1:M_.maximum_lag+options_.periods;
+        else
+            range = M_.maximum_lag+options_.periods:-1:M_.maximum_lag+1;
+        end
+        for it_ = range
+            [y, T] = feval(funcname, y, oo_.exo_simul, M_.params, oo_.steady_state, T, it_, false);
+        end
     elseif M_.block_structure.block(blk).Simulation_Type == 3 || ... % solveForwardSimple
            M_.block_structure.block(blk).Simulation_Type == 4 || ... % solveBackwardSimple
            M_.block_structure.block(blk).Simulation_Type == 6 || ... % solveForwardComplete
diff --git a/preprocessor b/preprocessor
index f022c0e16e..ad583adcd4 160000
--- a/preprocessor
+++ b/preprocessor
@@ -1 +1 @@
-Subproject commit f022c0e16e890a5647b16c3ad47547583b794142
+Subproject commit ad583adcd4fc3463910708c86ea4bdc0b70a0826
-- 
GitLab