cgal icon indicating copy to clipboard operation
cgal copied to clipboard

Try to add Scotch library as a fallback instead of METIS in mesh partition

Open sloriot opened this issue 1 month ago • 12 comments

METIS is used for mesh partition in CGAL::METIS::partition_graph() and CGAL::METIS::partition_dual_graph().

I would be interesting to add variant using the scotch library to compare it against METIS.

sloriot avatar Oct 21 '26 16:10 sloriot

Hello @sloriot, I am interested in contributing to CGAL & would like to work on this issue. Is anyone currently working on it, or can I take it up?

vedpanvar avatar Oct 29 '26 09:10 vedpanvar

Hi @sloriot,

I would like to help implement the Scotch fallback for mesh partitioning.

Looking at how METIS is integrated in BGL/include/CGAL/boost/graph/METIS/ and Installation/cmake/modules/FindMETIS.cmake, my proposed approach would be:

  1. Add Installation/cmake/modules/FindScotch.cmake to detect Scotch headers (scotch.h) and libscotch.
  2. Implement partition_graph() and partition_dual_graph() under BGL/include/CGAL/boost/graph/Scotch/, converting CGAL graph / dual graph adjacency into Scotch's CSR format (SCOTCH_graphBuild / SCOTCH_graphPart).
  3. Add a benchmark / comparison test referencing BGL/examples/BGL_surface_mesh/surface_mesh_partition.cpp to compare partition quality (edge cut) and runtime between METIS and Scotch.

Does this alignment look good to you, or do you have any specific preferences regarding the CMake configuration or API structure? If this is good, I can get started on this.

Ayush-CS-89112521 avatar Oct 30 '26 12:10 Ayush-CS-89112521

There is no need for a FindScotch.cmake but CGAL_Scotch_support.cmake. I think it does support cmake config mode.

About the code, I think I read that there is in Scotch a METIS compatibility API. So it should be rather easy using that API to get a first prototype.

@Ayush-CS-89112521 @vedpanvar You might want to coordinate to work together if you are interested in playing with this issue.

sloriot avatar Oct 30 '26 12:10 sloriot

Thanks for the pointers @sloriot, using CGAL_Scotch_support.cmake and Scotch's METIS compatibility API makes complete sense.

@vedpanvar Happy to coordinate and work together on this! How would you like to split it up?

Ayush-CS-89112521 avatar Oct 30 '26 14:10 Ayush-CS-89112521

Hi @Ayush-CS-89112521,

Happy to collaborate on this! Since @sloriot suggested using Scotch's METIS compatibility API, I think we can split the work as follows :) I can investigate the METIS compatibility API, build a small prototype, and test whether Scotch works with CGAL's existing mesh partitioning functions. And You could handle the CMake integration using CGAL_Scotch_support.cmake and the required linking configuration.

Once we both get done, we will integrate the changes and run the necessary tests for this issue.

& We can coordinate on a shared branch and submit a single PR with both contributions.

does this approach sounds good to you.!?

vedpanvar avatar Oct 30 '26 20:10 vedpanvar

Hi @vedpanvar,

Sounds good to me! A joint PR is a great idea.

I am working on the CGAL_Scotch_support.cmake integration locally. You can go ahead with the prototype, and we can test and combine our changes together once you're ready!

Ayush-CS-89112521 avatar Oct 30 '26 21:10 Ayush-CS-89112521

Quick update: I've pushed the initial CGAL_Scotch_support.cmake integration to my branch here: https://github.com/Ayush-CS-89112521/cgal/tree/scotch-cmake-support

@vedpanvar feel free to fetch it and build your prototype against it. Once ready, we can test and integrate everything together based on maintainer feedback!

Ayush-CS-89112521 avatar Oct 31 '26 20:10 Ayush-CS-89112521

hey @Ayush-CS-89112521 i have tested the Scotch compatibility path locally on MSYS2 UCRT64 using Scotch 7.0.12. I successfully compiled and ran a minimal test that calls CGAL's actual partition_dual_graph() implementation on a two-triangle Surface_mesh. It linked against Scotch's METIS compatibility library and exited with code 0.

One important finding: Scotch's compatibility metis.h exposes METIS_PartMeshDual and METIS_SetDefaultOptions, but does not declare METIS_PartMeshNodal, which CGAL uses in partition_graph(). I haven't tested the CMake fallback yet and My next step is to verify your CGAL_Scotch_support.cmake module and try building the actual surface mesh partitioning example with METIS unavailable and Scotch installed. This will help us to identify whether the current implementation is sufficient or not.!

vedpanvar avatar Nov 01 '26 06:11 vedpanvar

8. Quick update: I've pushed the initial CGAL_Scotch_support.cmake integration to my branch here: https://github.com/Ayush-CS-89112521/cgal/tree/scotch-cmake-support @vedpanvar feel free to fetch it and build your prototype against it. Once ready, we can test and integrate everything together based on maintainer feedback!

Looks good. Some comment: If Scotch supports config mode of cmake, then we don't need to have the else() part.

sloriot avatar Nov 01 '26 07:11 sloriot

Thanks @sloriot and @vedpanvar for testing and feedback!

Regarding CMake Config Mode (@sloriot): Scotch 7+ (MSYS2, vcpkg, and upstream CMake) provides ScotchConfig.cmake. The else() block was added because standard Debian/Ubuntu packages (libscotch-dev) still build without CMake configs. If CGAL prefers strictly config-driven modules, I'm happy to drop the else() block (or move it to a FindScotch.cmake if distro packages are desired). Please let me know your preferred direction.

Regarding METIS_PartMeshNodal & Example (@vedpanvar): Scotch's compatibility layer implements METIS_PartMeshDual, but not METIS_PartMeshNodal.

  • CGAL::METIS::partition_dual_graph() powers the surface_mesh_partition example. I've tested building and running this example with METIS disabled and Scotch enabled locally, and it runs and partitions cleanly.
  • For partition_graph(), I've added a compile-time static_assert so users get an informative diagnostic instead of an undefined symbol link error.

Ayush-CS-89112521 avatar Nov 01 '26 09:11 Ayush-CS-89112521

I do see it libscotch-dev_7.0.17-2_amd64.deb for sid but not for the version in stable so it indeed makes sense.

sloriot avatar Nov 01 '26 12:11 sloriot

Hey @Ayush-CS-89112521 i have completed and pushed my Scotch compatibility changes to my fork. Branch: scotch-cpp-prototype https://github.com/vedpanvar/cgal/tree/scotch-cpp-prototype The changes include:

  • Explicit Scotch header inclusion and removal of forced include.
  • A clear compile-time diagnostic for partition_graph() because Scotch doesn't provide METIS_PartMeshNodal().
  • Validation using Scotch 7.0.12, including the actual partition_dual_graph() example.

I've committed and pushed everything. Let's coordinate on integrating this with your scotch-cmake-support branch and prepare our joint PR!

vedpanvar avatar Nov 01 '26 16:11 vedpanvar