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

Allocatable Array Shape Conformance

asymptotic
Einsteiger
1.286Aufrufe

The IVF11.1.067 does not give some compile / run-time error for allocatable array shape conformance problem. For example:

subroutine Array_Shape_Conformance

implicit none

real:: ra(3, 3), rb(4, 4), rc(4, 4)

real, allocatable:: sa(:, :), sb(:, :), xy(:)

ra = 3.0; rb = 4.0;

! The shapes of the array expressions do not conform.

! rc = ra + rb ! *** *** *** error

allocate( sa(3, 3), source = ra )

allocate( sb(4, 4), source = rb )

rc = sa + sb ! the compiler give no compile or run-time error

write(unit = *, fmt = "(4F12.7)") rc

return

end subroutine

0 Kudos
5 Antworten
jimdempseyatthecove
Geehrter Beitragender III
1.286Aufrufe
The above example should be a runtime error when bounds checking enabled.

While there is sufficient information at compile time to determine that the expression is in error (due to knowing the shape of the arrays), I do not believe there is something in the specification to require the compiler to detect such an error. A "lint" feature should detect this error in programming.
TimP
Geehrter Beitragender III
1.286Aufrufe
As rc is big enough to accommodate all SIZEs involved, this may not strictly produce a bounds check error. I agree with Jim that it ought to produce a run time error when /check is set at compile time. Apparently, other brands of compilers agree also, judging by web references to updates to diagnose such problems.
Early f90 compilers diagnosed these unconditionally, but the performance hit was unacceptable.
I notice the results produced by ifort and gfortran are different, both problematical.
Steven_L_Intel1
Mitarbeiter
1.286Aufrufe
The Intel compiler does not do run-time shape checking. This is on our wish list. Sometimes, array bounds checking will be triggered by such an error but not always.
asymptotic
Einsteiger
1.286Aufrufe
Thanks a lot.
#1 what's meaning of -- lint
#2 what's meaning of -- rc
#3 I suggest: the IVF compiler give a run-time switch for (allocatable) array shape checking.
TimP
Geehrter Beitragender III
1.286Aufrufe
lint is an old Unix term for static syntax checking.
rc is the name you gave your array.
Antworten