-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Complex pointer to a real array and vice-versa #323
Comments
One thing that might be relevant here: often times in FFT it is possible to compute the transformation faster if all the real parts are stored first, and then all the imaginary parts. In other words, if |
@certik This goes beyond and looks more complex than my proposal, which is actually very simple. An alternative syntax has been proposed on the discourse group: |
Your proposal is only simple if you assume that Fortran prescribes an ABI/layout. In most cases however, the Fortran standard does not prescribe a particular layout. |
I don't know, but I think that the memory layout for the complex type is already significantly constrained by the existing rules. |
About the |
One difficulty here is if the pointed object is itself a pointer: the compiler has then no mean to check the contiguity at compile time. EDIT not a problem actually, I forgot that pointers could have the |
I think that we should extend Fortran to allow to select a memory layout of arrays. Just like in C++ the array support ( All I am saying is to keep the door open to allow to select array layouts and for all the features to still work. |
Putting aside my proposal, I have some doubt about the feasibility of a "blocked layout" for the complex type: complex, layout(block), target :: c(n) ! n > 1
complex, pointer :: s ! s is a scalar
s => c(1) With this layout the real part of c(1) would be for instance at address |
I think this last case is probably why the interleaved layout is currently used. You can imagine passing |
I am wondering if there could be an alignment issue here...
Compilers are supposed to handle the above case anyway, because they are also supposed to handle the similar case:
But can it have performance issues? Maybe aligning complex numbers on odd 4-bytes boundaries (that is on 4*(2*k+1) addresses) is a performance killer... Just wondering, I have no clue about that. If it was, maybe only |
In many codes that use FFTs and the Fourier domain one need to alternatively work on the same array as real or as complex numbers. Different tricks have to used, none being really satisfactory, e.g.:
Instead, the standard should provide a way to have a complex pointer to a real array:
And vice-versa
Of course some constraints would be needed:
c(:)%re
shall be equivalent tor(1::2)
andc(:)%im
shall be equivalent tor(2::2)
, which enforces the real component to be stored first (de-facto standard in all compilers that I know).The text was updated successfully, but these errors were encountered: