Contents of the function run well when timed alone, but not when they are in a loop inside the function

  1. There are many global variables in Gnew!. Non-const globals inhibit type inference during compilation and hurt performance at runtime. I can’t say for sure, but it could very well be causing overhead that stretched the expected ~20 minutes to ~73 minutes. Even 1 non-const global can seriously hamper a method. The usual fix is to create method arguments and to pass the values to them in the function call.
  2. You also didn’t post or describe the values for many global variables: rickshift, rick0, shift, pd, dd, Tshift.
  3. You don’t say what the arguments D and m_init in Gnew!(D, m_init) are.
  4. There are things in Gnew! I can’t make sense of.
    • The argument d (which the function call passes D to) isn’t used.
    • m is commented as a Tuple (nz,ny,nx,nT) of integers, which is fine. But m[iz,iy,ix, :] is either multidimensional indexing or making a Vector with type m, and neither of those things is consistent with the comment.
1 Like