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

Improvement backports from CDT_3 branch (Follow-up to PR #8170) #8273

Draft
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

lrineau
Copy link
Member

@lrineau lrineau commented Jun 10, 2024

Summary of Changes

In the PR #8170, merged for CGAL-6.0, there was several commits that I had to revert, because they broke the testsuite results:

This pull-request reintroduces those features, for CGAL-6.1.

Release Management

  • Affected package(s):
  • License and copyright ownership: maintenance by GeometryFactory

@lrineau

This comment was marked as outdated.

@lrineau

This comment was marked as outdated.

Comment on lines 165 to 169
#if CGAL_USE_BOOST_UNORDERED
typedef boost::unordered_flat_map<Edge, Context_list*, boost::hash<Edge>> Sc_to_c_map;
#else
typedef std::unordered_map<Edge, Context_list*, boost::hash<Edge>> Sc_to_c_map;
#endif
Copy link
Member Author

Choose a reason for hiding this comment

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

Order of the sequence of values from the range CGAL::Constrained_triangulation_plus_2<Tr>::subconstraints()

@janetournois @afabri

  • The patch 93fd966 makes the range CGAL::Constrained_triangulation_plus_2<Tr>::subconstraints() non-deterministic: instead of a std::map with a custom compare functor, now the sub-constraints are in an unordered map, for efficiency reasons. Note that the range was never documented as sorted or deterministic.
  • As my patch had broken a test from Mesh_2 (the test test_meshing), I had to fix that non-determinism. That was complicated to fix directly in Constrained_triangulation_plus_2 or Constrained_triangulation_plus_2. Instead, I have chosen to fix the only place in CGAL where the order of that range mattered, in Mesh_2/include/CGAL/Mesh_2/Refine_edges.h. See the commit 82b5359.

Is that correct? That is a sort of breaking change, but the ordering of Ctp_2::constraints() was never documented.

Copy link
Member Author

Choose a reason for hiding this comment

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

Jane (IRL) suggested that:

  • it is documented that there is a breaking change
  • and add a Tag to Constrained_triangulation_plus_2 to allow users to fallback to the previous behavior.

This comment was marked as off-topic.

Copy link
Member

Choose a reason for hiding this comment

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

Any idea how big the gain in efficiency is @lrineau ?

Copy link
Member

Choose a reason for hiding this comment

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

In order to avoid ping-pong changes, I suggest to have CGAL::unordered_map and to use it everywhere (at least for default hashable items).

Copy link
Member Author

@lrineau lrineau Jan 7, 2025

Choose a reason for hiding this comment

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

Speedups

@afabri:

Any idea how big the gain in efficiency is @lrineau ?

One the data set "Thingi #101881", I have run the experimental CDT_3 code, with compilation flags -O3 -DCGAL_NDEBUG. The timings of the step "conforming of facets borders" vary a lot:

with... time factor
std::map 4110 ms 1.00
std::unordered_map 3623 ms 0.88
boost::unordered_flat_map 2897 ms 0.70

I have repeated multiple time each of the three runs. The variance of the timings between each run is less than 5%, and the difference between the three implementations is about 15%.

And the code the "CDT_3 conforming" does a lot more than just handling the CGAL::Constrained_triangulation_plus_2 data-structure. The speedups are significant, in my opinion.

Code

@sloriot:

I suggest to have CGAL::unordered_map

Indeed. I have a patch. I will push it...

Copy link
Member

Choose a reason for hiding this comment

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

We had several times users where we worked hard to make algorithms deterministic for reproductibility. So this is maybe more important than speed. Also I find it more natural that subconstraints are ordered along the constraint.

Copy link
Member

Choose a reason for hiding this comment

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

I just realize that subconstraints are not the subconstraints of a constraint, but all subconstraints in the constrained triangulation. Instead iterating over the Xmap, why don't we iterate over the vertices of the constraints, as a subconstraint is just a pair of consecutive vertices on a constraint?

Copy link
Member Author

Choose a reason for hiding this comment

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

CGAL::unordered_map

I have pushed the commit 5526857. The results of the testsuites of Triangulation_2, Mesh_2, and Polyline_simplification_2 are PASSED on my machine (with Boost.Unordered available).

lrineau added a commit to lrineau/cgal that referenced this pull request Jul 1, 2024
@lrineau lrineau changed the title Follow-up to PR #8170 Improvement backports from CDT_3 branch (Follow-up to PR #8170) Aug 22, 2024
@lrineau

This comment was marked as off-topic.

@lrineau

This comment was marked as off-topic.

@lrineau

This comment was marked as off-topic.

This comment was marked as off-topic.

...and `refactor Polyline_constraint_hierarchy_2` to use it.

`CGAL::unordered_flat_map` will be Boost `unordered_flat_map` if availlable, or the standard `std::unordered_map` otherwise.
To debug non-determinism on Linux platforms.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants