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

Assignment to allocatable module variables

koen_poppe
Beginner
301 Views
! ifort_beta --version
! ifort_beta (IFORT) 12.1.5 20120612
! Copyright (C) 1985-2012 Intel Corporation. All rights reserved.
!
! ifort_beta -o allocatable_assignment -free -Tf allocatable_assignment.f03
! ./allocatable_assignment
! -> init_array
! array allocated? F << array should be allocated
!
! -> init_array_manual
! array allocated? T
! array values 1 2 3
!
! -> init_array
! forrtl: severe (174): SIGSEGV, segmentation fault occurred
! Image PC Routine Line Source
! allocatable_assig 0804A6BD Unknown Unknown Unknown
! allocatable_assig 08049E04 Unknown Unknown Unknown
! libc.so.6 4007BBD6 Unknown Unknown Unknown
! allocatable_assig 08049CA1 Unknown Unknown Unknown
! make: *** [run] Error 174
module allocatable_module
implicit none
public
save
integer, dimension(:), allocatable :: array
contains
subroutine init_array()
print *, "-> init_array"
array = (/ 1,2,3 /)
end subroutine init_array
subroutine init_array_manual()
print *, "-> init_array_manual"
if( allocated(array) ) deallocate(array)
allocate(array(3))
array(:) = (/ 1,2,3 /)
end subroutine init_array_manual
end module allocatable_module
program allocatable_assignment
use allocatable_module
implicit none
call init_array()
call check()
call init_array_manual()
call check()
call init_array()
call check()
contains
subroutine check()
print *, " array allocated? ", allocated(array)
if( allocated(array) ) then
print *, " array values ", array
deallocate(array)
end if
print *, ""
end subroutine check
end program allocatable_assignment
0 Kudos
3 Replies
Steven_L_Intel1
Employee
301 Views
Add -standard-semantics (or -assume realloc_lhs). By default, Intel Fortran does not do automatic (re)allocation of assignments to allocatable arrays.
0 Kudos
koen_poppe
Beginner
301 Views
Great! That solves the issue indeed, but what is the reasoning behind this deviation from the Fortran 2003 standard? Performance?
Thank you for the quick solution!
Best regards
0 Kudos
Steven_L_Intel1
Employee
301 Views
Yes, performance. Programs that conformed to Fortran 90 or 95 would have the array already allocated properly. There are some other default behaviors that are not F2003-conformant and that we have switches to change. -standard-semantics gets them all. Some other implementations (Cray is one, I think) do the same.
0 Kudos
Reply