Skip to content

Commit

Permalink
Parallel run_on_all in attribute transfer.
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-zint committed Nov 6, 2024
1 parent 49f1593 commit c593156
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "AttributeTransferStrategyBase.hpp"
#include <wmtk/Mesh.hpp>
#include <wmtk/simplex/neighbors_single_dimension.hpp>
#include <wmtk/utils/tbb_parallel_for.hpp>

#include <wmtk/simplex/utils/unique_homogeneous_simplices.hpp>

Expand All @@ -16,13 +17,23 @@ const Mesh& AttributeTransferStrategyBase::mesh() const
return const_cast<const Mesh&>(const_cast<AttributeTransferStrategyBase*>(this)->mesh());
}

void AttributeTransferStrategyBase::run_on_all() const
void AttributeTransferStrategyBase::run_on_all(bool parallel) const
{
const PrimitiveType pt = m_handle.primitive_type();
auto tuples = m_handle.mesh().get_all(pt);

for (const Tuple& t : tuples) {
run(simplex::Simplex(m_handle.mesh(), pt, t));
if (parallel) {
tbb::parallel_for(
tbb::blocked_range<int64_t>(0, tuples.size()),
[&](tbb::blocked_range<int64_t> r) {

Check warning on line 28 in src/wmtk/operations/attribute_update/AttributeTransferStrategyBase.cpp

View check run for this annotation

Codecov / codecov/patch

src/wmtk/operations/attribute_update/AttributeTransferStrategyBase.cpp#L26-L28

Added lines #L26 - L28 were not covered by tests
for (int64_t k = r.begin(); k < r.end(); ++k) {
run(simplex::Simplex(m_handle.mesh(), pt, tuples[k]));

Check warning on line 30 in src/wmtk/operations/attribute_update/AttributeTransferStrategyBase.cpp

View check run for this annotation

Codecov / codecov/patch

src/wmtk/operations/attribute_update/AttributeTransferStrategyBase.cpp#L30

Added line #L30 was not covered by tests
}
});

Check warning on line 32 in src/wmtk/operations/attribute_update/AttributeTransferStrategyBase.cpp

View check run for this annotation

Codecov / codecov/patch

src/wmtk/operations/attribute_update/AttributeTransferStrategyBase.cpp#L32

Added line #L32 was not covered by tests
} else {
for (const Tuple& t : tuples) {
run(simplex::Simplex(m_handle.mesh(), pt, t));
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class AttributeTransferStrategyBase : public AttributeTransferEdge

// runs the transfer on every simplex - good for initializing an attribute that will be
// managed by transfer
void run_on_all() const;
void run_on_all(bool parallel = false) const;

private:
attribute::MeshAttributeHandle m_handle;
Expand Down

0 comments on commit c593156

Please sign in to comment.