Use the Fortran 2008 CONTIGUOUS attribute

The loop is multi-versioned for unit and non-unit strides in assumed-shape arrays or pointers, but marked versions of the loop have unit stride access only. The CONTIGUOUS attribute specifies the target of a pointer or an assumed-shape array is contiguous. It can make it easier to enable optimizations that rely on the memory layout of an object occupying a contiguous block of memory.

Example

real, pointer, contiguous :: ptr(:)
real, contiguous :: arrayarg(:, :)
When multiple calling routines are involved, to tell the compiler assumed-shape arrays and/or pointers are always contiguous in memory, use the following options available in Version 18 and higher of the Intel® Fortran Compiler:
TypeWindows* OSLinux* OS
assumed-shape array/assume:contiguous_assumed_shape-assume contiguous_assumed_shape
pointer/assume:contiguous_pointer-assume contiguous_pointer

Note: Results are indeterminate and could result in incorrect code and segmentation faults if the user assertion is wrong and the data is not contiguous at runtime. To check at runtime if targets of contiguous pointer assignments are indeed contiguous in memory, use the following options available in Version 18 and higher of the Intel® Fortran Compiler:
Windows* OSLinux* OS
/check:contiguous-check contiguous

Example

$ ifort -DCONTIG -check contiguous -traceback

forrtl: severe (408): fort: (32): A pointer with the CONTIGUOUS attributes is being made to a non-contiguous target.
In this example, the compiler detects the assignment of a contiguous pointer to a non-contiguous target.The -traceback (Linux* OS)/ /traceback (Windows* OS) option identifies the function and source file line number at which the incorrect assignment occurs. It is not necessary to compile with the debugging option -g (Linux* and macOS* OS) / /Zi (Windows* OS) to get this traceback.

Read More