Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Returning zero on Divide By Zero

baroq
Beginner
972 Views
Hello,
is it possible with Intel Fortran for Linux (or Windows) to implement an exception handler which will trap a Divide By Zero,return a zero instead of a NaN and clear the exception? - thus allowing processing to continue.
We have this functionality on HP-UX, but are interested inporting the (legacy) applicationwhich relies on this feature to our Intel platform (IBM xSeries 250: dual processor Pentium Pro, Red Hat Linux 7.2.)
Answers/helpgratefully accepted,
Douglas
0 Kudos
4 Replies
glockner
Beginner
971 Views
Hi,
I usually add a constant (1.D-20 for instance) to the denomitor when it may be equal to zero. It does not produce zero as you require of course but allow the program to continue.
But, it seems that Intel compiler has problem with this kind of operation (see my following post)
S. Glockner
0 Kudos
baroq
Beginner
971 Views
Thanks for the suggestion. Unfortunately, this is a little difficult to implement. The application in question is a very large macroeconomic model, and there are many equations. The Divide By Zero (and Overflow) "problems" arise when there is missing data - which occurs quite often. The trap we have instituted under HP-UX which basically zeroes the results is a neat way of being able to avoid a lot of potentially messy (and time consuming) testing.
We have looked at a number of compilers in the past on Intel platforms, and have not found one which enables thebehaviourwe have on HP-UX, running on a PA-RISC processor. Could it be something to do with the floating point architecture generally on Intel??
Cheers,
Doug
0 Kudos
Steven_L_Intel1
Employee
971 Views
What you are looking for is what the DEC VAX architecture called "floating point faults". This allowed an exception handler to "complete" the instruction without later instructions interfering. VAX had an architected mechanism for writing such handlers, even in Fortran (!), and I wrote several of them myself, once upon a time. I would guess that PA-RISC has something similar.

Later architectures made it harder to do this, as the ability of the processor to interrupt the instruction stream without side-effects hindered performance. The DEC Alpha had something called "trap shadows" which, with compiler support, allowed you to "back up" in the instruction stream enough to restart execution, but the code needed to implement this was much more complicated.

I don't pretend to understand the IA-32 architecture to that level of detail, but I haven't seen that IA-32 has a similar mechanism. that can be applied on a whole program or even routine basis. The lack of a unified and cross-language exception handling mechanism is definitely a hindrance. If you were able to do this, you would almost certainly have to write (at least some of) the exception handler in assembler.
0 Kudos
baroq
Beginner
971 Views
Steve, thanks for your informative reply - this is exactly the functionality we are looking for. It would be great to havea "definitive" response fromIntel on whether this is in fact do-able given their architecture.Any ideas on who we might address the question to?
Cheers, Doug
0 Kudos
Reply