[Insight-developers] VC++ Debug/Release float/double preci sion and Schrodinger's Cat.

Miller, James V (Research) millerjv@crd.ge.com
Mon, 15 Apr 2002 13:31:19 -0400


I think the problem is defining "work".

I would guess that VTK's Delaunay routines or stream line routines
operate suprisingly differently between Release and Debug builds. I 
remember a few years ago we stamped a release of VTK where none of the 
ray cast volume rendering worked when the Microsoft optimizer was on. 
The inner loops of the ray casting just got "optimized away".

I agree that in most cases the Release and Debug builds can produce
"similar" results.  However, I would not say that they will get identical 
results. Algorithms need to be sensitive to the fact that order of operations
can affect precision.  This is why computational geometry algorithms are 
so hard to write.  The classic example is determining what side of a line 
a point lies on. If you test a point against line (a,b), the calculation
may say that you are on the "left" side of the line.  If you run the same
calculation against the line (b,a), the calculation may say that you are
on the "right" side of line (relative to the plane).

My point is that due to the freedom a compiler has to reoder calculations
I never expect two different systems to produce the "same" answer for 
any floating point calculation.


-----Original Message-----
From: Bill Hoffman [mailto:bill.hoffman@kitware.com]
Sent: Monday, April 15, 2002 12:34 PM
To: Luis Ibanez; Miller, James V (Research)
Cc: Insight Developers
Subject: Re: [Insight-developers] VC++ Debug/Release float/double preci
sion and Schrodinger's Cat.


These are advanced features, you can set them in cmake already.

You can change:
CMAKE_CXX_FLAGS   // these flags are added to the compile line for all configurations

There are also these flags:
CMAKE_CXX_FLAGS_RELEASE
CMAKE_CXX_FLAGS_DEBUG
CMAKE_CXX_FLAGS_MINSIZEREL
CMAKE_CXX_FLAGS_RELWITHDEBINFO

Which are added to the specific configuration.   (Note there is already a
optimize for size version).

I do not think we need more configurations or options for cmake.
However, the defaults should work.   Most applications (VTK, etc) will
work with the MS standard Release build.   If ITK does not, then we need
to fix the code to do the right thing with floating point calculations so
it does.    This really has to do with testing coverage, and being careful
with floating point and double operations.

-Bill




At 12:09 PM 4/15/2002 -0400, Luis Ibanez wrote:

>Jim,
>
>Yeap, That's it.
>
>Enabling  "Floating-Point Consistency" in VC++
>produce the right results for the example.
>
>So...      what do we do ?
>
>Should we maybe add a VC++ option in CMake ?
>something like:
>
>     VC++_USE_IEEE_FLOATING_POINT
>
>The concern is that for this particular example
>it was pretty obvious that something was going
>wrong (just three lines of code !) but the same
>can be happening right now on the internals of
>a Registration method when computing derivatives,
>or in the middle of a watershed segmentation or
>in the fuzzy connectedness filter.
>
>In those cases the complexity of the code involved
>will make almost impossible to realize that improper
>computations are being performed at the low level.
>Just reading the code will not help at all.
>
>Selecting this optimization option will sacrify
>speed but anyways...   running faster is useless
>is the results are wrong       :-/
>
>
>BTW there are other optimization options that
>may eventually be interesting to expose at CMake
>level, for example:
>
> - Favor small code
> - Favor fast code
> - Inline Function Expansion
>
>It could probably be better to set this on the
>Advanced level and preced this options (as VC++
>does) with something like :
>
>     VC++_CUSTOMIZE_OPTIMIZATION
>
>only when this option is "ON", CMake will present
>the detailed optimization options.
>
>
>
>
>Luis
>
>
>=====================================================
>
>Miller, James V (Research) wrote:
>>Just looked up the compiler option.  /Op ensures that all intermediate
>>calculations are done according to IEEE standards.  The downside is that it does this by reading
and writing variables to memory instead of leaving
>>them in a register.  The result is that the code is bigger and slower.
>>The /Za option (ANSI compatibility) turns on /Op by default.
>>http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccore/html/_core_.2f.op.asp
>>
>
>
>_______________________________________________
>Insight-developers mailing list
>Insight-developers@public.kitware.com
>http://public.kitware.com/mailman/listinfo/insight-developers