Subcategory: None · Core · Maths

Reshape

It’s often required to reshape arrays used in Fortran code. This can be achieved in several ways, the most naive of which is to use hand-coded do loops. This is not recommended as it is error-prone and verbose. A better approach is to use the intrinsic reshape function, which is concise and clear.

The most efficient way to reshape arrays is to use pointers. This is a more advanced approach and care must be taken to ensure that (a) the original array is not deallocated while the pointer is still in use and (b) you are aware that modifications to the “reshaped” array will modify the original array and vice versa because they share the same memory.

Read More

Use BLAS/LAPACK Instead of Reimplementing Maths Functions

BLAS (Basic Linear Algebra Subprograms) and LAPACK (Linear Algebra PACKage) are widely used open-source libraries for doing maths, especially matrix operations. They are highly optimised, often for specific CPU architectures by the vendors (Intel, AMD, etc.) themselves, and can be found on all modern HPC systems. Therefore, they are significantly faster than anything we can write ourselves, especially for larger matrices, and should be used in most circumstances.

Read More