Skip to content

Commit

Permalink
Additions to the parallel algorithms.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jhuighuy committed Feb 16, 2025
1 parent 919a5d4 commit a57cb7c
Show file tree
Hide file tree
Showing 11 changed files with 505 additions and 171 deletions.
1 change: 1 addition & 0 deletions source/tit/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ add_tit_library(
"par/control.cpp"
"par/control.hpp"
"par/memory_pool.hpp"
"par/partitioner.hpp"
"par/task_group.hpp"
"profiler.cpp"
"profiler.hpp"
Expand Down
15 changes: 9 additions & 6 deletions source/tit/core/containers/multivector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,17 +166,20 @@ class Multivector {
constexpr void assign_pairs_par_wide(size_t count, Pairs&& pairs) {
TIT_ASSUME_UNIVERSAL(Pairs, pairs);
assign_pairs_wide_impl_(count, [&pairs](auto func) {
par::static_for_each(pairs, std::move(func));
par::deterministic_for_each(pairs, std::move(func));
});
}
template<par::range Range>
constexpr void assign_pairs_par_wide(size_t count,
std::ranges::join_view<Range> pairs) {
auto base = std::move(pairs).base();
assign_pairs_wide_impl_(count, [&base](auto func) {
par::static_for_each(base, [&func](size_t thread, const auto& range) {
std::ranges::for_each(range, std::bind_front(std::ref(func), thread));
});
par::deterministic_for_each(base,
[&func](const auto& range, size_t thread) {

Check warning on line 178 in source/tit/core/containers/multivector.hpp

View check run for this annotation

Codecov / codecov/patch

source/tit/core/containers/multivector.hpp#L177-L178

Added lines #L177 - L178 were not covered by tests
std::ranges::for_each(
range,
std::bind_back(std::ref(func), thread));

Check warning on line 181 in source/tit/core/containers/multivector.hpp

View check run for this annotation

Codecov / codecov/patch

source/tit/core/containers/multivector.hpp#L181

Added line #L181 was not covered by tests
});
});
}
/// @}
Expand Down Expand Up @@ -223,7 +226,7 @@ class Multivector {
static Mdvector<size_t, 2> per_thread_ranges{};
const auto num_threads = par::num_threads();
per_thread_ranges.assign(num_threads, count + 1);
for_each_pair([count](size_t thread, const auto& pair) {
for_each_pair([count](const auto& pair, size_t thread) {
const auto index = std::get<0>(pair);
TIT_ASSERT(index < count, "Index of the value is out of expected range!");
per_thread_ranges[thread, index] += 1;
Expand All @@ -242,7 +245,7 @@ class Multivector {
// Place each value into position of the first element of it's index
// range, then increment the position.
vals_.resize(val_ranges_.back());
for_each_pair([count, this](size_t thread, const auto& pair) {
for_each_pair([count, this](const auto& pair, size_t thread) {
const auto& [index, value] = pair;
TIT_ASSERT(index < count, "Index of the value is out of expected range!");
auto& position = per_thread_ranges[thread, index];
Expand Down
Loading

0 comments on commit a57cb7c

Please sign in to comment.