I am working on a physical-process simulation, set on a large spatial grid. Each cell of the grid contains a set variables representing the status of the model. Let’s say the variables are a, b, c, d, and e, stored as arrays A, B, C, D, and E (all with the same size). Now, I need to perform a bunch of element-by-element arithmetic with these variables. For example, a = b + d; c = a * d; e = 2 * b + 20 * e / a; etc.
In terms of performance, is it better to:
(i) use a single loop to perform all the arithmetic (involving all the different arrays) at each array index; OR
(ii) use multiple loops to run through the array index, with each loop containing one (or at least a subset) of the arithmetic operations; OR
(iii) use broadcasting (e.g. the dot syntax) all the way; OR
(iv) some other way(s) that I have not considered here?
Let’s assume that all loops are sequenced in the memory access-friendly column-major order. (Actually, this is the essence of my questions: Does going through in column-major order help in any way when the loop needs to access multiple arrays?)
I am new to Julia and not a computer scientist, and have yet to know/understand the details of how the compiler goes about things. Any ideas and suggestions would be very welcome. Thank you!