8000 parallel CreateHalfedges by pca006132 · Pull Request #1188 · elalish/manifold · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

parallel CreateHalfedges #1188

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 13, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 29 additions & 2 deletions src/impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ void Manifold::Impl::CreateHalfedges(const Vec<ivec3>& triVerts) {
// Mark opposed triangles for removal - this may strand unreferenced verts
// which are removed later by RemoveUnreferencedVerts() and Finish().
const int numEdge = numHalfedge / 2;
for (int i = 0; i < numEdge; ++i) {
const auto body = [&](int i, int segmentEnd) {
const int pair0 = ids[i];
Halfedge h0 = halfedge_[pair0];
int k = i + numEdge;
Expand All @@ -362,9 +362,36 @@ void Manifold::Impl::CreateHalfedges(const Vec<ivec3>& triVerts) {
break;
}
++k;
if (k >= numHalfedge) break;
if (k >= segmentEnd + numEdge) break;
}
};

#if MANIFOLD_PAR == 1
Vec<std::pair<int, int>> ranges;
const int increment = std::min(
std::max(numEdge / tbb::this_task_arena::max_concurrency() / 2, 1024),
numEdge);
const auto duplicated = [&](int a, int b) {
const Halfedge& h0 = halfedge_[ids[a]];
const Halfedge& h1 = halfedge_[ids[b]];
return h0.startVert == h1.startVert && h0.endVert == h1.endVert;
};
int end = 0;
while (end < numEdge) {
const int start = end;
end = std::min(end + increment, numEdge);
// make sure duplicated halfedges are in the same partition
while (end < numEdge && duplicated(end - 1, end)) end++;
ranges.push_back(std::make_pair(start, end));
}
for_each(ExecutionPolicy::Par, ranges.begin(), ranges.end(),
[&](const std::pair<int, int>& range) {
const auto [start, end] = range;
for (int i = start; i < end; ++i) body(i, end);
});
#else
for (int i = 0; i < numEdge; ++i) body(i, numEdge);
#endif

// Once sorted, the first half of the range is the forward halfedges, which
// correspond to their backward pair at the same offset in the second half
Expand Down
0