# Loop crashes

**URL:** <https://forum.dynare.org/t/loop-crashes/4215>\
**Category:** Dynare help (legacy posts)\
**Created:** [10 October 2014 10:55 UTC](https://forum.dynare.org/t/loop-crashes/4215 "2014-10-10T10:55:04Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![petros\_varth](https://forum.dynare.org/letter_avatar_proxy/v4/letter/p/cc9497/32.png) [@petros\_varth](https://forum.dynare.org/u/petros_varth)\
**Post date:** [10 October 2014 10:55 UTC](https://forum.dynare.org/t/loop-crashes/4215/1 "2014-10-10T10:55:04Z")

</div>

Hi All,

I am running a very large loop in which i change some of the parameters of my model.

However, most of the times this loop crashes with the following error:

[quote]Error: Can’t open file two\_country\_currency\_union\_tn\_dynamic.m for writing

Error using dynare (line 114)  
DYNARE: preprocessing failed

Error in welfare\_star\_tn (line 49)  
dynare two\_country\_currency\_union\_tn noclearall;[/quote]

Any hints?

Best,

P.

---

<div class="post-metadata">

**Author:** ![jpfeifer](https://forum.dynare.org/user_avatar/forum.dynare.org/jpfeifer/32/5044_2.png) [@jpfeifer](https://forum.dynare.org/u/jpfeifer)\
**Post date:** [10 October 2014 11:48 UTC](https://forum.dynare.org/t/loop-crashes/4215/2 "2014-10-10T11:48:49Z")

</div>

If you only change parameters, you are not supposed to repeatedly call Dynare. Rather, run Dynare only once and then use the commands you want to run in a loop directly. See [[Loop over parameters](https://forum.dynare.org/t/loop-over-parameters/3335/1))  
Whenever you run dynare itself, you are running the preprocessor, which re-creates all files. It seems that your machine is not quick enough in writing these files so that the previous iteration was not done yet with writing the created files, leading to the crash.

---

<div class="post-metadata">

**Author:** ![hanz](https://forum.dynare.org/letter_avatar_proxy/v4/letter/h/aca169/32.png) [@hanz](https://forum.dynare.org/u/hanz)\
**Post date:** [14 October 2014 06:40 UTC](https://forum.dynare.org/t/loop-crashes/4215/3 "2014-10-14T06:40:48Z")

</div>

I had similar problems while using Dropbox. I paused syncing and the problem was solved.

---

<div class="post-metadata">

**Author:** ![jpfeifer](https://forum.dynare.org/user_avatar/forum.dynare.org/jpfeifer/32/5044_2.png) [@jpfeifer](https://forum.dynare.org/u/jpfeifer)\
**Post date:** [14 October 2014 08:26 UTC](https://forum.dynare.org/t/loop-crashes/4215/4 "2014-10-14T08:26:14Z")

</div>

Let me reiterate my point. Although e.g. Wouter Den Haan and Eric Sims say so in their Dynare notes, you should always avoid running full Dynare within a loop or optimizer. If anyhow possible, make use of the Dynare rountines without running the preprocessor over and over again. This typically requires only small effort and increases speed by several magnitudes.
