cgal icon indicating copy to clipboard operation
cgal copied to clipboard

CGAL slower than Mac(intel) on Mac(m1)

Open Dylanooo opened this issue 1 year ago • 5 comments

Shape detection is Very time consuming .

Issue Details

I tried to detect planes from a surface mesh(8,836,081 faces),But it is much slower than on my old Mac book(Intel). I suspect it has something to do with instruction set optimization. Other modules have similar problems.

Source Code

detect planes with region growth.

Environment

  • Operating system (Windows/Mac/Linux, 32/64 bits):Mac m1
  • Compiler: g++
  • Release or debug mode:Release
  • Specific flags used (if any):
  • CGAL version:5.4.1
  • Boost version:1.79.0
  • Other libraries versions if used (Eigen, TBB, etc.):

Dylanooo avatar Aug 09 '22 11:08 Dylanooo

Do you have a minimal example that we could try to run?

sloriot avatar Aug 09 '22 18:08 sloriot

Do you have a minimal example that we could try to run?

This is my example, you can download the PLY https://drive.google.com/file/d/1EOrS3GgU5R2zMXfRbPcUnf-XoWiQth1c/view?usp=sharing

#include <CGAL/Polyhedron_3.h>
#include <CGAL/Polygon_mesh_processing/border.h>
#include <CGAL/Polygon_mesh_processing/IO/polygon_mesh_io.h>
#include <CGAL/Polygon_mesh_processing/triangulate_faces.h>
#include <CGAL/Surface_mesh_simplification/edge_collapse.h>
#include <CGAL/Surface_mesh_simplification/Policies/Edge_collapse/Count_ratio_stop_predicate.h>
#include <CGAL/Surface_mesh.h>
#include <CGAL/Simple_cartesian.h>
#include <CGAL/draw_surface_mesh.h>

#include <boost/iterator/function_output_iterator.hpp>


typedef CGAL::Simple_cartesian<double>               Kernel;
typedef Kernel::Point_3                              Point_3;
typedef CGAL::Surface_mesh<Point_3>                  Mesh;

typedef boost::graph_traits<Mesh>::vertex_descriptor          vertex_descriptor;
typedef boost::graph_traits<Mesh>::halfedge_descriptor        halfedge_descriptor;
typedef boost::graph_traits<Mesh>::face_descriptor            face_descriptor;
typedef boost::graph_traits<Mesh>::edge_descriptor            edge_descriptor;

namespace SMS = CGAL::Surface_mesh_simplification;
namespace PMP = CGAL::Polygon_mesh_processing;

int simple_mesh()
{
    std::string filename = "test.ply";
    std::string output_name = "simp.ply";

    Mesh mesh;
    /*********** read mesh ************/
    if(!CGAL::IO::read_polygon_mesh(filename, mesh))
    {
        std::cerr << "Invalid input file." << std::endl;
        return EXIT_FAILURE;
    }

    bool mesh_simple = true;
    if (mesh_simple) {
        std::cout << "start mesh simple." << std::endl;
        int face_num = mesh.faces().size();
        int target_num = 100000;
        if (face_num > target_num) {
            double stop_ratio = target_num * 1.f / face_num;
              std::cout << "face_num : " << face_num << " stop_ratio:" << stop_ratio << std::endl;
            SMS::Count_ratio_stop_predicate<Mesh> stop(stop_ratio);
            int r = SMS::edge_collapse(mesh, stop);
            std::cout << "\nFinished!\n" << r << " edges removed.\n" << mesh.number_of_edges() << " final edges.\n";
        }

    }

    /*********** save result ************/
    CGAL::IO::write_polygon_mesh(output_name, mesh, CGAL::parameters::stream_precision(17));
    return EXIT_SUCCESS;
}

Dylanooo avatar Aug 11 '22 03:08 Dylanooo

Your original post speaks of region growing, but the code is surface mesh simplification. Do you observe the same slowdown for both these use cases?

How much slower is it?

MaelRL avatar Aug 16 '22 06:08 MaelRL

Your original post speaks of region growing, but the code is surface mesh simplification. Do you observe the same slowdown for both these use cases?

How much slower is it?

Yes, Both region growing and mesh simplification are slower,and the same thing happened on my colleague's computer.It takes a few minutes on Intel, but over an hour on M1.

Dylanooo avatar Aug 16 '22 06:08 Dylanooo

How exactly did you compile the program, with what commands and options? g++ is not very precise, the output of g++ -v (and g++ --version) would at least give some indication on which compiler it is. Are you sure it is compiled for arm64, not for x86_64 and then run through emulation? On a M1 running linux, this takes about 2 minutes, same as a PC. (your test doesn't have a main function, so it isn't a complete program. Also, a test that takes just a few seconds is more convenient for developers)

mglisse avatar Aug 18 '22 09:08 mglisse