From saikat at stat.wisc.edu  Fri Sep 26 10:46:15 2003
From: saikat at stat.wisc.edu (Saikat DebRoy)
Date: Fri Sep 26 15:44:44 2003
Subject: [Rd] Bugs compiling R-1.7.1 with Intel compilers icc and ifc
	(PR#4295)
In-Reply-To: <200309250926.h8P9QG0P023078@pubhealth.ku.dk>
Message-ID: <CC5C1771-F027-11D7-8345-0003931A3C9E@stat.wisc.edu>

On Thursday, Sep 25, 2003, at 05:26 US/Eastern, CanisMaior@web.de wrote:

> Bugs compiling R-1.7.1 with Intel compilers icc and ifc,
> on x86-computer (Pentium IV) and linux operating system
>

Many of those bugs can be fixed by using appropriate configure options. 
Some of the warnings are serious, but they quite a few of them or fixed 
yesterday.

> Hello,
> as there aren't many reports about that issue, I'll give a little
> report here. (Hope I don't bother anyone)
>
> The best thing about using icc and ifc are the warnings, because
> it is said that the Intel compilers are stricter and give more
> precise warnings than gcc.
> Warnings are good for making better code.

> used software :
> * Intel c/c++ Compiler for 32-bit applications, Version 7.1 Build 
> 20030307Z
> * Intel Fortran Compiler for 32-bit applications, Version 7.1 Build 
> 20030307Z
>   (both with licence FOR NON-COMMERCIAL USE ONLY)
> * autoconf (GNU Autoconf) 2.57

I used all of the above on an Intel Pentium IV running Debian Linux 
testing distribution. In addition I had GNU make version 3.80

> * GNU Make version 3.79.1
>
> First:
> It is possible to compile R-1.7.1 with intel compilers ;-)
>
> But:
> There are several bugs. As the Intel compilers are quite reliable,
> the bugs may be in the R-code :-(
>
> *) some commands crashes R, see later.

This can be fixed with appropriate options to the compiler. See below.

> *) the configure script seems to have a bug, even if you make your own
>    configure script with autoconf.
>    Perhaps it's only a typo, perhaps it's an error of autoconf.
>    So you have to do some things manually:
>

This indeed is a bug in the configure script. I have a fix that works 
for the intel and the GNU compilers. I have no idea if it breaks 
anything for other compilers or platforms.

> 1)
> run configure : (you have to adjust the paths)
> env CPICFLAGS=-shared CXXPICFLAGS=-shared FPICFLAGS=-shared
> SHLIB_LDFLAGS=-shared ./configure CC=icc CFLAGS=-O2
> CPPFLAGS=-I/opt/intel/compiler70/ia32/include F77=ifc CXX=icc
> CXXFLAGS=O2 FFLAGS=-C90
>

A better set of configure options is

./configure CC=icc CFLAGS='-O2 -mp'
CPPFLAGS=-I/opt/intel/compiler70/ia32/include F77=ifc CXX=icc
CXXFLAGS='-O2 -mp' FFLAGS='-C90 -w90 -w95 -mp'
CPICFLAGS=-shared CXXPICFLAGS=-shared FPICFLAGS=-shared 
SHLIB_LDFLAGS=-shared SHLIB_CXXLDFLAGS=-shared

The -mp option forces stricter IEEE-754 floating point arithmetic 
conformance.
Any operation involving an NA or NaN crashes R without this option.
The icc and ifc also have a less strict -mp1 option which does not work 
for R.
The -w90 and -w95 suppresses warnings about Fortran syntax made 
obsolete by Fortran 90 or 95.

> 2) delete a wrong path in some Makefiles:
> -L/usr/local/lib"
> The quotation mark is the wrong thing. Delete it!
>

The problem is in the AC_F77_LIBRARY_LDFLAGS macro. It guesses the 
linker flags by passing a verbose option (-v for ifc) to the compiler. 
For ifc this produces a multiline output, one line continued to the 
next by a \ character. It also contains some " characters. These 
together produces the wrong results. We can fix this by removing all \ 
and " from the variable ac_f77_v_output in that macro. I am not sure if 
this breaks anything in other compilers.

> make
> or better: Do a
>
> make  &>  this_is_a_logfile.log &
>
> which writes the compiler warnings to a file.
> Now it should succeed.
>

After you do everything I described, the make should succeed. It will 
still show some warnings. I think most of the warnings for R itself is 
harmless.

> Note:
> make check
> fails. That's a first hint that there are some problems.

Now make check should work.

> Don't install that R!

I would still be cautious about installing an R compiled with icc/ifc 
as your default but I think it is useful for the warnings it produces.

Thanks,
Saikat


[Rd] Bugs compiling R-1.7.1 with Intel compilers icc and ifc (PR#4295)
Saikat DebRoy