Optimizing vectorized array operations

As @JohnCampbell wrote, this is a harsh statement.

Typically even a HPC code is made of >95% of non performance-critical sections. Using array syntax there is most of time fine.

What about the few % that are critical? Depends…

I tend to write array syntax in the first place as long as the array syntax is at least as readable as the equivalent loop, because it also corresponds to cases where the compilers have got quite good at optimizing them (we are no longer in the 90’s where compilers were struggling very hard with the array syntax).

As soon as the full array syntax gets difficult to read, I write it as a mix of loops and simpler array syntax. Again with readability/simplicity in mind.

At the end, when profiling the code, if a section with some array syntax tend to take a lot of time, I investigate and possibly try rewriting it with only loops. But in my experience, the full “do loop” approach is rarely really more efficient than a mixed “do loop”+“array syntax” (although it sometimes happens, but again with some experience I can often spot this cases early).

7 Likes