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

Capturing exceptions

Reinaldo_Garcia
Beginner
1,282 Views
How can I capture runtime exceptions such as overflows, etc.? I am presently using "Produce Nan, signed infinities, and denormal results" (/fpe:3) and when an exception occurs the program just hangs. I would like it to generate an error message.
I have tried /fpe:0 and 1 but the program results are incorrect and different from the ones with /fpe:3.
Any suggestions?
R
0 Kudos
16 Replies
Steven_L_Intel1
Employee
1,282 Views
The program "hanging" is not normal for an arithmetic exception. Note that the default is to allow underflows to produce denormals and your program might be trying to "converge" and not doing so. If /fpe:0 gives you different results, then you are very likely doing computations with denormalized values and this loses precision. Since you don't get exceptions, you're not seeing overflows so there's nothing to capture.

The standard way to do what you want is through the IEEE_EXCEPTIONS and IEEE_ARITHMETIC intrinsic modules. You can set the behavior to give an error on an underflow.
0 Kudos
Reinaldo_Garcia
Beginner
1,282 Views
Thanks Steve.
When I said that the program was "hanging", I wanted to say that the program reported NaNs and became exceedingly slow. I just want it to bang and stop when an overflow occurs. Beside the IEEE modules, is there n equivalent option to /fpe:0 that would abort the program without reducing underflows to 0.0?
Cheers,
R//G
0 Kudos
TimP
Honored Contributor III
1,282 Views
You could simply test a strategic value (outside any performance-critical loop) by ieee_isnan() so as to take a kill action.
0 Kudos
Steven_L_Intel1
Employee
1,282 Views
USE, INTRINSIC :: IEEE_EXCEPTIONS
...
CALL IEEE_SET_HALTING_MODE(IEEE_OVERFLOW,.TRUE.)

I will comment, though, that if you're getting NaNs, you aren't seeing overflows.
0 Kudos
Reinaldo_Garcia
Beginner
1,282 Views
If I understand well, you are indicating that if my program was generating overflows, it would halt even when using /fpe:3?

Are NaNs generated by Division by 0?
0 Kudos
Steven_L_Intel1
Employee
1,282 Views
Yes, that's what should happen.

That's one way to generate NaNs, but not the only way.
0 Kudos
Reinaldo_Garcia
Beginner
1,282 Views
Thanks Steve.

Is there a compiler option that would forcethe program halt when a NaN occurs in the same way of the Overflows and withouth assinging 0. to the underflows?

R//G
0 Kudos
Steven_L_Intel1
Employee
1,282 Views
No, but you can call IEEE_SET_HALTING_MODE(IEEE_INVALID,.TRUE.) in the main program to do that.
0 Kudos
Reinaldo_Garcia
Beginner
1,282 Views
Excellent. I will try that.

Thanks again.

0 Kudos
strohhaecker
Beginner
1,282 Views
> Are NaNs generated by Division by 0?
0 Kudos
Steven_L_Intel1
Employee
1,282 Views
Yes, division by zero is one way to generate a NaN.
0 Kudos
TimP
Honored Contributor III
1,282 Views
Only for the case 0./0,, or possibly cases involving subnormal, as well as (x/0.)*0.
0 Kudos
Reinaldo_Garcia
Beginner
1,282 Views
I am not sure. I created the following code:

call ieee_get_flag (ieee_usual, flag_values)

if (any(flag_values)) then

write(*,*) ' Error code: ', flag_values

stop

endif

That outputs: T F T when it captures an error.

I guess that reflects an ieee_invalid, but I am not sure.

R//G


0 Kudos
strohhaecker
Beginner
1,282 Views

For whatever weird way posting on this forum is broken with IE9.

Anyways TimP posted the same (division by zero generates +-infinity, not NaN).

0 Kudos
netphilou31
New Contributor III
1,282 Views
Quoting strohhaecker

For whatever weird way posting on this forum is broken with IE9.

Anyways TimP posted the same (division by zero generates +-infinity, not NaN).


If you want to post to this forum with IE9 you need toswitch on the browsercompatibility mode (the iconshowing abrokenpage at the end of the address bar).

Best regards

0 Kudos
Steven_L_Intel1
Employee
1,282 Views
I'm not seeing any problems posting with IE9 (using it to post this) and there is no compatibility mode icon in my browser bar.
0 Kudos
Reply