From andy_liaw at merck.com  Wed May 27 14:58:42 2009
From: andy_liaw at merck.com (Liaw, Andy)
Date: Wed, 27 May 2009 08:58:42 -0400
Subject: [Rd] using a "third party" DLL in my package
In-Reply-To: <alpine.LFD.2.00.0905240727150.32603@gannet.stats.ox.ac.uk>
References: <4A0C079F.7080101@metla.fi><alpine.LFD.2.00.0905150905560.4378@gannet.stats.ox.ac.uk><4A13EA32.5010309@metla.fi><0A2C49D8-9EDA-432B-B3CD-04A395EBBAC4@stat.berkeley.edu>
	<alpine.LFD.2.00.0905240727150.32603@gannet.stats.ox.ac.uk>
Message-ID: <39B6DDB9048D0F4DAD42CB26AAFF0AFA074CEF36@usctmx1106.merck.com>

I don't know if this applies to Seija's case, but one instance that I've ran into when problem arose only with -O3 is uninitialized variables/arrays.  Adding the initialization fixed the problem.  Just one thing to check, I guess.

Best,
Andy

From: Prof Brian Ripley
> 
> It is likely that this is related to using higher-precision FPU 
> registers, in which case there is a portable solution: look up 
> SAFE_FFLAGS in 'Writing R Extensions'.
> 
> But if that is the cause, the real solution is to write the 
> code using 
> proper convergence tests.
> 
> On Sat, 23 May 2009, Kasper Daniel Hansen wrote:
> 
> >
> > On May 20, 2009, at 4:32 , Seija Sirki? wrote:
> >
> >> Hello again,
> >> 
> >> thank you for the comments, especially this one:
> >> 
> >> Prof Brian Ripley wrote:
> >> 
> >>> My concern would be that there are different cases that fail under
> >>> Fortran compiler X and you are just sweeping the problem under the
> >>> carpet.
> >> 
> >> It inspired us to go back to search the cause, and we've made some 
> >> progress: it's not the compiler, it's the compiler 
> options. Simple, but it 
> >> took a while to figure that out since my experience in 
> these things is 
> >> limited. When I build the package with default options 
> using INSTALL 
> >> --build the dll is built with option -O3 as per R's 
> Makeconfig file. If I 
> >> build the dll by hand, using gfortran with no additional 
> options and 
> >> dyn.load it, everything works, and also with -O and -Os. 
> (No, I don't fully 
> >> understand what the differences between all these are, but 
> that's another 
> >> question).
> >> 
> >> I'm looking at chapter 5.5 in Writing R Extensions and 
> also 6.3.3 in R 
> >> Installation and Administration but I can't figure out how 
> to tell "inside" 
> >> my package that it is not to be built -O3 but with, say, 
> -O. I can see how 
> >> to add flags in the package (and as far as I can tell, if 
> there are several 
> >> optimization level flags the last in line is used and 
> that's the wrong one 
> >> from my point of view), and also how to override flags but 
> only on my 
> >> computer. Am I blind or am I again attempting something I 
> shouldn't?
> >
> >
> > This is not trivial, and how you do it is compiler 
> dependent. A quick fix was 
> > provided by Simon Urbanek a while back and it is _not_ 
> portable, it assumes 
> > you are using GCC. It would be nice to have a configure 
> file that detects the 
> > compiler and optimization setting and then re-sets the 
> optimization level. I 
> > have thought about writing one, but have never got around to do it.
> >
> > Anyway, the fix is in the Makevars file from affxparser 
> from Bioconductor. 
> > Essentially, you use a Makevars file placed in the src 
> directory, containing
> >
> > MYCXXFLAGS=-O0 -Wall
> >
> > %.o: %.cpp
> >       $(CXX) $(ALL_CPPFLAGS) $(ALL_CXXFLAGS) $(MYCXXFLAGS) 
> -c $< -o $@
> >
> > Essentially this makes sure that -O0 (indicating no 
> optimization) is placed 
> > at the _end_ of the call to the compiler (this is for C++ 
> files btw), using 
> > the fact that if you have two -O* settings, the last one 
> overrides the first.
> >
> > This ought to be easily adaptable to FORTRAN.
> >
> > Kasper
> >
> > ______________________________________________
> > R-devel at r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-devel
> 
> -- 
> Brian D. Ripley,                  ripley at stats.ox.ac.uk
> Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
> University of Oxford,             Tel:  +44 1865 272861 (self)
> 1 South Parks Road,                     +44 1865 272866 (PA)
> Oxford OX1 3TG, UK                Fax:  +44 1865 272595
> 
Notice:  This e-mail message, together with any attachme...{{dropped:12}}



[Rd] using a "third party" DLL in my package
Liaw, Andy