I do apologize if I bring back a topic that’s already been discussed several times, but I couldn’t find much discussion on the approach I’m trying to use here.
Working on a Schur
decomposition function for LAPACK, I want to spare an allocation by splitting a complex
output array into two real
arrays, without additional internal reallocations/copies (see i.e. how dgees
outputs two real arrays for the complex eigenvalues). I came up with this approach (try it at compiler explorer):
complex(rk), allocatable, target :: arr(:)
real(rk), pointer :: rreal(:),rimag(:)
allocate(arr(10))
rreal => arr%re ! works in gfortran, wow!
rimag => arr%im
I think this may be a great and legal way to cast one complex array to two reals, at least it seems consistent to a pointer to a component in a derived type, so I think it may be legal. However:
- works in gfortran and flang but not in ifx (internal compiler error) nor ifort (internal compiler error)
- In both gfortran and flang, there 8 bytes between real values of the pointer array, as I would expect the memory layout of the complex array to be [re,im,re,im,re,im,…]
- gfortran reports
is_contiguous==.true.
while flang reportsis_contiguous==.false.
. Does that mean that gfortran stores memory as [re,re,re,…,im,im,im,…]? or is it just a compiler bug?
So I would like to ask any of the compiler and standard experts on here what is your view! Clearly it does not seem ready for production at this point, (too much uncertainty in compiler support), and I will revert to having one slower additional allocation with data copy.