Skip to content

Commit

Permalink
#37 Made get_mappings sequential, as it's faster that way.
Browse files Browse the repository at this point in the history
  • Loading branch information
carljohnsen committed Aug 7, 2024
1 parent ed415e1 commit 018b50b
Showing 1 changed file with 4 additions and 32 deletions.
36 changes: 4 additions & 32 deletions src/lib/cpp/cpu/connected_components.cc
Original file line number Diff line number Diff line change
Expand Up @@ -739,42 +739,14 @@ void filter_largest(const std::string &base_path, bool *__restrict__ mask, const
}

std::tuple<mapping_t, mapping_t> get_mappings(const std::vector<int64_t> &a, const int64_t n_labels_a, const std::vector<int64_t> &b, const int64_t n_labels_b, const idx3d &global_shape) {
std::vector<mapping_t> mappings_a;
std::vector<mapping_t> mappings_b;

mapping_t mapping_a(n_labels_a+1);
mapping_t mapping_b(n_labels_b+1);

#pragma omp parallel num_threads(8)
{
int64_t n_threads = omp_get_num_threads();

#pragma omp single
{
mappings_a.resize(n_threads, mapping_t(n_labels_a+1));
mappings_b.resize(n_threads, mapping_t(n_labels_b+1));
}

#pragma omp for schedule(static) collapse(2)
for (int64_t y = 0; y < global_shape.y; y++) {
for (int64_t x = 0; x < global_shape.x; x++) {
int64_t i = (y * global_shape.x) + x;
const int64_t plane_size = global_shape.y * global_shape.x;
for (int64_t i = 0; i < plane_size; i++) {
if (a[i] != 0 && b[i] != 0) {
mappings_a[omp_get_thread_num()][a[i]].insert(b[i]);
mappings_b[omp_get_thread_num()][b[i]].insert(a[i]);
}
}
}

for (int64_t i = 0; i < n_threads; i++) {
#pragma omp for schedule(static)
for (int64_t j = 1; j < n_labels_a+1; j++) {
mapping_a[j].insert(mappings_a[i][j].begin(), mappings_a[i][j].end());
}
#pragma omp for schedule(static)
for (int64_t j = 1; j < n_labels_b+1; j++) {
mapping_b[j].insert(mappings_b[i][j].begin(), mappings_b[i][j].end());
}
mapping_a[a[i]].insert(b[i]);
mapping_b[b[i]].insert(a[i]);
}
}

Expand Down

0 comments on commit 018b50b

Please sign in to comment.