Parallel make_mesh_3 does not have a speed-up

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Parallel make_mesh_3 does not have a speed-up

Chen Zhenghai
Hello,

I tried to enable concurrency in Mesh_3 package and link with tbb using
VS2017. However, it seems that there was no difference between sequential
and parallel versions when I switched on and off CGAL_CONCURRENT_MESH_3. Can
anybody help?

My CMakeLists and cpp are shown as follows:

=================CMakeLists======================
# Created by the script cgal_create_cmake_script
# This is the CMake script for compiling a CGAL application.


project(CGALmesh)

cmake_minimum_required(VERSION 2.8.11)

add_definitions(-DCGAL_MESH_3_NO_DEPRECATED_SURFACE_INDEX
                -DCGAL_MESH_3_NO_DEPRECATED_C3T3_ITERATORS)

if ( MESH_3_VERBOSE )
  add_definitions(-DCGAL_MESH_3_VERBOSE)
endif()

find_package(CGAL COMPONENTS)

if ( CGAL_FOUND )
        include( ${CGAL_USE_FILE} )

          # Activate concurrency ? (turned OFF by default)
          option(CGAL_ACTIVATE_CONCURRENT_MESH_3
                "Activate parallelism in Mesh_3"
                ON)
   
          # And add -DCGAL_CONCURRENT_MESH_3 if that option is ON
          if( CGAL_ACTIVATE_CONCURRENT_MESH_3 OR
ENV{CGAL_ACTIVATE_CONCURRENT_MESH_3} )
                add_definitions( -DCGAL_CONCURRENT_MESH_3 )
                find_package( TBB REQUIRED )
          else( CGAL_ACTIVATE_CONCURRENT_MESH_3 OR
ENV{CGAL_ACTIVATE_CONCURRENT_MESH_3} )
                option( LINK_WITH_TBB
                  "Link with TBB anyway so we can use TBB timers for profiling"
                  ON)
                if( LINK_WITH_TBB )
                  find_package( TBB )
                endif( LINK_WITH_TBB )
          endif()

        create_single_source_cgal_program("CGALmesh.cpp")
        foreach(target
                CGALmesh)
                if(TBB_FOUND AND TARGET ${target})
                        CGAL_target_use_TBB(${target})
                endif()
        endforeach()

else()
  message(STATUS "This program requires the CGAL library, and will not be
compiled.")
endif()

==================cpp====================
#define CGAL_LINKED_WITH_TBB
#define CGAL_CONCURRENT_MESH_3
#define NOMINMAX

#include <iostream>
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Mesh_triangulation_3.h>
#include <CGAL/Mesh_complex_3_in_triangulation_3.h>
#include <CGAL/Mesh_criteria_3.h>
#include <CGAL/Polyhedron_3.h>
#include <CGAL/Polyhedral_mesh_domain_with_features_3.h>
#include <CGAL/make_mesh_3.h>
#include <CGAL/Delaunay_Triangulation_3.h>

// Domain
typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
typedef CGAL::Mesh_polyhedron_3<K>::type Polyhedron;
typedef CGAL::Polyhedral_mesh_domain_with_features_3<K> Mesh_domain;

#ifdef CGAL_CONCURRENT_MESH_3
typedef CGAL::Parallel_tag Concurrency_tag;
#else
typedef CGAL::Sequential_tag Concurrency_tag;
#endif

// Triangulation
typedef CGAL::Mesh_triangulation_3<Mesh_domain, CGAL::Default,
Concurrency_tag>::type Tr;
typedef CGAL::Mesh_complex_3_in_triangulation_3<
        Tr, Mesh_domain::Corner_index, Mesh_domain::Curve_index> C3t3;
typedef C3t3::Triangulation Tr3;
// Criteria
typedef CGAL::Mesh_criteria_3
 Mesh_criteria;
// To avoid verbose function and named parameters call
using namespace CGAL::parameters;

int main()
{
        std::cout.precision(17);
        std::cerr.precision(17);

        char *fname = "fn";
        std::ifstream input(fname);
        char* fname2 = "fn2";
        std::ifstream input2(fname2);
        Polyhedron sm, smbounding;
        input >> sm;
        input2 >> smbounding;
        if (input.fail()) {
                std::cerr << "Error: Cannot read file " << fname << std::endl;
                std::cin.get();
                return 0;
        }

        // Create domain
        Mesh_domain domain(sm, smbounding);

        // Get sharp features
        domain.detect_features();

        Mesh_criteria criteria(
                edge_size = 5,
                facet_distance = 1,
                cell_radius_edge_ratio = 1.414);

        // Mesh generation
        C3t3 c3t3 = CGAL::make_mesh_3<C3t3>(domain, criteria,
                no_perturb(), no_exude());
}





--
Sent from: http://cgal-discuss.949826.n4.nabble.com/

--
You are currently subscribed to cgal-discuss.
To unsubscribe or access the archives, go to
https://sympa.inria.fr/sympa/info/cgal-discuss


Reply | Threaded
Open this post in threaded view
|

Re: Parallel make_mesh_3 does not have a speed-up

Laurent Rineau (CGAL/GeometryFactory)
On Thursday, May 9, 2019 9:46:31 AM CEST Chen Zhenghai wrote:

> int main()
> {
> std::cout.precision(17);
> std::cerr.precision(17);
>
> char *fname = "fn";
> std::ifstream input(fname);
> char* fname2 = "fn2";
> std::ifstream input2(fname2);
> Polyhedron sm, smbounding;
> input >> sm;
> input2 >> smbounding;
> if (input.fail()) {
> std::cerr << "Error: Cannot read file " << fname << std::endl;
> std::cin.get();
> return 0;
> }
>
> // Create domain
> Mesh_domain domain(sm, smbounding);
>
> // Get sharp features
> domain.detect_features();
>
> Mesh_criteria criteria(
> edge_size = 5,
> facet_distance = 1,
> cell_radius_edge_ratio = 1.414);
>
> // Mesh generation
> C3t3 c3t3 = CGAL::make_mesh_3<C3t3>(domain, criteria,
> no_perturb(), no_exude());
> }

Hi,

What were the two input files you used? Maybe with those criteria the meshing
process was either too short to exploit the parallelism, or it was dominated
by the non-parallel pre-processing stage. If you share the input files, I can
try to measure that.

--
Laurent Rineau, PhD
R&D Engineer at GeometryFactory           http://www.geometryfactory.com/
Release Manager of the CGAL Project       http://www.cgal.org/




--
You are currently subscribed to cgal-discuss.
To unsubscribe or access the archives, go to
https://sympa.inria.fr/sympa/info/cgal-discuss


Reply | Threaded
Open this post in threaded view
|

Re: Parallel make_mesh_3 does not have a speed-up

Chen Zhenghai
Hi Laurent,

Thanks for the fast reply. Attached are the input files.
On my PC, both sequential and parallel versions took around 20 mins to
complete and it seems that the parallel version did not take advantage of
multiple threads..... The output is shown as follows:

Number of points = 3236104
Number of subfaces = 41140187
Number of segments = 23809072
Number of tetrahedra = 20567218
Number of bad tetrahedra = 4514678
Total time = 1279.030000000 seconds
  edge_size = 5.000000
  facet_distance = 1.000000
  cell_radius_edge_ratio = 1.414000

I think the workload is big enough to exploit the possible concurrency.

Btw, I managed to speed up the program when using a single .off file as
input. Not sure if the type of domain would affect the parallelism or not.


bounding_box.off
<http://cgal-discuss.949826.n4.nabble.com/file/t376109/bounding_box.off>  
d2_s0_a0_p25000_t6250_e0.off
<http://cgal-discuss.949826.n4.nabble.com/file/t376109/d2_s0_a0_p25000_t6250_e0.off>  



--
Sent from: http://cgal-discuss.949826.n4.nabble.com/

--
You are currently subscribed to cgal-discuss.
To unsubscribe or access the archives, go to
https://sympa.inria.fr/sympa/info/cgal-discuss