Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Offset field in VF array descriptor

Jugoslav_Dujic
Valued Contributor II
679 Views
Background: using the documentation in the man page "Handling Arrays and Fortran Array Descriptors" and some reverse-engineering I wrote a neat C++ template class which emulates VF array descriptors, basic Fortran-95 array operations, and is interoperable with VF assumed-shape, pointer and allocatable arguments (will be published soon on my website). So far so good.

Question (mainly for developers): however, I'm uncertain about exact semantics and usage of the offset field, quote:
  • The third longword (bytes 8 to 11) contains the offset. The offset is added to the base address to define the start of the array.
As I concluded, this has value of -sizeof(T) for simple, 1-based arrays of type T, and it's supposed to define the distance between the actual ARRAY(1) and hypothetical ARRAY(0)... or something along these lines.

But, the entire field seems totally redundant: everything about array element addressing and indexing can be concluded from the base address and DIMS_INFOs of appropriate dimensions. My code, (where exact calculation of that offset is neglected) seems to work just fine in Fortran (using descriptor structure passed from C++ code). Is this just a leftover from older VF versions? Is it used at all for array indexing? If it is, what is the exact semantics (I'm talking about complex cases such as array sections starting at non-1 indices, arrays witl lbound different than zero, etc.)?

0 Kudos
4 Replies
Les_Neilson
Valued Contributor II
679 Views

Total guess on mypart :-)

Could it be used for handling array slices? or arrays with lower bounds other than 1?

Les

0 Kudos
Les_Neilson
Valued Contributor II
679 Views

Sorry Jugoslav somehow I totally missed the last paragraph of your original post.

Perhaps I need a bigger screen :-)

Les

0 Kudos
Jugoslav_Dujic
Valued Contributor II
679 Views
Partially answering my own post: I found the following on gfortran mailing list:

The data component points to the first element in the array.
The offset field is the position of the origin of the array
(ie element (0, 0 ...)). This may be outsite the bounds of the array.
...
An element is accessed by
data[offset + index0*stride0 + index1*stride1 + index2*stride2]
data[offset + index0*stride0 + index1*stride1 + index2*stride2]
This gives good performance as the computation does not involve the
bounds of the array. For packed arrays, this is optimized further by
substituting the known strides.


Apparently, this could be used to speed up array element index calculation, as it is not necessary to subtract 1 from each index (in order to achieve "C-style" zero-based memory indexing, which is more machine-friendly in terms of efficiency). I assume IVF uses the same semantics... if it uses it at all.
0 Kudos
jimdempseyatthecove
Honored Contributor III
679 Views

From my understanding of how this works is the Offset is the number you add to the index calculations to produce the final address. Fortran has range values for each index and is not (necessarily) zero based as in C/C++.

As an optimization the index supplied is not un-biased back to zero prior to producing the product of the index by the range of the prior index. For example, on a 3 indexed array this technique would eliminate threesubtraction operations. On a one indexed array it eliminates one subtraction operation.

e.g. X(I, J, K)

Effective address =
OffsetX
+ K*SizeSecondIndex*SizeFirstIndex
+ J*SizeFirstIndex
+ I

As opposed to

Effective address =
OffsetX
+ (K-LowValueThirdIndex)*SizeSecondIndex*SizeFirstIndex
+ (J-LowValueSecondIndex)*SizeFirstIndex
+ I-LowValueFirstIndex

(OffsetX would be different for each method)

0 Kudos
Reply