Skip to content

Commit

Permalink
clarify sortedness in MST algorithm
Browse files Browse the repository at this point in the history
  • Loading branch information
upsj committed Jan 15, 2025
1 parent 8656cdf commit aca0fdc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
8 changes: 5 additions & 3 deletions omp/factorization/elimination_forest_kernels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,12 @@ void compute_skeleton_tree(std::shared_ptr<const DefaultExecutor> exec,
edges.emplace_back(row, col);
}
}
// sort edge list ascending by edge weight
std::sort(edges.begin(), edges.end());
// the edge list is now sorted by row, which also matches the edge weight
// we don't need to do any additional sorting operations
assert(std::is_sorted(edges.begin(), edges.end(),
[](auto a, auto b) { return a.first < b.first; }));
// output helper array: Store row indices for output rows
// since we sorted by edge.first == row, this will be sorted
// since the input is sorted by edge.first == row, this will be sorted
vector<IndexType> out_rows(size, exec);
IndexType output_count{};
// Kruskal algorithm: Connect unconnected components using edges with
Expand Down
8 changes: 5 additions & 3 deletions reference/factorization/elimination_forest_kernels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,12 @@ void compute_skeleton_tree(std::shared_ptr<const DefaultExecutor> exec,
edges.emplace_back(row, col);
}
}
// sort edge list ascending by edge weight
std::sort(edges.begin(), edges.end());
// the edge list is now sorted by row, which also matches the edge weight
// we don't need to do any additional sorting operations
assert(std::is_sorted(edges.begin(), edges.end(),
[](auto a, auto b) { return a.first < b.first; }));
// output helper array: Store row indices for output rows
// since we sorted by edge.first == row, this will be sorted
// since the input is sorted by edge.first == row, this will be sorted
vector<IndexType> out_rows(size, exec);
IndexType output_count{};
// Kruskal algorithm: Connect unconnected components using edges with
Expand Down

0 comments on commit aca0fdc

Please sign in to comment.