Incorrect result with Intel Fortran Compiler on Mac, but fine on Linux
I have been working with a fast multipole code in Fortran. It is a black box to me,开发者_Go百科 and I have been having some strangeness when compiling it on my mac.
I am using version 11.1 of the compiler, I've got a MacBook Pro running a 2.5 GHz Intel Core 2 Duo on Snow Leopard.
The code runs fine when I set the optimization flag to -O0, but fails when I use -O2 or -O3. What is bizarre is that the code runs fine on a Linux box, at least with the default -O2 flag.
Anyone have any ideas on what could be causing the issue? It must be something with vectorization.
At first glance, and without any further information, I jump to the conclusion that your program is unstable; that is, your program produces very different results (failure vs non-failure in some cases) when you tweak the optimisation (which has all sorts of effects on the code that is generated). Some of the tweaks will have an impact on the results of floating-point arithmetic which can easily cause the difference between success and failure for long-running scientific simulations.
This is a symptom of an underlying 'issue' with the program and I would advise you not to rely on the results of 'successful' runs of the program until you understand it a lot better -- you need to prise open the black box and see what's inside.
At the very least you ought test the sensitivity of your program to small changes in inputs.
As already said, it is possible that the final result is numerically sensitive and optimization, which relaxes the arithmetic rules, is resulting in a numeric instability. Or optimization could be revealing a bug in the program. If the code is doing its own memory management (no longer necessary with Fortran 90/95/2003) with an internal array of ints, something could be going wrong different OS. I would investigate further...
I suggest turning on all warning and checking options. If there is a bug and you are lucky they might reveal it or give a clue. At least it is easy to try. Try these options:
-check all -traceback -warn all -fstack-protector
You could also try "-assume protect_parens", which will make ifort compliant with the Fortran standard, and see if that makes the problem go away.
Or maybe the program is assuming that memory is preallocated to some value. Is that a difference from Linux and Mac ?? I think that ifort has options to control this. If it is an old Fortran 77 code, it may assume that local variables are preserved across procedure calls, even without the use of "save" in the declarations. There is a compiler option to cause all local variables to act as if "save" were used -- see if that makes a difference.
精彩评论