<div dir="ltr">There is a lot going on here, and I'm not certain that I've got all the moving pieces straight in my mind yet, but I've had an quick look at the implementation now. I believe the Mattes v4 implementation is similar to other metrics it it's approach.
<div><br></div><div>As I suggested earlier in the thread: I believe accumulations like this:</div>
<div><br></div><div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"> for( ThreadIdType threadID = 1; threadID < this->GetNumberOfThreadsUsed(); threadID++ )<br>
{<br> this->m_ThreaderJointPDFSum[0] += this->m_ThreaderJointPDFSum[threadID];<br> }</blockquote><div><br></div><div>will guarantee that we don't have absolute consistent results between different threadcounts, due to lack of associativity.</div>
<div><br></div><div>When I perform only transform initialization and a single evaluation of the metric (i.e. outside of the registration routines), I get results consistent with this, for example, results for an center-of-mass initialization between two MR image volumes give me (double precision):</div>
<div><ul><li>1 thread : -0.396771472451519 </li><li>2 threads: -0.396771472450998 </li><li>8 threads: -0.396771472451149</li></ul><div>for the metric evalution (i.e. via GetValue() of the metric)</div></div><div><br></div>
<div>AFAICS, This is consistent magnitude of delta from the above. It will mean not chance of binary equivalence between different threadcounts/partitioning but you can do this accumulation quite a few times before the accumulated divergence gets into digits to worry about. This sort of thing is avoidable, but at some space/speed cost.</div>
<div><br></div><div>However, In the registration for this case it takes only about twenty steps for divergence in the third significant digit between metric estimates! (via registration->GetOptimizer()->GetCurrentMetricValue() )<br>
</div><div><br></div><div>Clearly the optimizer is not following the same path, so I think something else must be going on.<br></div><div><br></div><div>So at this point I don't think the data partitioning of the metric is the root cause, but I will have a more careful look later.</div>
<div><br></div><div>Any holes in this analysis you can see so far? <br></div><div><br></div><div>When I have time to get back into this, I plan to have a look at the optimizer next, unless you have better suggestions of where to look next.</div>
<div><br></div><div>cheers,</div><div>Simon</div><div><br></div><div><br></div><div><br></div><div class="gmail_extra"><div class="gmail_quote">
On Wed, Mar 19, 2014 at 12:56 PM, Simon Alexander <span dir="ltr"><<a href="mailto:skalexander@gmail.com" target="_blank">skalexander@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div dir="ltr">Brian, my apologies for the typo. <div><br></div><div>I assume you all are at least as busy as I am; just didn't want to leave the impression that I would definitely be able to pursue this, but I will try.</div>
</div><div><div><div class="gmail_extra"><br><br><div class="gmail_quote">On Wed, Mar 19, 2014 at 12:45 PM, brian avants <span dir="ltr"><<a href="mailto:stnava@gmail.com" target="_blank">stnava@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr">it's brian - and, yes, we all have "copious free time" of course.</div>
<div class="gmail_extra">
<span><font color="#888888"><br clear="all"><div><div><br></div>brian<br><div><br></div><div><br></div></div></font></span><div><div>
<br><br><div class="gmail_quote">On Wed, Mar 19, 2014 at 12:43 PM, Simon Alexander <span dir="ltr"><<a href="mailto:skalexander@gmail.com" target="_blank">skalexander@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div dir="ltr">Thanks for the summary Brain. <div><br></div><div>A lot of partitioning issues fundamentally come down to the lack of associativity & distributivity of fp operations. Not sure I can do anything practical to improve it but I will have a look if I can find a bit of my "copious free time" . </div>
</div><div><div><div class="gmail_extra"><br><br><div class="gmail_quote">On Wed, Mar 19, 2014 at 12:29 PM, brian avants <span dir="ltr"><<a href="mailto:stnava@gmail.com" target="_blank">stnava@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div>yes - i understand.</div><div><br></div>
* matt mccormick implemented compensated summation to address - it helps but is not a full fix<div>
<br></div><div>* truncating floating point precision greatly reduces the effect you are talking about but is unatisfactory to most people ... not sure if the functionality for that truncation was taken out of the v4 metrics but it was in there at one point. </div>
<div><br></div><div>* there may be a small and undiscovered bug that contributes to this in mattes specificallly but i dont think that's the issue. we saw this effect even in mean squares. if there is a bug it may be beyond just mattes. we cannot disprove that there is a bug. if anyone knows of way to do that, let me know.</div>
<div><br></div><div>* any help is appreciated</div></div><div class="gmail_extra"><span><font color="#888888"><br clear="all"><div><div><br></div>brian<br><div><br></div><div><br></div></div></font></span><div>
<div>
<br><br><div class="gmail_quote">On Wed, Mar 19, 2014 at 12:24 PM, Simon Alexander <span dir="ltr"><<a href="mailto:skalexander@gmail.com" target="_blank">skalexander@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div dir="ltr">Brain,<div><br></div><div>I could have sworn I had initially added a follow up email clarifying this but since I can't find it in the current quoted exchange, let me reiterate:</div><div><br></div><div>
This is not a case of with different results on different systems. This is a case of different results on the same system if you use a different number of threads. </div>
<div><br></div><div>So while that possibly could be some odd intrinsics issue, for example, the far more likely thing is that data partitioning is not being handled in a way that ensures consistency.</div><div><br></div>
<div>
Originally I was also seeing intra-system differences due to internal precision, but that was a separate issue and has been solved.</div><div><br></div><div>Hope that is more clear!</div><div><br></div></div><div>
<div><div class="gmail_extra">
<br><br><div class="gmail_quote">On Wed, Mar 19, 2014 at 12:13 PM, Simon Alexander <span dir="ltr"><<a href="mailto:skalexander@gmail.com" target="_blank">skalexander@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div dir="ltr">Brian,<div><br></div><div>Do you mean the generality of my AVX internal precision problem? </div><div><br></div><div>I agree that is a very common issue, the surprising thing there was that we were already constraining the code generation in way that worked as over the different processor generations and types we used, up until we hit the first Haswell cpus with AVX2 support (even though no AVX2 instructions were generated). Perhaps it shouldn't have surprised me, but It took me a few tests to work that out because the problem was confounded with the problem I discuss in this thread (which is unrelated). Once I separated them it was easy to spot.</div>
<div><br></div><div>So that is a solved issue for now, but I am still interested the partitioning issue in the image metric, as I only have a work around for now.</div><div><br></div></div><div><div>
<div class="gmail_extra"><br><br>
<div class="gmail_quote">On Wed, Mar 19, 2014 at 11:24 AM, brian avants <span dir="ltr"><<a href="mailto:stnava@gmail.com" target="_blank">stnava@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div dir="ltr"><a href="http://software.intel.com/en-us/articles/consistency-of-floating-point-results-using-the-intel-compiler" target="_blank">http://software.intel.com/en-us/articles/consistency-of-floating-point-results-using-the-intel-compiler</a><br>
<div><br></div><div>just as an example of the generality of this problem</div></div><div class="gmail_extra"><span><font color="#888888"><br clear="all"><div><div><br></div>brian<br><div><br></div><div><br>
</div></div></font></span><div><div>
<br><br><div class="gmail_quote">On Wed, Mar 19, 2014 at 11:22 AM, Simon Alexander <span dir="ltr"><<a href="mailto:skalexander@gmail.com" target="_blank">skalexander@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div dir="ltr">Brian, Luis,<div><br></div><div>Thanks. I have been using Mattes as you suspect.<br><div><br></div><div>I don't quite understand how precision is specifically the issue with # of cores. There are all kinds of issues with precision and order of operations in numerical analysis, but often data partitioning (i.e. for concurrency) schemes can be set up so that the actual sums are done the same way regardless of number of workers, which keeps your final results identical. Is there some reason this can't be done for the Matte's metric? I really should look at the implementation to answer that, of course.</div>
<div><br></div><div>Do you have a pointer to earlier discussions? If I can find the time I'd like to dig into this a bit, but I'm not sure when I'll have the bandwidth. I've "solved" this currently by constraining the core count.</div>
</div><div><br></div><div>Perhaps interestingly, my earlier experiments were confounded a bit by a precision issue, but that had to do with intrinsics generation on my compiler behaving differently on systems with AVX2 (even though only AVX intrinsics were being generated). So that made things confusing at first until I separated the issues.</div>
</div><div><div><div class="gmail_extra"><br><br><div class="gmail_quote">On Wed, Mar 19, 2014 at 9:49 AM, brian avants <span dir="ltr"><<a href="mailto:stnava@gmail.com" target="_blank">stnava@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr">yes - we had several discussions about this during v4 development.<div>
<br></div><div>experiments showed that differences are due to precision. </div>
<div><br></div><div>one solution was to truncate precision to the point that is reliable. </div>
<div><br></div><div>but there are problems with that too. last i checked, this was an </div><div><br></div><div>open problem, in general, in computer science.</div></div><div class="gmail_extra"><span><font color="#888888"><br clear="all">
<div><div>
<br></div>brian<br><div><br></div><div><br></div></div></font></span><div><div>
<br><br><div class="gmail_quote">On Wed, Mar 19, 2014 at 9:16 AM, Luis Ibanez <span dir="ltr"><<a href="mailto:luis.ibanez@kitware.com" target="_blank">luis.ibanez@kitware.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div dir="ltr">Hi Simon,<div><br></div><div>We are aware of some multi-threading related issues in </div><div>the registration process that result in metric values changing</div><div>depending on the number of cores used.</div>
<div><br></div><div>Are you using the MattesMutualInformationMetric ?</div><div><br></div><div>At some point it was suspected that the problem was the </div><div>result of accumulative rounding, in the contributions that</div>
<div>each pixel makes to the metric value.... this may or may</div><div>not be related to what you are observing.</div><div> </div><div><br></div><div> Thanks</div><div><br></div><div> Luis</div><div><br></div></div>
<div class="gmail_extra"><br><br><div class="gmail_quote">On Thu, Feb 20, 2014 at 3:27 PM, Simon Alexander <span dir="ltr"><<a href="mailto:skalexander@gmail.com" target="_blank">skalexander@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr">I've been finding some regressions in registration results when using systems with different numbers of cores (so the thread count is different). This is resolved by fixing the global max.<div>
<br></div>
<div>It's difficult for me to run the identical code on against 4.4.2, but similar experiments were run in that timeframe without these regressions.</div><div><br></div><div>I recall that there were changes affecting multhreading in the v4 registration in 4.5.0 release, so I thought this might be a side effect.</div>
<div><br></div><div>So a few questions:</div><div><br></div><div>Is this behaviour expected? </div><div><br></div><div>Am I correct that this was not the behaviour in 4.4.x ?</div><div><br></div><div>Does anyone who has a feel for the recent changes 4.4.2 -> 4.5.[0,1] have a good idea where to start looking? I haven't yet dug into the multithreading architecture, but this "smells" like a data partitioning issue to me.</div>
<div><br></div><div>Any other thoughts?</div><div><br></div><div>cheers,</div><div>Simon</div></div>
<br>_______________________________________________<br>
Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
<br>
Visit other Kitware open-source projects at<br>
<a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
<br>
Kitware offers ITK Training Courses, for more information visit:<br>
<a href="http://kitware.com/products/protraining.php" target="_blank">http://kitware.com/products/protraining.php</a><br>
<br>
Please keep messages on-topic and check the ITK FAQ at:<br>
<a href="http://www.itk.org/Wiki/ITK_FAQ" target="_blank">http://www.itk.org/Wiki/ITK_FAQ</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://www.itk.org/mailman/listinfo/insight-developers" target="_blank">http://www.itk.org/mailman/listinfo/insight-developers</a><br>
<br>_______________________________________________<br>
Community mailing list<br>
<a href="mailto:Community@itk.org" target="_blank">Community@itk.org</a><br>
<a href="http://public.kitware.com/cgi-bin/mailman/listinfo/community" target="_blank">http://public.kitware.com/cgi-bin/mailman/listinfo/community</a><br>
<br></blockquote></div><br></div>
<br>_______________________________________________<br>
Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
<br>
Visit other Kitware open-source projects at<br>
<a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
<br>
Kitware offers ITK Training Courses, for more information visit:<br>
<a href="http://kitware.com/products/protraining.php" target="_blank">http://kitware.com/products/protraining.php</a><br>
<br>
Please keep messages on-topic and check the ITK FAQ at:<br>
<a href="http://www.itk.org/Wiki/ITK_FAQ" target="_blank">http://www.itk.org/Wiki/ITK_FAQ</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://www.itk.org/mailman/listinfo/insight-developers" target="_blank">http://www.itk.org/mailman/listinfo/insight-developers</a><br>
<br></blockquote></div><br></div></div></div>
</blockquote></div><br></div>
</div></div></blockquote></div><br></div></div></div>
</blockquote></div><br></div>
</div></div></blockquote></div><br></div>
</div></div></blockquote></div><br></div></div></div>
</blockquote></div><br></div>
</div></div></blockquote></div><br></div></div></div>
</blockquote></div><br></div>
</div></div></blockquote></div><br></div></div></div>