Repository navigation
Let callers cap KD-tree threads (workers= keyword and SURFA_NUM_THREADS) - #90
Merged
Merged
Conversation
All KD-tree queries in surfa.mesh hard-code workers=-1, which makes SciPy spawn one thread per CPU reported by the OS. On cgroup-limited batch jobs (e.g. SLURM allocations of 1-2 cores on large nodes) this oversubscribes the allocation and there is no way for the caller to cap it. Add surfa.system.kdtree_workers(), which returns -1 by default (unchanged behaviour) or the value of the optional SURFA_NUM_THREADS environment variable (-1 or a positive integer; anything else raises ValueError), and use it at every KD-tree query site: - Mesh.nearest_vertex - Mesh.find_self_intersecting_faces / remove_self_intersections - sphere.barycentric_spherical_map (spherical resampling) - mesh.surface_distance Adds test/test_kdtree_workers.py (parsing, validation, and identical results with and without the cap). Originally committed in the inhuszar/surfa fork as part of 8ef40a9 ("Bugfix: thread limit, overlay accumulation"), which covered only the three call sites in mesh.py; this version extends the cap to the spherical-resampling and surface-distance queries so the limit holds process-wide. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> (cherry picked from commit b0b50f1)
…READS A per-call keyword makes the thread cap visible and testable in calling code, while the environment variable keeps capping batch jobs without code changes. The keyword takes precedence; when it is None (the default) the variable decides, and all CPUs are used when neither is given, as before. kdtree_workers(workers=None) validates an explicit value (-1 or a positive integer) and otherwise reads SURFA_NUM_THREADS. The keyword is added to Mesh.nearest_vertex, Mesh.find_self_intersecting_faces, Mesh.remove_self_intersections, surface_distance, barycentric_spherical_map, SphericalResamplingNearest, SphericalResamplingBarycentric, SphericalMapNearest and SphericalMapBarycentric. Tests: explicit values, precedence over the variable, invalid values, and every public entry point with the keyword (an invalid variable proves the keyword is used), giving the same results as the default. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Nh3ictregns29GiD8fnqCm
The resampling and map classes require a sphere centred at the origin; the random point cloud of the previous test was not, so it stopped at the first resampling class. Use Fibonacci spheres pinned by the six axis points. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Nh3ictregns29GiD8fnqCm
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Every KD-tree query used
workers=-1, which oversubscribes cgroup-limited batch jobs (e.g. SLURM) with noway for the caller to cap it. Each public entry point that queries a KD-tree (
Mesh.nearest_vertex,find_self_intersecting_faces,remove_self_intersections,surface_distance,barycentric_spherical_map, and the four spherical resampling and map classes) now takesworkers=, asSciPy does. When it is not given, the optional
SURFA_NUM_THREADSenvironment variable decides, so a batchscript can cap everything without code changes; with neither, all CPUs are used as before. Tests cover the
precedence, validation and every entry point.