Nice talk @rouson !
The PRIMA project followed strictly the “No More Loops (Than Necessary)” principle . It is nice to know that the same rule has been adopted in Berkeley Lab.
I also take the viewpoint that loops should be replaced with array (matrix/vector) operations whenever possible.
Quoting my old post “Automatic arrays and intrinsic array operations: to use or not to use? ”:
For me, one of the core strengths of Fortran is its native support for matrices and matrix/vector operations . By “native support for matrices”, I mean particularly automatic arrays — to get a matrix, you do not need to do anything more than declaring it. As for matrix/vector operations, I mean intrinsic array operations such as matmul, transpose, dot_product, and broadcasting.
Thanks to such support, we can write scientific computing code in a way that is very similar to how the algorithms are formulated in mathematics. Without such support, a language should not be called a “Formula Translator”.
Take matrix/vector operations as an example. Without intrinsic support for them, we have to either re-invent these wheels ourselves, or code them as loops whenever such operations appear in an algorithm. However, as a mathematician, I can tell that mathematicians rarely consider matrix/vector operations as loops — loops are only how we calculate them, but not how we define/understand them. Loops are used only when we describe truly iterative algorithms, e.g., CG, steepest descent, …
Not surprisingly, most other popular languages in scientific computing are also strong at supporting matrices and matrix/vector operations. My most familiar language is MATLAB — if you call it a language. It supports almost all matrix/vector operations you can name. A well-knowledged MATLAB programmer can code a sophisticated algorithm without using any loop but only using matrix/vector operations.
Indeed, as a common principle in MATLAB programming, you should never code a matrix/vector operation in loops. It is a bad practice to re-invent any tool that the language intrinsically provides. You may argue that this is because MATLAB is slow at loops as a scripting language. But I understand it from a more philosophical perspective: why does the language provide the functionality if we are not encouraged to use it?
2 Likes