From droberts at montana.edu  Sat Oct 25 00:53:39 2008
From: droberts at montana.edu (Dave Roberts)
Date: Fri, 24 Oct 2008 15:53:39 -0700
Subject: [Rd] gfortran optimization problems
Message-ID: <490251F3.6050301@montana.edu>

Colleagues,

I have a routine in package labdsv that calls a FORTRAN subroutine. 
Recently, I was informed that it sometimes gives different results on a 
PC and Mac, and that the PC version is clearly wrong.  I tested it on 
linux (because I don't have a PC), and I get the same (incorrect) 
behavior as the PC.

Simply by inserting debug WRITE statements in the FORTRAN I would get 
different, and correct, results, so I assumed it was an optimization 
error.

So,

1) R CMD SHLIB duleg.f    does not work, and produces bogus code

however,

2) gfortran -c alt_duleg.f
    gcc -O -std=gnu99 -shared -L/usr/local/lib -o alt_duleg.so
         alt_duleg.o -lgfortran -lm -lgcc_s

does work (note the -O low optimization).  Otherwise the gcc command is 
identical to the one produced by R CMD SHLIB.

Has anyone else seen this?  Is there a simple way to have my package 
enforce no optimization so others don't struggle with this?  As far as I 
know the same code worked under g77.

Thanks, Dave Roberts
-- 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
David W. Roberts                                     office 406-994-4548
Professor and Head                                      FAX 406-994-3190
Department of Ecology                         email droberts at montana.edu
Montana State University
Bozeman, MT 59717-3460



[Rd] gfortran optimization problems
Dave Roberts