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

cshift strange output when defining an elemental assignment for the type it shifts

kostas85
Beginner
759 Views
Hello all,
When I define an elemental assignment for a derived type and use cshift for an array of this derived type
I get a strange output. It seems that the {cshift-assignment} "structure" doesn' t correctly replace the last
element with the first when the derived type's assignment is declared as elemental.
There are too possible workarounds. Either defining an intermediate array to store cshift or skipping the "elemental" keyword for theassignment.
I understand that cshift works without defining an assignment for the derived type shifted, however, I think that thisis not the purpose of defining an assignment.
Here is the code:
[fortran]module mytypes_witheq type areal real(kind(0.d0)) :: x end type areal interface assignment (=) module procedure eqreals end interface contains elemental subroutine eqreals(p1,p2) !<----- this causes a problem !subroutine eqreals(p1,p2) ! <----- this seems to work fine type(areal), intent(inout) :: p1 type(areal), intent(in) :: p2 p1%x=p2%x end subroutine eqreals end module mytypes_witheq program test_shifts use mytypes_witheq type(areal), dimension(:), allocatable :: help type(areal), dimension(:), allocatable :: poiarr integer :: i , i1, alloc =3 allocate(poiarr(alloc),help(alloc)) do i=1, alloc poiarr(i)%x = i end do print *, ' ' print *, ' No shift ' do i1=1,alloc print *, poiarr(i1) end do print *, ' ' print *, ' An array of type a_real is used and changes after each cshift' do i=1,alloc print *, ' after ', i, 'shift(s)' poiarr=cshift(poiarr,1) do i1=1,alloc print *, poiarr(i1) end do end do print *, ' ' do i=1, alloc poiarr(i)%x = i help(i)%x = i end do print *, 'An intermediate array of the same type is used but does not change after each cshift' do i=1,alloc print *, ' after ', i, 'shift(s)' help=cshift(poiarr,i) do i1=1,alloc print *, help(i1) end do end do end program test_shifts[/fortran]
The above code gives :
No shift
1.00000000000000
2.00000000000000
3.00000000000000
An array of type a real is used and changes after each cshift
after 1 shift(s)
2.00000000000000
3.00000000000000
2.00000000000000 ! <---- not expected
after 2 shift(s)
3.00000000000000
2.00000000000000
3.00000000000000 ! <---- not expected
after 3 shift(s)
2.00000000000000
3.00000000000000
2.00000000000000 ! <---- not expected
An intermediate array of the same type is used but does not change after each c
shift
after 1 shift(s)
2.00000000000000
3.00000000000000
1.00000000000000
after 2 shift(s)
3.00000000000000
1.00000000000000
2.00000000000000
after 3 shift(s)
1.00000000000000
2.00000000000000
3.00000000000000
If the assignment is not declared as elemental, the output is correct.
Is this a bug ?
Please check it and let me know if you get the same error.
Thank you !
Note ::
ifort -V
Intel Fortran Intel 64 Compiler XE for applications running on Intel 64, Version 12.1 Build 20120612
Copyright (C) 1985-2012 Intel Corporation. All rights reserved.
FOR NON-COMMERCIAL USE ONLY
I have also tested it using the latest windows ifort compiler and the same error appeared.
0 Kudos
3 Replies
JVanB
Valued Contributor II
759 Views
That bug has already been reported > 5 years ago. Progress on this issue seems to have been slow.
0 Kudos
Steven_L_Intel1
Employee
759 Views
I tried the program with the current 12.1 compiler and can see the problem, but the compiler in the next major release (August-September) gets it right:

No shift
1.00000000000000
2.00000000000000
3.00000000000000

An array of type a_real is used and changes after each cshift
after 1 shift(s)
2.00000000000000
3.00000000000000
1.00000000000000
after 2 shift(s)
3.00000000000000
1.00000000000000
2.00000000000000
after 3 shift(s)
1.00000000000000
2.00000000000000
3.00000000000000

An intermediate array of the same type is used but does not change after each c

shift
after 1 shift(s)
2.00000000000000
3.00000000000000
1.00000000000000
after 2 shift(s)
3.00000000000000
1.00000000000000
2.00000000000000
after 3 shift(s)
1.00000000000000
2.00000000000000
3.00000000000000

I looked for issues reported against CSHIFT but the last one was closed in 2010 and isn't this problem. RO, do you have a pointer to a thread where this was reported?
0 Kudos
kostas85
Beginner
759 Views
Many thanks Steve !!
0 Kudos
Reply