[PATCH][RFC]Overloading intrinsics
Toon Moene
toon@moene.org
Wed Oct 31 19:58:00 GMT 2018
On 10/30/2018 04:40 PM, Martin Liška wrote:
Did anyone ever helped you with this error message ? I haven't seen a
reply to the list to that effect ...
> Now I've tried to separate real module and it's usage and I see strange error:
>
> $ cat ~/Programming/testcases/module.f90
> module vector_math
> interface
> function sin(arg)
> !GCC$ attributes simd_notinbranch :: sin
> real, intent(in) :: arg
> real :: sin
> end function sin
> end interface
> end module
>
> $ ./xgcc -B. -Ofast -c ~/Programming/testcases/module.f90
>
> $ cat ~/Programming/testcases/use.f90
> program test_overloaded_intrinsic
> use vector_math
> real(4) :: x(3200), y(3200), z(3200)
>
> ! this should be using simd clone
> y = sin(x)
> print *, y
>
> ! this not
> z = cos(x)
> print *, z
>
> z = sin (z)
> print *, z
> end
>
> $ ./xgcc -B. -Ofast -c ~/Programming/testcases/use.f90
> /home/marxin/Programming/testcases/use.f90:6:10:
>
> 6 | y = sin(x)
> | 1
> Error: Rank mismatch in argument âargâ at (1) (scalar and rank-1)
> /home/marxin/Programming/testcases/use.f90:13:11:
>
> 13 | z = sin (z)
> | 1
> Error: Rank mismatch in argument âargâ at (1) (scalar and rank-1)
What is happening here is that you define an EXTERNAL function "sin"
which, according to your declaration [ I left out the GCC attribute ]:
> function sin(arg)
> real, intent(in) :: arg
> real :: sin
is a real function of a scalar argument returning a scalar result.
However, in using it, you pass it 32000 element arrays of reals (you
don't need, and should omit, the (4) on the real declaration).
This works for the INTRINSIC functions "sin", "cos", etc., because the
Fortran language declares them to be ELEMENTAL.
This means that, while you can pass them a scalar argument and get a
scalar result, you can also pass them a rank-N array and get a rank-N
array result OF THE SAME SHAPE.
I wonder if it works to change the declaration to:
> elemental real function sin(arg)
> real, intent(in) :: arg
> real :: sin
which declares a user-defined, EXTERNAL, ELEMENTAL function called "sin".
Hope this helps,
--
Toon Moene - e-mail: toon@moene.org - phone: +31 346 214290
Saturnushof 14, 3738 XG Maartensdijk, The Netherlands
At home: http://moene.org/~toon/; weather: http://moene.org/~hirlam/
Progress of GNU Fortran: http://gcc.gnu.org/wiki/GFortran#news
More information about the Fortran
mailing list