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

remove deterministic flag #1033

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 1 commit into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
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
2 changes: 0 additions & 2 deletions include/manifold/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -596,8 +596,6 @@ struct ExecutionParams {
/// Suppresses printed errors regarding CW triangles. Has no effect if
/// processOverlaps is true.
bool suppressErrors = false;
/// Deterministic outputs. Will disable some parallel optimizations.
bool deterministic = false;
/// Perform optional but recommended triangle cleanups in SimplifyTopology()
bool cleanupTriangles = true;
};
Expand Down
6 changes: 2 additions & 4 deletions src/boolean_result.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ void AddNewEdgeVerts(
#if (MANIFOLD_PAR == 1) && __has_include(<tbb/tbb.h>)
// parallelize operations, requires concurrent_map so we can only enable this
// with tbb
if (!ManifoldParams().deterministic && p1q2.size() > kParallelThreshold) {
if (p1q2.size() > kParallelThreshold) {
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pca006132 Actually, switching this to serial had the smallest performance impact of anything, but for now I'm going with the determinism == false path for everything.

// ideally we should have 1 mutex per key, but kParallelThreshold is enough
// to avoid contention for most of the cases
std::array<std::mutex, kParallelThreshold> mutexes;
Expand Down Expand Up @@ -486,9 +486,7 @@ void AppendWholeEdges(Manifold::Impl &outR, Vec<int> &facePtrR,
bool forward) {
ZoneScoped;
for_each_n(
ManifoldParams().deterministic ? ExecutionPolicy::Seq
: autoPolicy(inP.halfedge_.size()),
countAt(0), inP.halfedge_.size(),
autoPolicy(inP.halfedge_.size()), countAt(0), inP.halfedge_.size(),
DuplicateHalfedges({outR.halfedge_, halfedgeRef, facePtrR, wholeHalfedgeP,
inP.halfedge_, i03, vP2R, faceP2R, forward}));
}
Expand Down
59 changes: 27 additions & 32 deletions src/csg_tree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -468,35 +468,32 @@ std::shared_ptr<Manifold::Impl> CsgOpNode::BatchBoolean(
return std::make_shared<Manifold::Impl>(boolean.Result(operation));
}
#if (MANIFOLD_PAR == 1) && __has_include(<tbb/tbb.h>)
if (!ManifoldParams().deterministic) {
tbb::task_group group;
tbb::concurrent_priority_queue<SharedImpl, MeshCompare> queue(
results.size());
for (auto result : results) {
queue.emplace(result);
}
results.clear();
std::function<void()> process = [&]() {
while (queue.size() > 1) {
SharedImpl a, b;
if (!queue.try_pop(a)) continue;
if (!queue.try_pop(b)) {
queue.push(a);
continue;
}
group.run([&, a, b]() {
Boolean3 boolean(*getImplPtr(a), *getImplPtr(b), operation);
queue.emplace(
std::make_shared<Manifold::Impl>(boolean.Result(operation)));
return group.run(process);
});
}
};
group.run_and_wait(process);
SharedImpl r;
queue.try_pop(r);
return *std::get_if<std::shared_ptr<Manifold::Impl>>(&r);
tbb::task_group group;
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one had a noticeable perf impact when removed, but not huge.

tbb::concurrent_priority_queue<SharedImpl, MeshCompare> queue(results.size());
for (auto result : results) {
queue.emplace(result);
}
results.clear();
std::function<void()> process = [&]() {
while (queue.size() > 1) {
SharedImpl a, b;
if (!queue.try_pop(a)) continue;
if (!queue.try_pop(b)) {
queue.push(a);
continue;
}
group.run([&, a, b]() {
Boolean3 boolean(*getImplPtr(a), *getImplPtr(b), operation);
queue.emplace(
std::make_shared<Manifold::Impl>(boolean.Result(operation)));
return group.run(process);
});
}
};
group.run_and_wait(process);
SharedImpl r;
queue.try_pop(r);
return *std::get_if<std::shared_ptr<Manifold::Impl>>(&r);
#endif
// apply boolean operations starting from smaller meshes
// the assumption is that boolean operations on smaller meshes is faster,
Expand Down Expand Up @@ -604,10 +601,8 @@ std::vector<std::shared_ptr<CsgNode>> &CsgOpNode::GetChildren(

if (forceToLeafNodes && !impl->forcedToLeafNodes_) {
impl->forcedToLeafNodes_ = true;
for_each(impl->children_.size() > 1 && !ManifoldParams().deterministic
? ExecutionPolicy::Par
: ExecutionPolicy::Seq,
impl->children_.begin(), impl->children_.end(), [](auto &child) {
for_each(ExecutionPolicy::Par, impl->children_.begin(),
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changing this to Seq caused about 75% of the performance regression I was seeing. Even just the impl->children_.size() > 1 check was causing noticeable perf regression.

impl->children_.end(), [](auto &child) {
if (child->GetNodeType() != CsgNodeType::Leaf) {
child = child->ToLeafNode();
}
Expand Down
Loading
0