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

CVF to IVF conversion question (evaluating logical expressions)

wiland
Beginner
903 Views
I just converted a CVF project to IVF. I am getting a runtimeerror message on the following statement:
if(J.ne.K.and.JFLAG(JARRAY(L)).ne.1) cycle
The error is that the subscript L of JARRAY has a value 0 which is less than the lower bound of 1.
This statement previously executed fine under CVF. Under CVF, the first part of the logical expression "J.ne.K" was evaluated first. If it was false, the second part of the logical expression was not evaluated because the entire expression would be false regardless of thehow the second part after the .AND. was evaluated. Hence, it did not matter whether the value of L was zero or not.
This does not seem to be the behavior under IVF. I can of course correct the problem by adding a statement to check the value of L(L is neverzero unless J and K are equal). However, is this a change in how logical FORTRAN statements are evaluated? Is there some sort of option to force the compiler to evaluate these logical expressions as it did under CVF?
Bruce Wiland

Message Edited by wiland@att.net on 09-14-2004 07:12 AM

0 Kudos
3 Replies
Steven_L_Intel1
Employee
903 Views
CVF did not deliberately evaluate the expression the way you wanted - you just got lucky. Fortran allows a compiler to evaluate logical expressions in any order that is logically equivalent, and in fact may evaluate "any other expression" that is equivalent (meaning partial evaluation is allowed but not required.)
In short, your code is incorrect and needs to be fixed. A nested IF-THEN is the appropriate solution.
0 Kudos
wiland
Beginner
903 Views
Steve,
Thank you for the explanation. I had already changed it to a nested IF/THEN. I guess I have been lucky for a long time. I have been porting this same code as I have followed the migration path from Microsoft Fortran to Digital Fortran to Compaq Fortran and now to Intel Fortran. This is the first time the code has failed.
I had been under the impression that the logical expression was evaluated from left to right, either because someone toldme that or an earlier compiler documentation said so. Obviously, this was either incorrect or is no longer correct. In either case, thank you for setting the record straight. I wonder how many other places I might have this incorrect code. Oh well.
Bruce
0 Kudos
Steven_L_Intel1
Employee
903 Views
This aspect of the Fortran language has been there "forever" - it has not changed, at least back to F77 if not F66. There is no specification of left-to-right evaluation, nor of "short circuit evaluation", of logical operands.
0 Kudos
Reply