Search code examples
iterationcompile-timerunge-kutta

How to get less compile time for Runge Kutta Method


I want to simulate 8 differential equations by Runge Kutta fourth-order method, the number of iterations is around 60,000,000(the time step is 0.001 ms and the total time is 60s), in which way I will have less compile time to solve these equations? (I've tried solving these equations with 6 million iterations by Euler method that takes around 3 days to solve it)


Solution

  • That question does not make sense. If you optimize, you optimize everything. Apart from the language, you should also use a higher order method that allows you to take larger step sizes. And you should use an adaptive step size strategy so that you can skip over large stretches of "boring" dynamics.

    Only use fixed step RK4 over relatively short segments to get a feeling for the system and to calibrate the higher order methods against.

    As for choice of programming language, in compiled languages the same algorithm should perform about equally well if all the details like vector operations are implemented directly. It is only when working with vector abstractions and vector operations that you might find differences that are caused by implementation choices.

    For instance, in a vector addition one would have to decide if one only implements an addto in-place addition or also a variant that constructs a new object, implying frequent disallocation of intermediate results etc. But for RK implementation one only needs the axpy type of operations without any intermediate results. For the computation of the derivative vector this might be again different.