Arrays

Arrays are what Fortran was built around, and this is the longest part of the course. Declarations and constructors, indexing and bounds, whole-array operations and sections come first, then WHERE, FORALL and the allocatable arrays. The assumed-shape and assumed-size arguments follow, the reduction intrinsics, MATMUL, RESHAPE and the sorting of an array. The part ends on column-major order, which decides what a loop over a matrix costs.

4.1 Array declarations and constructors DIMENSION, the shape, array constructors, implied DO and the lower bound Open 4.2 Indexing, bounds and zero-sized arrays the default lower bound, LBOUND and UBOUND, SIZE and SHAPE, and a bound that is not one Open 4.3 Whole-array operations an operation on two arrays is element by element, a scalar broadcasts, and the shapes must conform Open 4.4 Sections, strides and triplets a(i:j), the stride a(1:n:2), a section is not a copy, and a section as an argument Open 4.5 WHERE and ELSEWHERE a masked assignment, WHERE with ELSEWHERE, the mask evaluated once, and a masked reduction Open 4.6 FORALL FORALL as an assignment, its mask, the difference from DO CONCURRENT, and why it is rarely needed Open 4.7 Allocatable arrays ALLOCATE, DEALLOCATE, automatic deallocation at the end of scope, MOVE_ALLOC and a growing array Open 4.8 Assumed-shape arguments a(:), the lower bound inside the procedure, SIZE and the explicit interface it needs Open 4.9 Explicit-shape and assumed-size arrays a(n) as a dummy, a(*) as the old form, sequence association and the bounds a caller promises Open 4.10 SUM, COUNT, ANY, ALL and the reductions SUM, PRODUCT, MAXVAL, MINVAL, COUNT, ANY, ALL, the DIM argument and a masked reduction Open 4.11 MATMUL, DOT_PRODUCT and TRANSPOSE matrix multiplication, the inner product, TRANSPOSE, and a matrix-vector product by hand Open 4.12 RESHAPE, SPREAD, PACK, UNPACK, CSHIFT RESHAPE with its PAD and ORDER, SPREAD, PACK and UNPACK, CSHIFT and EOSHIFT Open 4.13 MAXLOC, MINLOC and FINDLOC MAXLOC and MINLOC with DIM, the BACK argument, FINDLOC with a value, and a mask Open 4.14 Sorting arrays a bubble sort by hand, MAXLOC as a selection sort, and the intrinsic route with an index array Open 4.15 Column-major order and array memory the first index moves fastest, a 2D array in memory, the loop order that matters and a timing Open

Lessons