Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added deterministic option #550

Merged
merged 7 commits into from
Sep 5, 2023
Merged

Conversation

pca006132
Copy link
Collaborator

@pca006132 pca006132 commented Sep 5, 2023

This disables some racy optimizations when user wants deterministic output. We should now consider non-deterministic output when deterministic option is enabled a bug.

The area and volume calculation now uses Kahan summation, which is numerically stable.

Also, it turns out parallel compose will somehow cause non-determinism. Considering we already do parallel for inside compose, I just disabled doing multiple compose in parallel and rewrote it in a simpler way.

Fixes #545.

@pca006132 pca006132 requested a review from elalish September 5, 2023 03:34
src/manifold/src/boolean_result.cpp Outdated Show resolved Hide resolved
src/utilities/include/public.h Outdated Show resolved Hide resolved
test/boolean_test.cpp Outdated Show resolved Hide resolved
#else
std::sort(starts.begin(), starts.end(), cmp);
std::stable_sort(starts.begin(), starts.end(), cmp);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do these stable sorts make much difference?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably not, this is just in case. the performance of stable sort is not a lot different than sort from my testing

(FYI: rust uses stable sort by default, and the c++ sort is named unstable sort in rust and we will only use it when profile shows it is beneficial)

@pca006132 pca006132 marked this pull request as ready for review September 5, 2023 05:08
@codecov
Copy link

codecov bot commented Sep 5, 2023

Codecov Report

Patch coverage: 84.21% and project coverage change: -0.10% ⚠️

Comparison is base (77051ea) 91.23% compared to head (cfbd0c4) 91.13%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #550      +/-   ##
==========================================
- Coverage   91.23%   91.13%   -0.10%     
==========================================
  Files          35       35              
  Lines        4553     4547       -6     
==========================================
- Hits         4154     4144      -10     
- Misses        399      403       +4     
Files Changed Coverage Δ
src/utilities/include/par.h 96.87% <ø> (-0.19%) ⬇️
src/utilities/include/public.h 67.05% <0.00%> (ø)
src/manifold/src/sort.cpp 89.61% <66.66%> (ø)
src/manifold/src/properties.cpp 82.16% <90.00%> (-1.50%) ⬇️
src/manifold/src/boolean_result.cpp 98.74% <100.00%> (ø)
src/manifold/src/csg_tree.cpp 91.00% <100.00%> (-0.58%) ⬇️
src/manifold/src/edge_op.cpp 95.34% <100.00%> (ø)
src/polygon/src/polygon.cpp 91.12% <100.00%> (ø)
src/utilities/include/sparse.h 51.35% <100.00%> (ø)

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Owner

@elalish elalish left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

FaceAreaVolume({halfedge_, vertPos_, precision_}),
thrust::make_pair(0.0f, 0.0f), SumPair());
return {areaVolume.first, areaVolume.second};
// Kahan summation
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is cool - I hadn't heard of this before.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, I just know this after searching for numerically stable summation algorithm.

@pca006132 pca006132 merged commit 5e10393 into elalish:master Sep 5, 2023
@elalish elalish mentioned this pull request Nov 3, 2023
cartesian-theatrics pushed a commit to SovereignShop/manifold that referenced this pull request Mar 11, 2024
* added deterministic option

* fix formatting

* address some comments

* use kahan summation

* revert DoesOverlap changes

* remove old code

* formatting
@pca006132 pca006132 deleted the determinism branch November 16, 2024 16:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Volume calculation is not deterministic
2 participants