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

assignment of derived-type arrays

David_Smith1
Beginner
694 Views
Yesterday I downloaded a demo version of the "Intel Fortran Compiler
Professional Edition for Mac OS* X". One of my large programs got
some wrong results when I tested it with this compiler.
Here is a small test program that shows some of what I was doing.
Both my large program and this test program compile with no error messages
and give correct results with all of the following compilers:
gfortran, g95, nagfor (all on a Mac), and lahey (on a pc).
I will appreciate any help you can give me.
Thanks,
David Smith, 23 July, 2010
===============================================================================
! Program to test the creation and assignment of derived-type arrays.
! It creates an array of type(f) objects, converts it to an array of doubles,
! then assigns that to double precision array v1.
! Next it creates the same array of type(f) objects, then assigns that to type(f) array fv2.
! Expected output: (compiling with gfortran, g95, nagfor, or lahey gives this output)
! V1 = 3.1540000438690186 7.2300000190734863 6.1449999809265137
! FV2 = 3.1540000438690186 7.2300000190734863 6.1449999809265137
!
! Check components: FV2(1)%FV = 3.1540000438690186
! FV2(2)%FV = 7.2300000190734863
! FV2(3)%FV = 6.1449999809265137
! Intel fortran output:
! ifort ArrayTest2.f90 -o ArrayTest2 (ifort -v ==> Version 11.1) output:
! V1 = 3.1540000438690186 7.2300000190734863 6.1449999809265137
! FV2 = 6.1449999809265137 6.1449999809265137 6.1449999809265137
!
! Check components: FV2(1)%FV = 6.14499998092651
! FV2(2)%FV = 6.14499998092651
! FV2(3)%FV = 6.14499998092651
MODULE TYPE_F
TYPE F
DOUBLE PRECISION :: FV
END TYPE
INTERFACE TO_F
MODULE PROCEDURE REAL_TO_F
END INTERFACE
INTERFACE TO_DP
MODULE PROCEDURE ARRAY_F_TO_DOUBLE
END INTERFACE
INTERFACE ASSIGNMENT (=)
MODULE PROCEDURE ARRAY_F_EQUALS
END INTERFACE
CONTAINS
FUNCTION REAL_TO_F
REAL :: R
TYPE (F) :: REAL_TO_F
REAL_TO_F%FV = R
END FUNCTION REAL_TO_F
FUNCTION ARRAY_F_TO_DOUBLE(A)
TYPE (F), DIMENSION(:) :: A
DOUBLE PRECISION, DIMENSION(SIZE(A)) :: ARRAY_F_TO_DOUBLE
INTEGER :: J
DO J = 1, SIZE(A)
ARRAY_F_TO_DOUBLE(J) = A(J)%FV
ENDDO
END FUNCTION ARRAY_F_TO_DOUBLE
SUBROUTINE ARRAY_F_EQUALS(A,B)
TYPE (F), DIMENSION(:) :: A, B
INTEGER :: J
INTENT (INOUT) :: A
INTENT (IN) :: B
DO J = 1, SIZE(B)
A(J)%FV = B(J)%FV
ENDDO
END SUBROUTINE ARRAY_F_EQUALS
END MODULE TYPE_F
PROGRAM ITEST
! Test derived-type array assignments.
USE TYPE_F
TYPE (F) :: FV2(3)
DOUBLE PRECISION :: V1(3)
! Create an array of type(f) objects, convert it to an array of double precision
! numbers, and then assign that to double precision array v1.
V1 = TO_DP( (/ TO_F( 3.154 ) , TO_F( 7.230 ) , TO_F( 6.145 ) /) )
! Create an array of type(f) objects, and assign it to fv2.
FV2 = (/ TO_F( 3.154 ) , TO_F( 7.230 ) , TO_F( 6.145 ) /)
WRITE (*,*) " "
WRITE (*,"(A,3F20.16)") " V1 = ",V1
WRITE (*,"(A,3F20.16)") " FV2 = ",TO_DP(FV2)
WRITE (*,*) " "
WRITE (*,*) " Check components: FV2(1)%FV = ",FV2(1)%FV
WRITE (*,*) " FV2(2)%FV = ",FV2(2)%FV
WRITE (*,*) " FV2(3)%FV = ",FV2(3)%FV
WRITE (*,*) " "
END PROGRAM ITEST
0 Kudos
2 Replies
Steven_L_Intel1
Employee
694 Views
I am sorry to say that you have found a bug in the compiler. I find it very puzzling since the first use of the array constructor works properly. At first I wondered if this was the known issue of using Xcode 3.2.2, but it isn't - I can reproduce it on Windows too.

I have escalated this to the developers as issue DPD200158415. As I learn more about this, I will let you know. Thank you for letting us know about the problem and we'll fix it as soon as we can.
0 Kudos
Steven_L_Intel1
Employee
694 Views
We have found the cause of this problem and expect to have the fix included in our next major release, scheduled for November. The problem is not in the array constructor itself but rather this being the argument to a procedure, invoked because of the defined assignment.

A workaround is to replace the array defined assignment procedure with an ELEMENTAL scalar procedure, such as:

[fortran]    ELEMENTAL SUBROUTINE ARRAY_F_EQUALS(A,B)
      TYPE (F) :: A, B
      INTENT (INOUT) :: A
      INTENT (IN) :: B
         A%FV = B%FV
    END SUBROUTINE ARRAY_F_EQUALS[/fortran]
This works and may be useful to you.
0 Kudos
Reply