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

How to force lazy evaluation in IF statements

judios
Beginner
1,493 Views
I am trying to compile old source code withIVF.The oldsourcewas written taking advantage of lazy evaluation.

for example inthe following code:


IVAL = 0
IF ( IVAL .GT. 0 .AND. IFUNCTION(ARGS) .GT. 0)THEN
.
.
.
ENDIF


the IFUNCTION was never evaluated since IVAL is not greater than 0. Therefore, there was not need to continue evaluation after the .AND.

Using IVF, the IFUNCTION is allways evaluated, even when IVAL is greater than zero. How can I force IVF to use lazy evaluation, to avoid the evaluation of IFUNCTION when IVAL is not greater than zero?

Thanks for your help!
0 Kudos
3 Replies
ZlamalJakub
New Contributor III
1,493 Views
You should use
IF ( IVAL .GT. 0) then
if (IFUNCTION(ARGS) .GT. 0)THEN


because IVF allways evaluate whole logical expression.

Jakub
0 Kudos
John4
Valued Contributor I
1,493 Views

You shouldn't expect short-circuit evaluation in a Fortran IF statement. If it worked with other compilers, then it was a feature (or a bug?) in those compilers.

In general, keep in mind that the compiler is free to optimize the code you provide in whatever way it likes ---and that includes removing statements, optimizing variables away, changing the order of evaluation, etc.

See this old thread for a much better explanation.

0 Kudos
judios
Beginner
1,493 Views
:( it seems that I am going to have to spend several days looking for those IF statements.

Thanks for your help!!!
0 Kudos
Reply