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

Large do loop bounds

nameiii
Beginner
425 Views

I have a code with a simple do loop, DO I = J,K, with I,J,K all Integer(4).

For handling exceptional situations the limits sometimes get set to large values. In particular sometimes one has J = HUGE(J) and K = - HUGE(K). The intention is that the loop won't execute in this situation. However on CVF 6.6 it is executed at least once (it fails in the first iteration so I don't know if it would try to execute a second time). I guess the number of possible iterations is calculated as K-J+1 and, while this should be negative, it overflows to give a positive number. Using HUGE(J)/4, -HUGE(K)/4 works fine.

I realise CVF 6.6 is no longer supported (I have a copy of Intel 9.0 and am intending to change soon). However I am curious to know whether this is a compiler bug or is consistent with the Fortran standard (in which case I'll have to be much more careful in using HUGE in future). Thanks for any help.

0 Kudos
1 Reply
Steven_L_Intel1
Employee
425 Views
It is consistent with the standard. The standard specifies how you determine the loop count , as you say,by computing the expression (end-start)+1. If this expression cannot be computed, then the results are undefined. It falls in the category of "complexity".
0 Kudos
Reply