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

Intel Fortran 12.0.0 Bug with Allocate & Source Clause

David_Bal
Beginner
447 Views
There seems to be a bug with Intel Fortran 12.0.0 that didn't exist in version 11.1 with Allocate & the Source clause. With version 11.1 you could allocate an array with the source clause by defining bounds and have those bounds carry over into the new array. This doesn't happen with version 12.0.0. In version 12.0.0 the array bounds of the newly allocated array always start at 1. Please see the example code and the execution below:
[fortran]program test
implicit none

integer, allocatable, dimension(:) :: a, b

! ALLOCATE ARRAY A
allocate (a(10:20))

! ALLOCATE B WITH FORTRAN 2003 SOURCE CLAUSE
allocate (b, source=a(11:20))
print *,lbound(b,dim=1),ubound(b,dim=1) ! PRINT ARRAY BOUNDS (should be 11 to 20)

! DEALLOCATE TO START OVER
deallocate (b)

! ALLOCATE B FORTRAN 90 WAY WITHOUT SOURCE CLAUSE
allocate (b(11:20))
b = a(11:20)
print *,lbound(b,dim=1),ubound(b,dim=1) ! PRINT ARRAY BOUNDS (should be 11 to 20)

end program test[/fortran]

david@david-GA:~/workspace/test$ ifort -v
Version 11.1
david@david-GA:~/workspace/test$ ifort test.f90
david@david-GA:~/workspace/test$ ./a.out
11 20
11 20


david@david-GA:~/workspace/test$ ifort -v
Version 12.0.0
david@david-GA:~/workspace/test$ ifort test.f90
david@david-GA:~/workspace/test$ ./a.out
1 10
11 20

Any thoughts?
0 Kudos
2 Replies
Hirchert__Kurt_W
New Contributor II
447 Views
It looks like ifort had a bug in version 11.1 that was fixed in version 12.0.0.

a(11:20) is an array section. The lbound of any array section is 1; the ubound of any array section is the size of the array in the corresponding dimension. Version 12.0.0 allocated b with the same lbound and ubound as the supplied source; version 11.1 didn't!

The fact that lbound(a(11:20)) is 1 rather than 11 surprises many people. That may be why the original implementation made that error.

-Kurt
0 Kudos
David_Bal
Beginner
447 Views

Too bad. I preferred the "incorrect" implementation.

0 Kudos
Reply