Topic: Someone pls explain Fortran optimising

I have completed a major project.  During debugging, I had set optimising to none.  On completion, everything worked.

I then tried various optimising levels, and all of them caused malfunctions.  Specifically, I found some dynamic arrays were empty.

Can anyone help me understand this, please?
----
John

Re: Someone pls explain Fortran optimising

John,

When you say "dynamic arrays were empty," what exactly are you referring to?   And are you saying they were empty when printed out or when you attempted to access them via the debugger?  I just want to understand the issue more fully.

One thing you can try is enabling common optimizations and debugging, then executing your code via the debugger.  There's a chance it will fail under this condition too, and you'll be able to see at least some information as to what went wrong.  Also, you can enable "Runtime Diagnostics" with optimization; the two aren't mutually exclusive.  That might catch any array indexing issues at runtime.

I find that once optimizations are enabled in any significant manner, the compiled code loses some of "slop" that allows it to run even when there are big buffer overruns.  This finding is of course anecdotal and may be highly flawed.   It is frustrating to debug these issues.

Jeff Armstrong
Approximatrix, LLC

Re: Someone pls explain Fortran optimising

I didn't get far in my investigation of the problem.

As long as I compile without selecting any optimisation, the executable runs fine.
It runs correctly, all functionality works, and the analysis results are correct when checked against commercial software.
When I use optimisation, the program fails, giving me an error when solving equations with large dynamic arrays.

Using the debugger to investigate the above, I have established that at least one of my dynamic arrays, which should contain equation coefficients, contains no data.  I don't know why.

When I re-compile without optimisation, all good again.
I was just wondering if anyone had any ideas about why this might happen.
---
John

Re: Someone pls explain Fortran optimising

John,

What do you mean when you say:

at least one of my dynamic arrays...contains no data

I'm not sure I understand your terminology.  Do you mean the array was not ALLOCATEd at all?  Do you mean it is full of zeros? 

What happens if you were to display the contents of the array (or just a few elements of it) while your program is running?  I'm just wondering if optimization has somehow made the arrays "appear" empty to the debugger.

Jeff Armstrong
Approximatrix, LLC

Re: Someone pls explain Fortran optimising

I think this is most likely to be a bug in your code, rather than problem with the optimizer. Can you check if the code works with the following options. You should be able to run this in the debugger and see what your problem is.

compile:

-g -finit-real=snan -fcheck=all -ffpe-trap=zero,overflow,underflow -fbacktrace

link:

-g

--
David

Re: Someone pls explain Fortran optimising

My code is indeed still quite unstable. 
I'm just happy that I've finally managed to build a version that does at last both work and does correct answers.

I'm grateful for your recommended compilation options, David, and I will try them.
---
John