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

Assignment to Allocatable Array

kulachi
Beginner
1,038 Views
Why would the following not work:
-------------------------------------------------------
PROGRAM Test
IMPLICIT NONE

INTEGER, ALLOCATABLE :: Alt(:)
INTEGER, DIMENSION(8) :: Fxd

Fxd = [1, 2, 3, 0, 5, 0, 7, 8]

Alt = pack(Fxd, Fxd .NE. 0)

WRITE(*,*) Alt

!DEALLOCATE(Alt)

END PROGRAM Test
-------------------------------------------------------

According to Metcalf et al. Fortran 95/2003 PP. 298, the direct assignment to an allocatable array (Alt) is possible due to an extension in Fortran 95 standards (Ch. 12).

I am using Intel Fortran Compiler Ver. 10.1.021 on MSXP SP3.

- Kulachi
0 Kudos
4 Replies
Steven_L_Intel1
Employee
1,038 Views
Because we didn't want to slow down applications written to the F90/95 standard, which required that Alt already be allocated to the correct shape, the F2003 feature of automatic reallocation is disabled by default. You can enable it with the option /assume:realloc_lhs.
0 Kudos
kulachi
Beginner
1,038 Views
Because we didn't want to slow down applications written to the F90/95 standard, which required that Alt already be allocated to the correct shape, the F2003 feature of automatic reallocation is disabled by default. You can enable it with the option /assume:realloc_lhs.
Thank you Steve. In the help on /assume:realloc_lhs, it is mentioned that: "This feature may cause extra overhead at run time." Would it be true if we adhere to Fortran 2003 standards strictly? I am a little worried on that.

-Kulachi
0 Kudos
Steven_L_Intel1
Employee
1,038 Views
If you want the F2003 semantics, then you need the "overhead", which is the added code to do the automatic deallocation/reallocation. If you know that the arrays are always allocated to the correct shape, then you don't need that option.
0 Kudos
kulachi
Beginner
1,038 Views

Many Thanks Steve!

-Kulachi
0 Kudos
Reply