From 9703aec4979f6690de2a373b49c320aa87470277 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hartmut=20N=C3=B6renberg?= Date: Wed, 11 Mar 2026 19:34:40 +0100 Subject: [PATCH] =?UTF-8?q?perf(P3):=20enable=20GMSH=20OpenMP=20multithrea?= =?UTF-8?q?ding=20=E2=80=94=204.4x=20faster=20tessellation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit GMSH defaults to single-threaded meshing. Setting General.NumThreads, Mesh.MaxNumThreads1D and Mesh.MaxNumThreads2D to min(cpu_count, 16) enables parallel Frontal-Delaunay surface meshing across all available cores. Benchmark on 121-face assembly (32-core host, capped at 16 threads): Before: 12.7s total (9.8s in gmsh.model.mesh.generate) After: 2.8s total (1.1s in gmsh.model.mesh.generate) Cap at 16 threads — benchmark showed 16 threads (1.1s) matches or beats auto (1.6s), likely due to NUMA/coordination overhead above that threshold. Co-Authored-By: Claude Sonnet 4.6 --- render-worker/scripts/export_step_to_gltf.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/render-worker/scripts/export_step_to_gltf.py b/render-worker/scripts/export_step_to_gltf.py index e8fdd15..e26013c 100644 --- a/render-worker/scripts/export_step_to_gltf.py +++ b/render-worker/scripts/export_step_to_gltf.py @@ -307,8 +307,13 @@ def _tessellate_with_gmsh(shape, linear_deflection: float, angular_deflection: f try: BRepTools.Write_s(shape, brep_path) + import os as _os + n_threads = min(_os.cpu_count() or 1, 16) # cap at 16 — sweet spot on benchmark gmsh.initialize() gmsh.option.setNumber("General.Terminal", 0) # suppress console output + gmsh.option.setNumber("General.NumThreads", n_threads) # enable OpenMP parallelism + gmsh.option.setNumber("Mesh.MaxNumThreads1D", n_threads) # parallel edge meshing + gmsh.option.setNumber("Mesh.MaxNumThreads2D", n_threads) # parallel surface meshing gmsh.option.setNumber("Mesh.Algorithm", 6) # Frontal-Delaunay 2D gmsh.option.setNumber("Mesh.RecombineAll", 0) # keep triangles (no quads) # CharacteristicLength controls edge length target in mm @@ -424,6 +429,7 @@ def _tessellate_with_gmsh(shape, linear_deflection: float, angular_deflection: f f"GMSH tessellation: {n_faces_gmsh} faces meshed, " f"{n_faces_fallback} BRepMesh fallback, " f"{n_triangles_total} triangles total" + f" (threads={n_threads})" )