Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Does optimizing code make the final product less or more accurate?

Status
Not open for further replies.

RamonetB

Technical User
Oct 20, 2003
4
US
Hello again all!

An interesting situation has arisen. I'm running some code to calculate the neutron transport fluxes in a reactor. Fun stuff. I've compiled two versions of the code using the same compiler (Intel Fortran V.8). One is not optimized and the other is optimized for use on an Intel P4(which is the computer I am using).

The final flux results from each compile vary wildly at times, by as much as 50%!! My question becomes thus: in your best opinions, does an optimized piece of software offer more accurate results than the unoptimized one? Which set of results should I treat with greater authority?

Thanks

-kirk
 
As I see it, there are 2 possibilities for the different results.

One is that there are bugs in the code that show up differently in the optimized and non-optimized code. Examples of these include exceeding the bounds of an array or using an uninitialized variable which is zero in one version and not in the other.

The other possibility is that the code produced by the compiler is wrong in one (or both) cases.

In my experience the optimized code is more likely to be wrong than the non-optimized, but a bug in the code is by far the most likely explanation. I am not familiar with the Intel compiler, but I suggest that you set the warning level to be as high as possible and don't ignore any warnings. Also, if you have access to any other compilers or operating systems, I would try those and compare the results.

Good luck!

CaKiwi
 
For some compilers the highest optimization level may be "unsafe". That is the compiler may:
* Make certain assumptions about your code, which may not be true.
* Use a "fast" math library, which may not give as accurate results.
* etc.

You should check with your particular compiler's documentation to see whether that might be the case.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top