Prompted by this suggestion and previous discussion I’ve explored whether it’s possibe to extract array slicing information out of CFI_cdesc_t
using ISO_Fortran_binding.h
.
The aim is to extract array slice information such that when calling a BLAS/LAPACK function with array slices,
call subroutine solve(a(1:10:4,3:15:2))
it may be used avoiding copyin/copyout internally providing a pointer reference and proper inc
rements:
subroutine solve(a)
real, intent(inout) :: a(:,:)
s = strides(a) ! returns [4,2]
call lapack_fun(a(1,1),incx=s(1),...,incx=s(2))
- stdlib_linalg_arrays.h and stdlib_linalg_arrays.c define interoperable array descriptors to pass
CFI_descr_t
(that is compiler-dependent) to fortran - stdlib_linalg_arrays.f90 is the attempt to gather slicing information from inside a function.
Though we can return all information in CFI_descr_t
back to Fortran nicely, I think the problem is impossible to solve, because different slicings can return the same address information. For example:
cfi1 = array_descriptor(a(1:5:3,1:10:6))
call CFI_print(cfi1)
cfi2 = array_descriptor(b(1:6:3,1:10:5))
call CFI_print(cfi2)
returns two CFI objects with the same strides:
# a(1:5:3,1:10:6)
base address : 16D5030D8
total length : 4
CFI version : 1
Variable type : 1027
Rank : 2
1) [1:2], padded every 3 elements
2) [1:2], padded every 30 elements
# a(1:6:3,1:10:5)
base address : 16D502F50
total length : 4
CFI version : 1
Variable type : 1027
Rank : 2
1) [1:2], padded every 3 elements
2) [1:2], padded every 30 elements
both have 30-element strides (5 x 6 slices vs. 6 x 5 slices), so the stride of dimension 2 is undefined in terms of number of elements. @PierU any thoughts?