From 56106ae42b42e7b0af0d068bdefe978049087229 Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Mon, 15 Mar 2021 18:45:17 +0100 Subject: [PATCH 1/6] Add a test (which so far does not show any difference --- Kernel_23/test/Kernel_23/identical.cpp | 30 ++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 Kernel_23/test/Kernel_23/identical.cpp diff --git a/Kernel_23/test/Kernel_23/identical.cpp b/Kernel_23/test/Kernel_23/identical.cpp new file mode 100644 index 00000000000..25a5837046c --- /dev/null +++ b/Kernel_23/test/Kernel_23/identical.cpp @@ -0,0 +1,30 @@ +#define CGAL_IDENTICAL + +#include +#include + +#include +#include + +typedef CGAL::Exact_predicates_exact_constructions_kernel K; +typedef K::Point_3 Point_3; + + +int main(){ + + int N = 10000000; + + std::vector points(N); + + for(int i = 0; i < N; i+=10){ + points[i] = Point_3((N-i) * CGAL_PI , 0, 0); + for(int j = 1; j < 10; j++){ + points[i+j] = points[i]; + } + } + CGAL::Timer t; + t.start(); + std::sort(points.begin(), points.end()); + std::cout << t.time() << " sec." << std::endl; + return 0; +} From 5aecb82f7b5764c7d94eb36eed0fb9a6c81a1ba6 Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Mon, 15 Mar 2021 19:00:45 +0100 Subject: [PATCH 2/6] Construct points where inf !=sup for the intervals --- Kernel_23/test/Kernel_23/identical.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Kernel_23/test/Kernel_23/identical.cpp b/Kernel_23/test/Kernel_23/identical.cpp index 25a5837046c..86e8fec5f9c 100644 --- a/Kernel_23/test/Kernel_23/identical.cpp +++ b/Kernel_23/test/Kernel_23/identical.cpp @@ -1,4 +1,4 @@ -#define CGAL_IDENTICAL +#define TEST_IDENTICAL #include #include @@ -8,6 +8,7 @@ typedef CGAL::Exact_predicates_exact_constructions_kernel K; typedef K::Point_3 Point_3; +typedef K::Vector_3 Vector_3; int main(){ @@ -16,12 +17,17 @@ int main(){ std::vector points(N); + int count = 0; for(int i = 0; i < N; i+=10){ - points[i] = Point_3((N-i) * CGAL_PI , 0, 0); + points[i] = Point_3((N-i) * CGAL_PI , 0, 0) + Vector_3(i * (CGAL_PI/2.0), 0, 0); + if(points[i].approx().x().inf() != points[i].approx().x().sup()){ + ++count; + } for(int j = 1; j < 10; j++){ points[i+j] = points[i]; } } + std::cout << count << " points approx().x().inf() != approx().x().sup()" << std::endl; CGAL::Timer t; t.start(); std::sort(points.begin(), points.end()); From 51490546c10f47b3e147ed09644ef566f70df55e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Loriot?= Date: Sat, 10 Apr 2021 07:03:19 +0200 Subject: [PATCH 3/6] move to benchmark --- Kernel_23/benchmark/Kernel_23/CMakeLists.txt | 12 ++++++++++++ .../Kernel_23/cmp_epeck_points.cpp} | 0 2 files changed, 12 insertions(+) create mode 100644 Kernel_23/benchmark/Kernel_23/CMakeLists.txt rename Kernel_23/{test/Kernel_23/identical.cpp => benchmark/Kernel_23/cmp_epeck_points.cpp} (100%) diff --git a/Kernel_23/benchmark/Kernel_23/CMakeLists.txt b/Kernel_23/benchmark/Kernel_23/CMakeLists.txt new file mode 100644 index 00000000000..d061469c729 --- /dev/null +++ b/Kernel_23/benchmark/Kernel_23/CMakeLists.txt @@ -0,0 +1,12 @@ +# Created by the script cgal_create_cmake_script +# This is the CMake script for compiling a CGAL application. + +cmake_minimum_required(VERSION 3.1...3.14) +project( benchmark ) + +find_package(CGAL REQUIRED QUIET OPTIONAL_COMPONENTS Core ) + + include_directories (BEFORE "../include") + +create_single_source_cgal_program( "cmp_epeck_points.cpp" ) + diff --git a/Kernel_23/test/Kernel_23/identical.cpp b/Kernel_23/benchmark/Kernel_23/cmp_epeck_points.cpp similarity index 100% rename from Kernel_23/test/Kernel_23/identical.cpp rename to Kernel_23/benchmark/Kernel_23/cmp_epeck_points.cpp From 68dc09b3d9840580433af49b8137899b8e935fa4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Loriot?= Date: Sat, 10 Apr 2021 07:10:29 +0200 Subject: [PATCH 4/6] optimize filter failures cmp_epeck_points.cpp runtime goes from 23s. to 5s. based on mglisse suggestion --- .../include/CGAL/predicates/kernel_ftC2.h | 20 +++++++++-------- .../include/CGAL/predicates/kernel_ftC3.h | 22 ++++++++++--------- .../include/CGAL/Kernel/function_objects.h | 4 ++-- STL_Extension/include/CGAL/Uncertain.h | 1 + 4 files changed, 26 insertions(+), 21 deletions(-) diff --git a/Cartesian_kernel/include/CGAL/predicates/kernel_ftC2.h b/Cartesian_kernel/include/CGAL/predicates/kernel_ftC2.h index 601dcf5c9a0..7e49bb62376 100644 --- a/Cartesian_kernel/include/CGAL/predicates/kernel_ftC2.h +++ b/Cartesian_kernel/include/CGAL/predicates/kernel_ftC2.h @@ -55,10 +55,10 @@ equal_lineC2(const FT &l1a, const FT &l1b, const FT &l1c, return false; // Not parallel. typename Sgn::result_type s1a = CGAL_NTS sign(l1a); if (s1a != ZERO) - return s1a == CGAL_NTS sign(l2a) - && sign_of_determinant(l1a, l1c, l2a, l2c) == ZERO; - return CGAL_NTS sign(l1b) == CGAL_NTS sign(l2b) - && sign_of_determinant(l1b, l1c, l2b, l2c) == ZERO; + return CGAL_AND(s1a == CGAL_NTS sign(l2a), + sign_of_determinant(l1a, l1c, l2a, l2c) == ZERO); + return CGAL_AND(CGAL_NTS sign(l1b) == CGAL_NTS sign(l2b), + sign_of_determinant(l1b, l1c, l2b, l2c) == ZERO); } template < class FT > @@ -230,7 +230,7 @@ compare_y_at_x_segment_C2(const FT &px, CGAL_kernel_precondition(are_ordered(s1sx, px, s1tx)); CGAL_kernel_precondition(are_ordered(s2sx, px, s2tx)); - if (s1sx != s1tx && s2sx != s2tx) { + if (CGAL_AND(s1sx != s1tx, s2sx != s2tx)) { FT s1stx = s1sx-s1tx; FT s2stx = s2sx-s2tx; @@ -265,9 +265,9 @@ typename Equal_to::result_type equal_directionC2(const FT &dx1, const FT &dy1, const FT &dx2, const FT &dy2) { - return CGAL_NTS sign(dx1) == CGAL_NTS sign(dx2) - && CGAL_NTS sign(dy1) == CGAL_NTS sign(dy2) - && sign_of_determinant(dx1, dy1, dx2, dy2) == ZERO; + return CGAL_AND_3( CGAL_NTS sign(dx1) == CGAL_NTS sign(dx2), + CGAL_NTS sign(dy1) == CGAL_NTS sign(dy2), + sign_of_determinant(dx1, dy1, dx2, dy2) == ZERO ); } template < class FT > @@ -391,7 +391,9 @@ typename Compare::result_type compare_lexicographically_xyC2(const FT &px, const FT &py, const FT &qx, const FT &qy) { - typename Compare::result_type c = CGAL_NTS compare(px,qx); + typedef typename Compare::result_type Cmp; + Cmp c = CGAL_NTS compare(px,qx); + if (is_indeterminate(c)) return indeterminate(); return (c != EQUAL) ? c : CGAL_NTS compare(py,qy); } diff --git a/Cartesian_kernel/include/CGAL/predicates/kernel_ftC3.h b/Cartesian_kernel/include/CGAL/predicates/kernel_ftC3.h index ba15fd30790..8765d0cb587 100644 --- a/Cartesian_kernel/include/CGAL/predicates/kernel_ftC3.h +++ b/Cartesian_kernel/include/CGAL/predicates/kernel_ftC3.h @@ -61,8 +61,10 @@ compare_lexicographically_xyzC3(const FT &px, const FT &py, const FT &pz, { typedef typename Compare::result_type Cmp; Cmp c = CGAL_NTS compare(px, qx); + if (is_indeterminate(c)) return indeterminate(); if (c != EQUAL) return c; c = CGAL_NTS compare(py, qy); + if (is_indeterminate(c)) return indeterminate(); if (c != EQUAL) return c; return CGAL_NTS compare(pz, qz); } @@ -288,12 +290,12 @@ typename Equal_to::result_type equal_directionC3(const FT &dx1, const FT &dy1, const FT &dz1, const FT &dx2, const FT &dy2, const FT &dz2) { - return sign_of_determinant(dx1, dy1, dx2, dy2) == ZERO - && sign_of_determinant(dx1, dz1, dx2, dz2) == ZERO - && sign_of_determinant(dy1, dz1, dy2, dz2) == ZERO - && CGAL_NTS sign(dx1) == CGAL_NTS sign(dx2) - && CGAL_NTS sign(dy1) == CGAL_NTS sign(dy2) - && CGAL_NTS sign(dz1) == CGAL_NTS sign(dz2); + return CGAL_AND_6(sign_of_determinant(dx1, dy1, dx2, dy2) == ZERO, + sign_of_determinant(dx1, dz1, dx2, dz2) == ZERO, + sign_of_determinant(dy1, dz1, dy2, dz2) == ZERO, + CGAL_NTS sign(dx1) == CGAL_NTS sign(dx2), + CGAL_NTS sign(dy1) == CGAL_NTS sign(dy2), + CGAL_NTS sign(dz1) == CGAL_NTS sign(dz2) ); } template < class FT > @@ -313,10 +315,10 @@ equal_planeC3(const FT &ha, const FT &hb, const FT &hc, const FT &hd, sign_of_determinant(pa, pd, ha, hd) == ZERO ); Sg s1b = CGAL_NTS sign(hb); if (s1b != ZERO) - return s1b == CGAL_NTS sign(pb) - && sign_of_determinant(pb, pd, hb, hd) == ZERO; - return CGAL_NTS sign(pc) == CGAL_NTS sign(hc) - && sign_of_determinant(pc, pd, hc, hd) == ZERO; + return CGAL_AND(s1b == CGAL_NTS sign(pb), + sign_of_determinant(pb, pd, hb, hd) == ZERO ); + return CGAL_AND( CGAL_NTS sign(pc) == CGAL_NTS sign(hc), + sign_of_determinant(pc, pd, hc, hd) == ZERO ); } template diff --git a/Kernel_23/include/CGAL/Kernel/function_objects.h b/Kernel_23/include/CGAL/Kernel/function_objects.h index 1a803d094ae..40d05f8094d 100644 --- a/Kernel_23/include/CGAL/Kernel/function_objects.h +++ b/Kernel_23/include/CGAL/Kernel/function_objects.h @@ -3111,7 +3111,7 @@ namespace CommonKernelFunctors { result_type operator()(const Iso_rectangle_2& i1, const Iso_rectangle_2& i2) const { - return ((i1.min)() == (i2.min)()) && ((i1.max)() == (i2.max)()); + return CGAL_AND((i1.min)() == (i2.min)(), (i1.max)() == (i2.max)()); } }; @@ -3138,7 +3138,7 @@ namespace CommonKernelFunctors { result_type operator()(const Point_3 &p, const Point_3 &q) const { - return p.x() == q.x() && p.y() == q.y() && p.z() == q.z(); + return CGAL_AND_3(p.x() == q.x(), p.y() == q.y(), p.z() == q.z()); } result_type diff --git a/STL_Extension/include/CGAL/Uncertain.h b/STL_Extension/include/CGAL/Uncertain.h index 21f46a9196a..1a7539b2b24 100644 --- a/STL_Extension/include/CGAL/Uncertain.h +++ b/STL_Extension/include/CGAL/Uncertain.h @@ -348,6 +348,7 @@ Uncertain operator&(Uncertain a, bool b) #endif #define CGAL_AND_3(X, Y, Z) CGAL_AND(X, CGAL_AND(Y, Z)) +#define CGAL_AND_6(A, B, C, D, E, F) CGAL_AND(CGAL_AND_3(A, B, C), CGAL_AND_3(D, E,F)) #define CGAL_OR_3(X, Y, Z) CGAL_OR(X, CGAL_OR(Y, Z)) From 8e2b75d3daf150922456fa72ca18097a19cf9615 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Loriot?= Date: Sat, 10 Apr 2021 08:00:39 +0200 Subject: [PATCH 5/6] optimize lexicographic cmp of identical points cmp_epeck_points.cpp runs in 2.6s --- Filtered_kernel/include/CGAL/Lazy_kernel.h | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/Filtered_kernel/include/CGAL/Lazy_kernel.h b/Filtered_kernel/include/CGAL/Lazy_kernel.h index 89a84b5f150..8c02b7f7c99 100644 --- a/Filtered_kernel/include/CGAL/Lazy_kernel.h +++ b/Filtered_kernel/include/CGAL/Lazy_kernel.h @@ -480,6 +480,18 @@ public: }; + struct Less_xyz_3 : public BaseClass::Less_xyz_3 + { + typedef typename Kernel_::Point_3 Point_3; + + using BaseClass::Less_xyz_3::operator(); + + bool operator()(const Point_3& p, const Point_3& q) const + { + if (p.rep().identical(q.rep())) { return false; } + return BaseClass::Less_xyz_3::operator()(p,q); + } + }; Construct_point_2 construct_point_2_object() const { @@ -502,7 +514,6 @@ public: return Compute_weight_3(); } - Assign_2 assign_2_object() const { return Assign_2(); } @@ -534,6 +545,10 @@ public: Compute_approximate_area_3 compute_approximate_area_3_object() const { return Compute_approximate_area_3(); } + + Less_xyz_3 + less_xyz_3_object() const + { return Less_xyz_3(); } }; // end class Lazy_kernel_base From 39bdf32bc9922171cafec5c841d7b15d7d13c384 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Loriot?= Date: Tue, 13 Apr 2021 08:07:56 +0200 Subject: [PATCH 6/6] remove useless using statement --- Filtered_kernel/include/CGAL/Lazy_kernel.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/Filtered_kernel/include/CGAL/Lazy_kernel.h b/Filtered_kernel/include/CGAL/Lazy_kernel.h index 8c02b7f7c99..0e9bb380f6a 100644 --- a/Filtered_kernel/include/CGAL/Lazy_kernel.h +++ b/Filtered_kernel/include/CGAL/Lazy_kernel.h @@ -484,8 +484,6 @@ public: { typedef typename Kernel_::Point_3 Point_3; - using BaseClass::Less_xyz_3::operator(); - bool operator()(const Point_3& p, const Point_3& q) const { if (p.rep().identical(q.rep())) { return false; }