Failure of implicit real*8
Jerry DeLisle
jvdelisle@frontier.com
Sun Feb 20 02:42:00 GMT 2011
On 02/19/2011 06:13 PM, Michael D. Berger wrote:
> Using:
> gfortran44 -fdefault-real-8
>
> where:
> [~]$ gfortran44 --version
> GNU Fortran (GCC) 4.4.0 20090514 (Red Hat 4.4.0-6)
>
> I have two nearly identical subroutines very similar to:
>
> subroutine orderRows(mx, idxSort, nrows, ncols)
> dimension idxSort(nrows),mx(nrows,ncols),tmp(nrows,ncols)
> ...
>
> where mx is expected to be real, in particular, real*8 because
> of the compile option.
>
> But one of the two interprets mx as an integer, giving
> radically wrong results.
>
> Using, instead:
>
> subroutine orderRows(mx, idxSort, nrows, ncols)
> dimension idxSort(nrows)
> real mx(nrows,ncols),tmp(nrows,ncols)
> ...
>
> produces correct results.
>
> I compiler bug?
>
First, not likely a compiler bug, though one can not tell without seeing more of
the code, perhaps you can send a small working example that shows the problem.
Second, it is ill advised to ever use -fdefault-real-8. Results are not always
predictable. Your code may not be as clean as you think and there could be side
effects. For example if there is a kind explicitly set somewhere. Also, mx
will be implicitly an integer if you do not explicitly define it to be real. So
I think you were lucky that it worked at all before.
Third, if you need to change kind do this:
real(kind=mp) mx(nrows,ncols),tmp(nrows,ncols)
and have mp be a parameter you set in one place ahead of where you use it. This
way you have explicit control over what is happening. I would also recommend to
always use IMPLICIT NONE so you don't have unknowns floating around in your code.
Fourth, consider getting a more recent version of the compiler. 4.5 is out now
and 4.6 is approaching release (maybe a month). There have been lots of bugs
fixed, although 4.4 is OK.
More information about the Fortran
mailing list