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

Continue from Divide by 0

jimdempseyatthecove
Honored Contributor III
1,095 Views

I am using IVF 10.1.014 on Windows with VS 2005.

Due to programming errors on my part I occasionaly get a Divied by 0 error. I would like to reset the values of the variables (this I can do), reset the next statement (this I can do), and then continue execution. Upon doing this Div by 0 event is still active and I cannot seam to clear this such that I can continue. What are the settings in both VS events and in IVF an/or proceedure I can follow to clear a floating point error. BTW this error is with FP87 as the source file is compiled with optimizations off.

Yes, I should know this by now... :~S

Jim Dempsey

0 Kudos
10 Replies
g_f_thomas
Beginner
1,095 Views

It has just slipped your mind Jim, its probably SETCONTROLFPQQ. You can't trap it though unless you resort to C/C++ SEH, although that functionally inIVF seems to come and go with every release. If the f2003 IEEE stuff were available then you'd have no problem. However, if the div by zero is due to integer divide then you're back to C/C++.

Gerry

0 Kudos
jimdempseyatthecove
Honored Contributor III
1,095 Views

Gerry,

Thanks for your reply. However, I think I was not clear in my inquiry.

I do not wish for my application to handle Divide by 0 as a well written application should not experience this.

While the application is in development, errors may be in the code that result in a code section producing a Divide by 0. And this will necessitate inserting some defensive code into the application to correct for this (take corrective action).

However, what I want to do is enter the correction notes into a ToDo.txt file, and if possible, correct or bypass the offending statement, and continue debugging the application (with defective code still in place). The reason for this is to get to the point where the deffective code is (rarely) executed may take 10 hours of compute time. I would like to find more than one bug, if possible, during lengthy run times like this.

To rephrase my requiest:

From VS 2005 and IVF,how does the programmer clear the FP87 error events using the debugger? And while we are at it, how to clear the MMX/SSE error events. Such that in both cases I can take evasive action using the debugger and then continue with the test run. As it stands now, I cannot relieve the error condition to permit a continue.

Jim Dempsey

0 Kudos
g_f_thomas
Beginner
1,095 Views

Jim,

Sorry, I've never done that. If I had to I'd contact John Robbin's at Wintelectuals (something like that) who wrote Debugging Microsoft .NET 2.0 Applications. He's was very helpful to me in the past when I asked him to clarify more difficulty with the debugger on which he's a master. If you manage to solve the problem please post the solution here, it sound very interesting. Good luck.

Gerry

0 Kudos
Jugoslav_Dujic
Valued Contributor II
1,095 Views
Will SIGNALQQ / GETEXCEPTIONPTRSQQ / CLEARSTATUSFPQQ / TRACEBACKQQ do the job? Of course, you have to call them from the code, but you might be able to register the basic FPE errors. I haven't used any of those myself, but by a superficial redading of the documentation, they look promising.
0 Kudos
Steve_Nuchia
New Contributor I
1,095 Views

Jim,

I wrote the exception mechanism test suite for the K7 at AMD; if you are having trouble with the logic for handling these exceptions I can probably refresh my memory pretty quickly and help you. I've held off saying anything though because I know nothing about the FORTRAN interace to those mechanisms.

Keep in mind that the x87 was originally a coprocessor; its exception model is bizarre because of that history. You probably need to clear the status register before resetting the control register and do both of those before executing any FP arithmetic.

-swn

0 Kudos
Steve_Nuchia
New Contributor I
1,095 Views
Another point: it has been my experience that the visual studio debugger does not display the FP status and control register contents in a way that is completely clear and/or correct. I recommend adding some code to copy those values into local variables so you can double-check them in the debugger.
0 Kudos
jimdempseyatthecove
Honored Contributor III
1,095 Views

That is the problem (FP status register not available for clearing)

The dialog that pops-up is confusing because it implies you can Ignore the error (Ignore button) but the Div by 0 error flag is not cleared and I cannot continue (Ignore). Even moving the Next Location doesn't effect the state of the error condition.

Inserting FP exception routine, which basically is going to tell me where I diedwon't get me where I want to be.

This is an MS VS issue, but I was hoping someone had some advice on this.

Jim

0 Kudos
Steve_Nuchia
New Contributor I
1,095 Views

Ignoring the FP exception in the default popupis going to retry the instruction without changing anything, so that's not going to help.

Three ways to proceed beyond the exception:

1) Handle the exception and either 1a) modify the data or 1b) leave the exception masked off before repeating the instruction. For 1b, harvest the fault state to a log and unmask it, if desired, at the end of each iteration. You'll also have to cope with the infinite result when the output is re-consumed.

2) Using the debugger, as you are doing now, but insert some service functions you can call in the immediate window to access the FP registers as part of the restart sequence. Alt: find someone who knows the recipe for working with the FP registers directly through the VS debugger.

3) run with divide-by-zero exceptions masked off and add code (debug only?) at the desired granularity to check-and-clear the status flag so you know which iterations suffered faults.

-swn

0 Kudos
jimdempseyatthecove
Honored Contributor III
1,095 Views

Swn,

Thanks for your suggestions.

3) is out because I want Div by 0 to trap as I want to find the unprotected code sequences.

I haven't tried 2) so I do not know if the service function can be called with an FP error pending (without itself generating an exeption), and return from the service functionwithout having the FP error state restored. I will have to try this. Although I think this should be feature implemented in the IVF exception/abort handler whereby you can elect to continue through the divide by 0. i.e. Step out of IVF exception handler to the position immediately following the offending instruction (with FP exception reset).

Jim

0 Kudos
g_f_thomas
Beginner
1,095 Views

What is this

'IVF exception/abort handler '

that you're referring to? There is no such topic in the VS-integrated Intel help.

Gerry

0 Kudos
Reply