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

Catch Fortran run-time errors

bburgerm
Beginner
1,324 Views

Hello,

we use the (very useful) compiler option "-check uninit" to detect uninitialized variables at run-time for third party Fortran subroutines. I have to replace the abort and console message by a more user friendly method:
1) the message should be written to a logfile instead of console (at least the name of the uninitialized variable)
2) the program should continue execution as if "-check uninit" was not specified

In the threadhttp://software.intel.com/en-us/forums/showthread.php?t=52304Jugoslav Dujic suggested to overwrite the functionfor_emit_diagnostic. Infortunately the original post he referenced is no longer available. If I write an own for_emit_diagnostic it is not called/used from the internal functions in the fortran runtime lib.

But a similiar idea worked: I have written an ownfor__rtc_uninit_use to replace the call to the original runtime error handler. Returning from this function continues execution of the Fortran program.

So my questions are:
1) Is the implementation of an own for__rtc_uninit_use currently the only possibility to catch these errors or is there a "more official" way?
2) Currently for__rtc_uninit_use gets a pointer to the variable name as argument - can I rely on this (at least for a specific compiler version) to print out the name of the uninitialized variable?

This was only tested on Linux, but I hope the same works on Windows too.

Regards,
Bernhard.

0 Kudos
4 Replies
Steven_L_Intel1
Employee
1,324 Views
You are relying on an undocumented procedure intended for use by compiler-generated code. You can't really depend on anything here. One problem you could potentially have is if we enhanced the interface in a future compiler version and you recompiled - now the compiler would be assuming the new interface but your routine supports only the old.

Also, I believe that the compiler may believe that the call doesn't return - if you return then you MIGHT execute the wrong code path.
0 Kudos
bburgerm
Beginner
1,324 Views
Thank you for the fast answer. I know that it is not documented and may change in future versions (or even builds) of the compiler, so do you have any other idea how to catch the runtime error (and output)?

I checked the disassembled code and for__rtc_uninit_use can return (if for__issue_diagnostics returns), so I hope the calling code handles this correctly. I thought it must be possible to define an uninitialized variable error to a non-fatal warning.

Tests with complex routines were successfull too. We don't bother the undefined result if uninitialized variables are used, but it is important to keep the program running to save any open data (which does not depend on the called Fortran routine)
0 Kudos
Steven_L_Intel1
Employee
1,324 Views
The output can be redirected by defining the environment variable FOR_DIAGNOSTIC_LOG_FILE. There is no supported mechanism for intercepting the error calls - I have a feature request in on that.
0 Kudos
Steven_L_Intel1
Employee
1,324 Views

In compiler version 14 we added the ESTABLISHQQ routine to let you intercept run-time errors.

0 Kudos
Reply