Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.
29282 Discussions

bug or not in fortran compiler under linux 64 bits ?

Yves_Limoge
Beginner
566 Views

the two forms below don't give the same result :

464 !              do m = 1,3
465 !                if (l2 == d(ntemp,m)) l = m
466 !                exit
467 !              end do


468             if (l2 == d(ntemp,1)) l = 1             
469             if (l2 == d(ntemp,2)) l = 2
470             if (l2 == d(ntemp,3)) l = 3
in the first case I get l = 2 and 3 (correct answer) in the second. (naturly the "!" character is switched as needed !)

What is wrong ? (compiler 2013.3.163)

DAELIII

0 Kudos
3 Replies
mecej4
Honored Contributor III
566 Views

Because of the EXIT statement in the DO loop, the loop is executed only once, with m = 1. If the comparison yields .FALSE., after the loop is exited the variable I will retain whatever value it had before the loop was entered.

Perhaps you mean to write, instead:

[fortran] if (l2 == d(ntemp,m)) then      l = m     exit endif [/fortran]
0 Kudos
jimdempseyatthecove
Honored Contributor III
566 Views

In addition to exit issue previously discussed.

What are the values of l, l2 and d(ntemp,1:3) prior to entering code section given?

As the code is written, it is unknown to the reader as to if any of the if tests result in .true.
IOW l passes through the filter unchanged.

Jim Dempsey

0 Kudos
jimdempseyatthecove
Honored Contributor III
566 Views

>>Indeed the exit has to be included in the if branch

Doing so would not produce equivalent results (e.g. when all three in line if tests result in .true.)

Jim Dempsey

0 Kudos
Reply