Barry Rowlingson
2014-Sep-30 11:41 UTC
[Rd] Intel Fortran compiler returns a -1 TRUE value
I have access to a cluster on which I have been supplied with R 3.1.0 which appears to have been built using the intel compiler tools. The following minimal Fortran file: subroutine truth(lind) logical lind lind = .TRUE. end Compiles thusly: arcadia> R CMD SHLIB truth.f ifort -fpic -O3 -xHOST -axCORE-AVX-I -fp-model precise -c truth.f -o truth.o ifort: command line warning #10212: -fp-model precise evaluates in source precision with Fortran. icc -std=gnu99 -shared -L/usr/local/lib64 -o truth.so truth.o -lifport -lifcore -limf -lsvml -lm -lipgo -lirc -lpthread -lirc_s -ldl And runs so: > dyn.load("truth.so") > z = .Fortran("truth",as.logical(TRUE)) > z[[1]] [1] TRUE > as.numeric(z[[1]]) [1] -1 > z[[1]] == TRUE [1] FALSE > all(z[[1]]) [1] TRUE > identical(z[[1]],TRUE) [1] FALSE The value generated by Fortran's .TRUE. evaluates as "truthy" -- as in all(z[[1]]) -- but is neither equal to nor identical to TRUE. Its numeric conversion to -1 is most unusual, every other system I've tried converts to +1. So.... wrong compiler flag on build? User error - never try comparing truthy values, as with the various flavours of NA? Or something else? If its a compiler/config problem I'll pass it on to the cluster admin - I've had a good look for stuff on building R on Intel compilers, nothing stood out. I might try building R myself this afternoon but as I implied I don't have admin on this cluster so I might have to track down a bunch of library sources to build R from source. If its a user error then I'll track down every instance of "if(foo==TRUE)" and shoot it, and it would be nice to have a note in ?TRUE Some useful info:> sessionInfo()R version 3.1.0 (2014-04-10) Platform: x86_64-unknown-linux-gnu (64-bit) arcadia> ifort -v ifort version 13.0.0 Thanks Barry [[alternative HTML version deleted]]
On 30/09/2014, 7:41 AM, Barry Rowlingson wrote:> I have access to a cluster on which I have been supplied with R 3.1.0 which > appears to have been built using the intel compiler tools. > > The following minimal Fortran file: > > subroutine truth(lind) > logical lind > lind = .TRUE. > end > > Compiles thusly: > > arcadia> R CMD SHLIB truth.f > ifort -fpic -O3 -xHOST -axCORE-AVX-I -fp-model precise -c truth.f -o > truth.o > ifort: command line warning #10212: -fp-model precise evaluates in source > precision with Fortran. > icc -std=gnu99 -shared -L/usr/local/lib64 -o truth.so truth.o -lifport > -lifcore -limf -lsvml -lm -lipgo -lirc -lpthread -lirc_s -ldl > > > And runs so: > > > dyn.load("truth.so") > > z = .Fortran("truth",as.logical(TRUE)) > > z[[1]] > [1] TRUE > > as.numeric(z[[1]]) > [1] -1 > > z[[1]] == TRUE > [1] FALSE > > all(z[[1]]) > [1] TRUE > > identical(z[[1]],TRUE) > [1] FALSE > > The value generated by Fortran's .TRUE. evaluates as "truthy" -- as in > all(z[[1]]) -- but is neither equal to nor identical to TRUE. Its numeric > conversion to -1 is most unusual, every other system I've tried converts to > +1. > > So.... wrong compiler flag on build? User error - never try comparing > truthy values, as with the various flavours of NA? Or something else? > > If its a compiler/config problem I'll pass it on to the cluster admin - > I've had a good look for stuff on building R on Intel compilers, nothing > stood out. I might try building R myself this afternoon but as I implied I > don't have admin on this cluster so I might have to track down a bunch of > library sources to build R from source. > > If its a user error then I'll track down every instance of "if(foo==TRUE)" > and shoot it, and it would be nice to have a note in ?TRUE > > Some useful info: > >> sessionInfo() > R version 3.1.0 (2014-04-10) > Platform: x86_64-unknown-linux-gnu (64-bit) > > arcadia> ifort -v > ifort version 13.0.0This appears to be user error. According to Writing R Extensions, the Fortran type corresponding to R logical is INTEGER, not LOGICAL. Duncan Murdoch
Hello> The value generated by Fortran's .TRUE. evaluates as "truthy" -- as in > all(z[[1]]) -- but is neither equal to nor identical to TRUE. Its numeric > conversion to -1 is most unusual, every other system I've tried converts to > +1.Please read the -fpscomp logicals option of ifort. -- "\u4e2d\u9593\u6804\u6cbb" <nakama (a) ki.rim.or.jp>