HOME
| OPENMP API Specification: Version 5.0 November 2018

2.1.5  Array Sections

An array section designates a subset of the elements in an array.

SVG-Viewer needed.

To specify an array section in an OpenMP construct, array subscript expressions are extended with the following syntax:  

 
[ lower-bound : length : stride] or 
[ lower-bound : length : ] or 
[ lower-bound : length ] or 
[ lower-bound : : stride] or 
[ lower-bound : : ] or 
[ lower-bound : ] or 
[ : length : stride] or 
[ : length : ] or 
[ : length ] or 
[ : : stride] 
[ : : ] 
[ : ]  

The array section must be a subset of the original array.

Array sections are allowed on multidimensional arrays. Base language array subscript expressions can be used to specify length-one dimensions of multidimensional array sections.

Each of the lower-bound, length, and stride expressions if specified must be an integral type expression of the base language. When evaluated they represent a set of integer values as follows:

{ lower-bound, lower-bound + stride, lower-bound + 2 * stride,... , lower-bound + ((length - 1) * stride) }

The length must evaluate to a non-negative integer.

The stride must evaluate to a positive integer.

When the size of the array dimension is not known, the length must be specified explicitly.

When the stride is absent it defaults to 1.

When the length is absent it defaults to ⌈⌈(size -lower-bound)stride⌉⌉, where size is the size of the array dimension.

When the lower-bound is absent it defaults to 0.

The precedence of a subscript operator that uses the array section syntax is the same as the precedence of a subscript operator that does not use the array section syntax.

SVG-Viewer needed.

Note – The following are examples of array sections:  

 
a[0:6] 
a[0:6:1] 
a[1:10] 
a[1:] 
a[:10:2] 
b[10][:][:] 
b[10][:][:0] 
c[42][0:6][:] 
c[42][0:6:2][:] 
c[1:10][42][0:6] 
S.c[:100] 
p->y[:10] 
this->a[:N] 
(p+10)[:N]  

Assume a is declared to be a 1-dimensional array with dimension size 11. The first two examples are equivalent, and the third and fourth examples are equivalent. The fifth example specifies a stride of 2 and therefore is not contiguous.

Assume b is declared to be a pointer to a 2-dimensional array with dimension sizes 10 and 10. The sixth example refers to all elements of the 2-dimensional array given by b[10]. The seventh example is a zero-length array section.

Assume c is declared to be a 3-dimensional array with dimension sizes 50, 50, and 50. The eighth example is contiguous, while the ninth and tenth examples are not contiguous.

The final four examples show array sections that are formed from more general base expressions.

The following are examples that are non-conforming array sections:  

 
s[:10].x 
p[:10]->y 
*(xp[:10])  

For all three examples, a base language operator is applied in an undefined manner to an array section. The only operator that may be applied to an array section is a subscript operator for which the array section appears as the postfix expression.

SVG-Viewer needed.

SVG-Viewer needed.

SVG-Viewer needed.

Fortran has built-in support for array sections although some restrictions apply to their use, as enumerated in the following section.

SVG-Viewer needed.

RestrictionsRestrictions to array sections are as follows: