2

I'm a bit confused regarding the usage of ieee modules in gfortran. I know gfortran 5.x support ieee modules. I have a code (with *.f90 extension plus one .f03 file for declaring wrapper data types to interface with an external library written in C++. The .f03 file is used in a .f90 module via include command) that was written in days of gfortran 4.x, as such no explicit way of exception handling was used. But now, it seems to me that 5.x tries to signal exceptions whenever they occur. This is known to me because output text from my code includes this signal message even when I don't trap them.

Does that mean floating point rounding,adding,division,multiplication and square roots, now conform to ieee standards implicitly?In other words, wherever I've set precision using selected_real_kind, I can use ieee_selected_real_kind and then all arithmetic conforms to ieee standards i.e. for example, the operators +, -, /, *, etc. conform to ieee standards.

Moreover, GCC documentation says that the standard is for Fortran 2003 and later. Does it mean that for all *.f90 files have to renamed as *.f03 for the standard to take effect? If that's so I think the exception signalling I'm getting is generated by .f03 file only.

I also want to know that if I trap the error with compiler options, can I know which floating point operation in the code which caused it in the first place?

Ricky
  • 121
  • 2
  • 2
    The file name extension is not used in determining the standard used to interpret the file. – francescalus Aug 16 '17 at 15:40
  • 1
    You can see [this question](https://stackoverflow.com/q/39350816/3157076) for some aspects. – francescalus Aug 16 '17 at 15:55
  • If you have a STOP just before the END, just delete it. It is useless or even harmful. – Vladimir F Героям слава Aug 16 '17 at 16:19
  • Full implementation of ieee_arithmetic requires avoidance of -ffast-math optimizations. – tim18 Aug 17 '17 at 01:21
  • There is no explicit line in the code i.e. `use, intrinsic::ieee_arithmetic` or other scoping of ieee modules, yet SIGFPE is generated. I'm confused then whether it is superfluous to declare precision as ieee_selected_real_kind. – Ricky Aug 17 '17 at 05:06
  • @Ricky - confirmed your observations. In this question https://stackoverflow.com/questions/45693403/adapting-an-existing-underflow-so-answer-for-my-underflow-error I do not have any use,intrinsic::ieee_arithmetic and have .f90 file but I am still getting a IEEE_UNDERFLOW error. – gansub Aug 17 '17 at 07:36
  • Having the modules/entities accessible in a scoping unit places a burden on a processor. However, not having them accessible doesn't mean the processor mustn't behave in a similar way. That is, the compiler can do exactly the same in both settings if it so chooses. – francescalus Aug 17 '17 at 10:06
  • @francescalus With respect to gfort, whether ieee_selected_real_kind is superfluous syntax or not? What are ieee modules then for? What is the use of this command `use, intrinsic::ieee_` then? – Ricky Aug 17 '17 at 10:48
  • Ricky, your problems has probably **nothing** to do with the IEEE modules. Please respond: Do you end your program by calling `STOP`? Have you read the link https://stackoverflow.com/q/39350816/3157076 ? If you have a `STOP` before `END PROGRAM`, just delete the `STOP`. It is useless. – Vladimir F Героям слава Aug 17 '17 at 10:49
  • I don't know whether this is detracting from your underlying problem, but you'll probably see that the kind values returned by `ieee_selected_real_kind` and `selected_real_kind` are the same. The IEEE modules require certain standardized behaviour - it's possible for a compiler vendor to make those choices even when not required. – francescalus Aug 17 '17 at 10:56
  • Yes and No. My code has 'STOP' statements but they are executed only under conditional statements i.e for example, if a computed parameter happens to exceed a threshold. – Ricky Aug 17 '17 at 10:58
  • I wanted to keep the code aligned with ieee standards. Since I cannot fully use some of the libraries like LAPACK because of precision related problems. In those cases I used custom code from Numerical Recipes. But still many a times denormal numbers etc. occur. For such cases I want to know how best to utilise iee standards – Ricky Aug 17 '17 at 11:01
  • @francescalus Sadly, I (can only) use gfortran. Other compiler vendors I really don't care about. So my answer is specifically related to gfort as the question says – Ricky Aug 17 '17 at 11:04
  • @Ricky - have you looked at this solution - https://stackoverflow.com/questions/32851780/flush-to-zero-in-gfortran ? – gansub Aug 17 '17 at 13:11
  • @gansub I had seen that before posting the question – Ricky Aug 17 '17 at 13:18
  • @Ricky - can you please make a toy example of what you have tried and share it ? – gansub Aug 17 '17 at 13:20
  • @gansub Infact this post with its compiler options & implicit signalling of gfortran 5.x was what confused me. – Ricky Aug 17 '17 at 13:21
  • @Ricky - in the question that I posed couple of days back I also tried this solution and could not eliminate the IEEE_UNDERFLOW.Though it maybe I did it the incorrect way. – gansub Aug 17 '17 at 13:22

0 Answers0