Skip to content

[Point Set Processing] Big factorization + cleanup#4552

Merged
sloriot merged 32 commits intoCGAL:masterfrom
sgiraudot:PSP-No_copy_for_kdtree-GF
Apr 2, 2020
Merged

[Point Set Processing] Big factorization + cleanup#4552
sloriot merged 32 commits intoCGAL:masterfrom
sgiraudot:PSP-No_copy_for_kdtree-GF

Conversation

@sgiraudot
Copy link
Copy Markdown
Contributor

Summary of Changes

This PR introduces many factorizations and cleaning in the PSP package (internal code only, no API change):

  • In lots of places, points were copied in a first container then passed to the KD tree (which copied them again), which seems quite inefficient. The KD tree now works on the input range (using iterators to limit copies if the data set is big)
  • The neighbor search that I already factorized some time ago is even more factorized now (even the tree type/instantiation is now handled in a single class, removing many code duplication)
  • TBB functors are removed and replaced by lambdas (which are much more self-contained as no typedefs/templates are required)
  • The Parallel_callback I introduced to handle callbacks in parallel mode is replaced by a Callback_wrapper which indifferently works with sequential and parallel
  • A function (so far undocumented) CGAL::for_each is introduced to run a functor on a range either sequentially or in parallel with TBB. It checks that no parallel tag is used without TBB being linked and it handles the cases of parallel loop on non-random access iterators (by copying iterators in a vector, which is equivalent to what was done in PSP in general, only now it only happens in the worst case scenario)

In general, the code of PSP is largely reduced and much more readable. Many functions were written ike that:

#ifndef CGAL_LINKED_WITH_TBB
  CGAL_static_assertion_msg (!(boost::is_convertible<ConcurrencyTag, Parallel_tag>::value),
			     "Parallel_tag is enabled but TBB is unavailable.");
#else
   if (boost::is_convertible<ConcurrencyTag,Parallel_tag>::value)
   {
     CGAL::internal::Tbb_functor_defined_somewhere_else</* many template paremeters */>
       f (/* many parameters */);
     tbb::parallel_for(tbb::blocked_range<size_t>(0, kd_tree_points.size ()), f);
   }
   else
#endif
     {
       for(typename PointRange::const_iterator it = points.begin(); it != points.end(); it++, nb++)
       {
         /* The actual algorithm, often duplicated in TBB functor */
       }
     }

Now they look like that:

  CGAL::for_each<ConcurrencyTag>
    (points,
     [&](const typename PointRange::const_iterator::value_type& t)
     {
       /* The actual algorithm */
     });

Release Management

  • Affected package(s): PSP, Demo

@maxGimeno
Copy link
Copy Markdown
Contributor

travis error

@maxGimeno
Copy link
Copy Markdown
Contributor

still :(

@sgiraudot
Copy link
Copy Markdown
Contributor Author

Sorry, I should have spotted those… I rerun PSP examples + tests locally, it should be good now.

@lrineau
Copy link
Copy Markdown
Member

lrineau commented Mar 5, 2020

A license issue, now: https://travis-ci.com/CGAL/cgal/jobs/294843121#L2868

@sgiraudot
Copy link
Copy Markdown
Contributor Author

Please do not merge this PR yet, I just found a bug.

@sgiraudot
Copy link
Copy Markdown
Contributor Author

Fixed.

@sloriot
Copy link
Copy Markdown
Member

sloriot commented Mar 18, 2020

There is a least one warning. Please check other possible impacted packages. Poisson runtime error is most probably related to the PR about the compact container.

@maxGimeno
Copy link
Copy Markdown
Contributor

error

@maxGimeno
Copy link
Copy Markdown
Contributor

@MaelRL MaelRL changed the base branch from master to releases/CGAL-4.14-branch March 26, 2020 20:02
@MaelRL MaelRL changed the base branch from releases/CGAL-4.14-branch to master March 26, 2020 20:03
return m_random.get_double() < ratio;
bool operator()(Iterator it) const {
// make the result deterministic for each iterator
return Random((std::size_t)(&*it)).get_double() < ratio;
Copy link
Copy Markdown
Member

@sloriot sloriot Mar 27, 2020

Choose a reason for hiding this comment

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

@lrineau : this is not something we should do, right?
@sgiraudot what are you trying to achieve? you need different seeds per iterator? This won't be deterministic across runs AFAIU.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

First, that does not seem efficient, to create an object of type Random, at each call, just to get a few random bits.

Second, I am surprised, because I think the previous version (before the patch) seemed deterministic, and then the second one seems to be non-deterministic, because that depends on the memory layout. And the comment says the contrary.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The previous version produced a different range everytime a for() loop was used to iterator from begin to end, which created problems in the new version of compute_average_spacing() where the range is iterated twice. This patch was made to make the range consistently the same if iterated several times.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

can't you init the random with the size of the range as seed once?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It's not a matter of initialization.
Do this:

for(const auto& : range)
  // something

for(const auto& : range)
  // something

and you don't get the same range on the second loop, no matter the initialization. Maybe I could use a trick to initialize a shared Random object when calling begin()

@maxGimeno
Copy link
Copy Markdown
Contributor

The following files have trailing whitespaces:
Poisson_surface_reconstruction_3/include/CGAL/Poisson_reconstruction_function.h

@sloriot
Copy link
Copy Markdown
Member

sloriot commented Apr 2, 2020

Tested in CGAL-5.1-Ic-114

@sloriot sloriot self-assigned this Apr 2, 2020
@sloriot sloriot merged commit 3bca04d into CGAL:master Apr 2, 2020
@sloriot sloriot deleted the PSP-No_copy_for_kdtree-GF branch April 2, 2020 12:13
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.

6 participants