From b.rowlingson at lancaster.ac.uk  Tue Sep 30 13:41:26 2014
From: b.rowlingson at lancaster.ac.uk (Barry Rowlingson)
Date: Tue, 30 Sep 2014 12:41:26 +0100
Subject: [Rd] Intel Fortran compiler returns a -1 TRUE value
Message-ID: <CANVKczM_RkKjX_8U62Zb4BG=afNin3t=bjMb+CJKLEv6O2U-DQ@mail.gmail.com>

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



[Rd] Intel Fortran compiler returns a -1 TRUE value
Barry Rowlingson