bug or not in fortran compiler under linux 64 bits ?

bug or not in fortran compiler under linux 64 bits ?

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

publicaciones de 5 / 0 nuevos
Último envío
Para obtener más información sobre las optimizaciones del compilador, consulte el aviso sobre la optimización.
Imagen de mecej4

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:


if (l2 == d(ntemp,m)) then

        l = m

       exit

   endif

Imagen de jimdempseyatthecove

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

www.quickthreadprogramming.com

Indeed the exit has to be included in the if branch ! Probably the result of a too tiring day !

In any case many thanks to the comments, and apologies for the time wasted.

DAELIII

Imagen de jimdempseyatthecove

>>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

www.quickthreadprogramming.com

Inicie sesión para dejar un comentario.