# Why solving two differential equations is 8 times slower than solving one?

**URL:** <https://fortran-lang.discourse.group/t/why-solving-two-differential-equations-is-8-times-slower-than-solving-one/1842>\
**Category:** Uncategorized\
**Created:** [September 15, 2021, 1:36am UTC](https://fortran-lang.discourse.group/t/why-solving-two-differential-equations-is-8-times-slower-than-solving-one/1842 "2021-09-15T01:36:48Z")\
**Posts on this page:** 1\
**Showing post:** 6

<div class="post-metadata">

**Author:** ![CRquantum](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/crquantum/32/730_2.png) [@CRquantum](https://fortran-lang.discourse.group/u/CRquantum)\
**Post date:** [September 17, 2021, 4:08am UTC](https://fortran-lang.discourse.group/t/why-solving-two-differential-equations-is-8-times-slower-than-solving-one/1842/6 "2021-09-17T04:08:05Z")

</div>

I did solve the problem by putting the RNG outside the loop, also do not heap arrays.  
If I do not heap arrays, then solving 1 ODE cost 0.4s, while solving two cost 0.9s. So it is as expected. And the problem is solved.

However, if I heap-arrays, solving 1 ODE still cost 0.35s, but solving two cost 3s.  
But I just wanted to know more why heap-arrays can cause a big difference, and how to prevent such performance problem.  
A related heap-arrays topic is here,

> [@Why heap array make my code 6 times slower?](https://fortran-lang.discourse.group/t/why-heap-array-make-my-code-6-times-slower/1858):
>
> Dear all, I am using Intel Fortran OneAPI, I have a code will show you below, which is just a very very very raw my initial version of stochastic\_rk which is based on John Burkardt’s code. John’s version is scaler version can solve 1 SDE. I just made it can slove 2 SDE, it can be extend to solve any number of SDEs. Again, it is a raw version. I have an improved version which I put the random number generator outside the loop so it is faster. Now it is actually another question. See the code b…

---

_[View the full topic](https://fortran-lang.discourse.group/t/why-solving-two-differential-equations-is-8-times-slower-than-solving-one/1842)._
