Menu

#339 fails to initialize logical variable

None
open
nobody
None
1
2020-02-19
2020-02-19
dan hayes
No

in certain callings of the subroutine det(n,aa,dt) below the determinant was being returned with
the wrong sign because the logical variable fl was not being initialized using an official line fortran standard line

logical*1:: fl=.false.

which should consistently initialize, nor did the just below consistently work either

logical*1 fl /.false./

but instead had to specifically do

fl=.false.

which should not have been necessary
NOTe it committed the error sometimes whether this was in a module and
called or whether the subroutine was in the same program as the
calling routine in main, not included below because it did same
error on various calling routines but not all,
eg if in a file he2.f03 for example used command lines

gfortran -O3 -ffast-math he2.f03
gfortran -g -fbacktrace -fcheck=all -Wall -O3 -ffast-math he2.f03

using either of these command lines got the error sometimes
and NO warnings and NO errors reported from gfortran neither at
compile nor runtime - NO errors reported from gfortran


subroutine det(n,aa,dt)
real8 aa(n,n),dt,rm,tmp(n)
integer m(2)
logical
1:: fl=.false. ! did not work nor did logical1 fl /.false./ work consistently all the time either
! fl=.false. !but had to do this
dt=1
do i=1,n-1
m=maxloc(abs(aa(i:,i:)))
rm=aa(i+m(1)-1,i+m(2)-1)
dt=dt
rm
if(m(1).ne.1)then
fl=.not.fl
tmp(i:)=aa(i,i:)
aa(i,i:)=aa(i+m(1)-1,i:)
aa(i+m(1)-1,i:)=tmp(i:)
endif
if(m(2).ne.1)then
fl=.not.fl
tmp(i:)=aa(i:,i)
aa(i:,i)=aa(i:,i+m(2)-1)
aa(i:,i+m(2)-1)=tmp(i:)
endif

do j=i+1,n
aa(j,i+1:)=aa(j,i+1:)-aa(j,i)aa(i,i+1:)/rm
enddo
enddo!i
dt=dt
aa(n,n)
if(fl)then;dt=-dt;endif
end


reference

COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=c:/tdm-gcc-32/bin/../libexec/gcc/x86_64-w64-mingw32/4.8.2/lto-wrapper.exe
Target: x86_64-w64-mingw32
Configured with: ../gcc-4.8.2-mingw/configure --host=x86_64-w64-mingw32 --build=x86_64-unkno
wn-linux-gnu --target=x86_64-w64-mingw32 --prefix=/home/gfortran/gcc-home/binary/mingw32/nat
ive/x86_64/gcc/4.8.2 --with-sysroot=/home/gfortran/gcc-home/binary/mingw32/cross/x86_64/gcc/
4.8.2 --with-gcc --with-gnu-ld --with-gnu-as --with-gmp=/home/gfortran/gcc-home/binary/mingw
32/native/x86_64/gmp --with-mpfr=/home/gfortran/gcc-home/binary/mingw32/native/x86_64/mpfr -
-with-mpc=/home/gfortran/gcc-home/binary/mingw32/native/x86_64/mpc --with-cloog=/home/gfortr
an/gcc-home/binary/mingw32/native/x86_64/cloog --with-isl=/home/gfortran/gcc-home/binary/min
gw32/native/x86_64/isl --enable-cloog-backend=isl --enable-targets=i686-w64-mingw32,x86_64-w
64-mingw32 --enable-lto --enable-languages=c,c++,fortran --enable-threads=win32 --enable-sta
tic --enable-shared=lto-plugin --enable-plugins --enable-ld=yes --enable-libquadmath --enabl
e-libquadmath-support --enable-libgomp --disable-nls --disable-tls --disable-win32-registry
Thread model: win32
gcc version 4.8.2 (GCC)

Discussion

Anonymous
Anonymous

Add attachments
Cancel