Strange behavior in data assignment/output

Strange behavior in data assignment/output

Hi,

I'm sorry for this unspecific subject but it's hard to find a title for this problem. I have the following minimal example:

File: base.f90

module m_type
  implicit none

  type mytype
    real(kind=8) :: array(6)
  end type mytype

  type (mytype) :: te

  data te%array /1.d0, 1.d0, 1.d0, 0.d0, 0.d0, 0.d0/

contains

  subroutine output_0(number, name)
    implicit none
    real(kind=8) :: number
    character(*) :: name

    write(*,*) name, number

  end subroutine output_0

  subroutine output_1(typ, name)
    implicit none
    type(mytype) :: typ
    character(*) :: name

    write(*,*) name, typ%array

  end subroutine output_1

end module m_type

 

File: main.f90

program test
  use m_type
  implicit none
      integer, parameter :: steps = 10, periods = 10
      integer :: i1
      type(mytype) :: t(steps*periods)

      do i1 = 1, steps*periods
        t(i1) = te
      enddo

      call output_0(t(2)%array(1), "t2(1) = ")
      call output_1(te, "te = ")
!      call output_1(t(2), "t(2) = ")
!      write(*,*) t(steps)%array(1)

end program test

I would expect the following output:

 t2(1) =    1.00000000000000              
 te =    1.00000000000000        1.00000000000000        1.00000000000000     
  0.000000000000000E+000  0.000000000000000E+000  0.000000000000000E+000 

Instead, I get the following:

ifort --version
ifort (IFORT) 13.0.0 20120731                     
Copyright (C) 1985-2012 Intel Corporation.  All rights reserved.

ifort base.f90 main.f90 -o Test
./Test

 t2(1) =   0.000000000000000E+000
 te =    1.00000000000000        1.00000000000000        1.00000000000000
  0.000000000000000E+000  0.000000000000000E+000  0.000000000000000E+000

This does not occur in the following cases:

  • -debug full
  • uncomment one of the two last lines in main.f90
  • use a single file for the code
  • only use "steps" as an upper boundary in the do-loop

Is there something wrong with the data-statement in module m_type (by the way, is there a way to define a type as a parameter?)? Or is this a compiler bug? gfortran works as expected, even if I use optimization.

Thank you!

2 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.
Best Reply

I can reproduce this through the 14.0.2 compiler, but not in the beta version of the release planned for later this year.

There's nothing wrong with your use of the DATA statement. You can create a parameter constant of derived type, like this:

type (mytype), parameter :: te = mytype(array=[1.d0, 1.d0, 1.d0, 0.d0, 0.d0, 0.d0])

 

Retired 12/31/2016

Leave a Comment

Please sign in to add a comment. Not a member? Join today