Visual Studio compiler: different output using release configuration vs. debug configuration

Visual Studio compiler: different output using release configuration vs. debug configuration

Post by Deborah Al » Wed, 19 Oct 2005 02:37:25


I've been working on some fairly lengthy calculations, and I discovered
that I could substantially decrease the run time by using the "release
configuration" instead of the "debug configuration" when compiling the
code. When I make this change, I get answers which are slightly
different than those calculated using the debug configuration. Though
the differences are relatively small, I'd like to have a better
understanding of where the difference comes from before trusting one
over the other.

thanks,
Deborah
 
 
 

Visual Studio compiler: different output using release configuration vs. debug configuration

Post by Dan Nagl » Wed, 19 Oct 2005 03:13:57

Hello,

Briefly,the compiler is writing instructions in a slight different
order with the release configuration. Floating point operations
do not generally commute, nor are they associative, etc. Also,
if an operand has been returned to memory rather than staying in
register, it may be shortened or rounded differently.

If your results are scientifically different, you can try doing
a binary sort through your procedures to see where the differences
originate. It's not that hard, but it is time consuming.

If you want to know how, post again. :-)



--
Cheers!

Dan Nagle
Purple Sage Computing Solutions, Inc.

 
 
 

Visual Studio compiler: different output using release configuration vs. debug configuration

Post by Deborah Al » Wed, 19 Oct 2005 04:51:47

Thanks for the info. It makes sense that changing the order of
calculations could lead to a more efficient way to do the calculations.
Is there one way which is more "correct"? My understanding is that
the release configuration does not stop to take variables out of the
register. Does that mean that there are fewer rounding errors?

If I switch to longer variables, will that decrease the difference in
the answers? What's your opinion on whether that's worth the
additional time (and memory) required to do that?

And yes, I'd be interested to know how to do the binary sort and
interpret its output.

thanks,
Deborah
 
 
 

Visual Studio compiler: different output using release configuration vs. debug configuration

Post by Dan Nagl » Wed, 19 Oct 2005 06:26:59

Hello,



It's probably a case of "different rounding" rather than "correct"
versus incorrect. You must judge whether the differences are
significant in terms of your application. Sorry, I can't help there.


Try it and see. How hard it is depends on how the code
is written. If you use named parameters for the kind values,
it may be very easy. If the compiler has a "all reals are 8 bytes"
switch it may be very easy. Otherwise, you must change
declarations using an editor. If you also have specific
references to intrinsic functions (i.e., dsqrt() instead of sqrt()),
there's more tedium to making the change.


Compile all your source files to object files both compiler options.
Put those objects compiled with optimization in a subdirectory
named "O" or "optimized" or whatever you want. Put those objects
compiled with debugging options in a "g" or "debug" or whatever you
want subdirectory.

Copy about half the files from the "O" subdirectory (say, those
whose name starts with A through M) into a "test" subdirectory.
Copy the rest of the objects from the "g" directory into the test
subdirectory. Link using the files in the test subdirectory.
Run the program, check the output.

Repeatedly re-link and run the program. when the output is closer
to the debug output,use more files from the "O" directory. When
the output is closer to the release output, use more files from
the "g" subdirectory. Repeat until you can find one file,
or a small set of files, which make the most difference. Those
are the files whose results are changing the most.

Examine the source code for those files. Look for operations,
such as subtractions of quantities very similar in value,
which may be responsible for the differences. Judge whether
the differences are significant for your applications.

Quick description, sorry, I have class tonight. :-)

--
Cheers!

Dan Nagle
Purple Sage Computing Solutions, Inc.
 
 
 

Visual Studio compiler: different output using release configuration vs. debug configuration

Post by D. Alterma » Sun, 23 Oct 2005 02:15:54

Thanks for the suggestion about looking for an "all reals are 8 bytes"
switch. The compiler has one, and it painlessly switched everything
over to higher precision. This resolves a lot of these questions, and
will make my life easier on lots of other projects as well.
 
 
 

Visual Studio compiler: different output using release configuration vs. debug configuration

Post by Ken Plotki » Sun, 23 Oct 2005 13:53:18

On 21 Oct 2005 10:15:54 -0700, "D. Alterman" < XXXX@XXXXX.COM >



Just don't get complacent about higher precision fixing everything.
Depending on the algorithms you're using (particularly small
differences between large numbers) you can run out of bits with higher
precision, too.

Consider following Dan's suggestion about finding out where the
differences are happening. You'll either find that it's definitely no
big deal, or find that you've been standing on quicksand.

Ken Plotkin