Repository navigation
Parallelize marching cubes: 5-pass core with num_threads - #54
Open
Harold2017 wants to merge 1 commit into
Open
Harold2017 wants to merge 1 commit into
Harold2017 wants to merge 1 commit into
Conversation
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.
Summary
The marching-cubes core is now a count-then-fill pipeline: one ordered sweep becomes
five passes that each run on the requested number of threads.
Parallelism follows from one ownership rule: a cube owns the three edges at its
minimum corner (edge 0, 3, 8), and one extra layer of "ghost" cubes past each upper
boundary owns the edges lying on that boundary. Every edge in the volume therefore
belongs to exactly one cube, so no pass needs a shared-index buffer, a fix-up, or a
boundary special case.
Evidence
Before:
pytest -q→ 20 passed.marching_cubes(sphere 256³)→ 310 ms.After:
pytest -q→ 27 passed,flake8 .clean.marching_cubes(sphere 256³, num_threads=4)→ 80 ms.The new core does not change the mesh it produces:
0for bool/integer,3.6e-15for floatOne thread is already faster than the old sweep everywhere (1.6–2.2×); the func
gain comes from one evaluation per node, not from threading, since the callbacks
hold the GIL.
Detailed performance comparison can be found in
PARALLEL.mdMerge Danger
Door: two-way — a single commit, no data or state migration;
git revert 63294d5restores the previous core.
Blast Radius: consumers — the geometry is unchanged but three observable
behaviours are not:
anything that assumed the old index order will see a diff.
mc::marching_cubesnow takesvalue_at(i, j, k)withnode indices, not coordinates, may call it from several threads, and
edge_table/triangle_table/num_indices_tableare nowconst. A hand-writtencallable keeps compiling but returns the wrong field. The Python API is unaffected.
mesh, allocated regardless of the thread count.