Red Hat axp-list: Linux on Alpha (1995-2022)
 help / color / mirror / Atom feed
* floating point exceptions: Linux kernel feature or bug?
@ 1998-05-03 15:00 James D. Freels
  1998-05-03 16:44 ` Michal Jaegermann
  0 siblings, 1 reply; 4+ messages in thread
From: James D. Freels @ 1998-05-03 15:00 UTC (permalink / raw)
  To: axp-list, ornl.mail.alpha-osf-managers, comp.os.linux.alpha,
	debian-alpha
  Cc: nina, xgz, Linus.Torvalds, kaszeta

Colleagues:

I have a problem with floating-point error on the DEC-Alpha under
Linux.  I have on a single machine installed on separate disks: (1)
DEC-Unix v4.0b with DEC FORTRAN, (2) Microsoft Windows NT 4, and (3)
Linux 2.0.30 and later kernels (2.0.33, 2.1.9x, etc.).  On the Linux
disk, I have partitioned a RedHat 5.0 and Debian 2.0 (hamm unreleased)
distributions.  All are working correctly except for this
floating-point problem I am about to describe.

On the DEC-Alpha, a FORTRAN (or any other type of compiler) compiled
code that is linked with the -non_shared option will create a
statically linked executable.  This executable can be copied to the
Linux partition (via second machine and reboot since direct
disk-2-disk copies are not possible?) and executed directly.  This
seems to work for me except in the case where a floating overflow or
divide by zero occurs on the Linux operating system.

I need to be able to tolerate such poor coding practices because the
FORTRAN code I use is in a production mode, is very large and
developed over many years by many people, and would take too long and
be too costly to correct.   Hence, I compile the code with DEC-FORTRAN
using the -fpe1 or -fpe2 options which generates an executable that
will allow for divide by zero or floating overflows to occur.
However, when I execute the same code under Linux, I immediately get a
"forrtl: floating exception (75)" error and the code does a core dump
and halts.  For many reasons, I would prefer to perform these
production runs (with very few recompiles) under Linux, but currently
I cannot do this.

I can best illustrate the problem with a very simple test code that is
attached to the end of this mailing.  When compiled and executed with
default swithes on the following machines/compilers, the code execution
continues to a normal completion except under Linux where the code
halts with core dump.  Note that the first entry is under Intel-Linux
using the g77 compiler which gives the desired result.

Machine        OS            compiler        output for divide by zero

Pentium        Linux         g77 (egcs)      infinity

RS/6K          AIX           xlf             infinity

SGI            Irix          f77             infinity

Alpha          DEC-Unix      f77             infinity

Alpha          Linux         g77 (egcs)      core dump and halt

Alpha          Linux         f77 (DEC Unix)  core dump and halt


My questions are: (1) Is there a kernel configuration switch I can set
to allow the Linux kernel to tolerate divide by zero and hence run
correctly? (2) If not, is this therefore a Linux-Alpha kernel bug
(note the Intel g77 compiler allows the divide by zero)? (3) Is there
anything else I can do that will allow a divide by zero (run-time
libraries, etc.)?  (4) Have other people experienced this problem and
found a workaround?

Thanks for any help and feel free to e-mail me directly rather than
via the newsgroups and/or mailing lists.

test.f:
___________________________________________________________
      program test
c
c     program to test g77 on i386 and alpha
c
      x=1.0
      y=0.0
      z=2.0

      a=x/z
      write(*,*)x,z,a

      b=x/y
      write(*,*)x,y,b

      end
____________________________________________________________
-- 
/------------------------------------------------------------------\
|James D. Freels, P.E._i, Ph.D. |Phone:  (423)576-8645 |   | L | A |
|Oak Ridge National Laboratory  |FAX:    (423)574-9172 | H | I | L |
|Research Reactors Division     |work e-m: fea@ornl.gov| F | N | P |
|P. O. Box 2008                 |home e-m: fea@icx.net | I | U | H |
|Oak Ridge, Tennessee 37831-6392|world's best neutrons | R | X | A |
\------------------------------------------------------------------/


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: floating point exceptions: Linux kernel feature or bug?
  1998-05-03 15:00 floating point exceptions: Linux kernel feature or bug? James D. Freels
@ 1998-05-03 16:44 ` Michal Jaegermann
  1998-05-04  2:43   ` Craig Burley
  0 siblings, 1 reply; 4+ messages in thread
From: Michal Jaegermann @ 1998-05-03 16:44 UTC (permalink / raw)
  To: axp-list; +Cc: fea

> 
> Thanks for any help and feel free to e-mail me directly rather than
> via the newsgroups and/or mailing lists.
> 
> test.f:
> ___________________________________________________________
>       program test
> c
> c     program to test g77 on i386 and alpha
> c
>       x=1.0
>       y=0.0
>       z=2.0
> 
>       a=x/z
>       write(*,*)x,z,a
> 
>       b=x/y
>       write(*,*)x,y,b
> 
>       end
> ____________________________________________________________

This program compiled on Alpha with 'g77 -O2 -mieee -o check test.f'
produces the following output:

  1.  2.  0.5
  1.  0.        Inf.

g77 from egcs-1.0.2 release.  Options -mieee, -mieee-with-inexact
and -mieee-conformant are documented in gcc info files so one has
to know, I am afraid, that g77 will accept gcc flags on the top of
its own specific stuff.

BTW - never call your test programs 'test' or you may be for a nasty
surprise. :-)  If you want to know why type, in bash, 'which test'. :-)

 Michal
 


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: floating point exceptions: Linux kernel feature or bug?
  1998-05-03 16:44 ` Michal Jaegermann
@ 1998-05-04  2:43   ` Craig Burley
  0 siblings, 0 replies; 4+ messages in thread
From: Craig Burley @ 1998-05-04  2:43 UTC (permalink / raw)
  To: axp-list

>g77 from egcs-1.0.2 release.  Options -mieee, -mieee-with-inexact
>and -mieee-conformant are documented in gcc info files so one has
>to know, I am afraid, that g77 will accept gcc flags on the top of
>its own specific stuff.

People who read the g77 docs *should* know this, but if there's
any improvements to the docs anyone can suggest, feel free --
the docs themselves describe how to do that.
-- 

"Practice random senselessness and act kind of beautiful."
James Craig Burley, Software Craftsperson    burley@gnu.org


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: floating point exceptions: Linux kernel feature or bug?
       [not found] <199805041645.LAA02957@bifur.math.ukans.edu>
@ 1998-05-04 17:38 ` Wes Bauske
  0 siblings, 0 replies; 4+ messages in thread
From: Wes Bauske @ 1998-05-04 17:38 UTC (permalink / raw)
  To: axp-list@redhat.com

Aaron M. Johnson wrote:

> Hi,
>
>         Your message about the floating point exception sounds related
> to a problem I have.  For me it appears to be an underflow.  Keep me
> posted if you find a solution.
>
> Thank you,
> aaron
>
> I am running Persistance of Vision ray tracer (povray) compiled on
>
> [amj@testnode branch]$ uname -a
> Linux testnode.math.ukans.edu 2.1.96 #2 SMP Thu Apr 16 19:05:54 CDT 1998 alpha unknown
> [amj@testnode branch]$ gcc --version
> 2.7.2.3
>
> This code generates a picture as output using Intel-Linux and IRIX 6.3
>
> [amj@testnode branch]$ gdb ~/bin/povray.debug
> (gdb) run +L/home/amj/thesis/povray3/include +Imov +KFF1 +FP
> Starting program: /home/amj/bin/povray.debug +L/home/amj/thesis/povray3/include +Imov +KFF1 +FP
>
>  <irrelevant povray output deleted>
>
> Parsing...........
>
> Creating bounding slabs.
> Scene contains 1 frame level objects; 0 infinite.
>
>  00:00:00 so far, Rendering frame 1, going to 1.
>
> Rendering...
> Program received signal SIGFPE, Arithmetic exception.
>
> 0x120045dcc in do_specular (Finish=0x120211ce0, Light_Source_Ray=0x11fffec38,
>     REye=0x11ffff5d8, Layer_Normal=0x11ffff6e0, Colour=0x11ffff758,
>     Light_Colour=0x11ffff5f0, Layer_Pigment_Colour=0x11ffff710)
>     at ../lighting.c:1688
> 1688          Intensity = Finish->Specular * pow(Cos_Angle_Of_Incidence, Finish->Roughness);
> (gdb) list 1680
> 1675
> 1676      VHalf(Halfway, REye, Light_Source_Ray->Direction);
> 1677
> 1678      VLength(Halfway_Length, Halfway);
> 1679
> 1680      if (Halfway_Length > 0.0)
> 1681      {
> 1682        VDot(Cos_Angle_Of_Incidence, Halfway, Layer_Normal);
> 1683
> 1684        Cos_Angle_Of_Incidence /= Halfway_Length;
> (gdb)
> 1685
> 1686        if (Cos_Angle_Of_Incidence > 0.0)
> 1687        {
> 1688          Intensity = Finish->Specular * pow(Cos_Angle_Of_Incidence, Finish->Roughness);
> 1689
> 1690          if (Finish->Metallic > 0.0)
> 1691          {
> 1692            /*
> 1693             * Calculate the reflected color by interpolating between
> 1694             * the light source color and the surface color according
> (gdb) p Halfway_Length
> $1 = 0.7136288436493563
> (gdb) p Cos_Angle_Of_Incidence
> $2 = 0.49138409073828376
> (gdb) p Intensity
> $3 = 2.3872427115046736e-314
> (gdb)
>
> Don't know the gdb syntax to print values within structure Finish->

Use "p *structptrname" or just 'p structname".

Be careful about assuming there is no bug in the code. What you show
here is similar to what I found in my own code when I first ported it
to Alpha. It looks like an underflow but the cause could be more than
one thing. For example, somehow pointers get screwed up and you
attempt to use a int when it was supposed to be a float. Course it
could also be a true underflow. Recursive agorithms can easily
underflow. Choices are to build using the ieee flags or figure out
how to silently handle the underflows. A while back, someone
talked about setting FP modes on the Alpha processor. I started
to look at it but found it was easier to debug my code, plus the
code is now correct vs previously using garbage as valid data.


Wes


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~1998-05-04 17:31 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1998-05-03 15:00 floating point exceptions: Linux kernel feature or bug? James D. Freels
1998-05-03 16:44 ` Michal Jaegermann
1998-05-04  2:43   ` Craig Burley
     [not found] <199805041645.LAA02957@bifur.math.ukans.edu>
1998-05-04 17:38 ` Wes Bauske

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox