Skip to content

Commit fe8a5bd

Browse files
raphael-s-steinerChristos Konstantinos Matzorospapp-pal-andras
authored
Sanitizers and fixes
* added sanitizers * Clean Eigen Iterator * bug in hillclimbing --------- Co-authored-by: Christos Konstantinos Matzoros <christos.konstantinos.matzoros@h-partners.com> Co-authored-by: papp-pal-andras <pal.andras.papp@huawei.com>
1 parent 780fcb9 commit fe8a5bd

4 files changed

Lines changed: 32 additions & 44 deletions

File tree

CMakeLists.txt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,22 @@ target_compile_options(ProjectExecutableFlags INTERFACE
118118
>
119119
)
120120

121+
# Flag for address sanitizer
122+
option(ENABLE_ASAN "Enable Address Sanitizer" OFF)
123+
if (ENABLE_ASAN)
124+
message(STATUS "Address sanitizer enabled.")
125+
target_compile_options(ProjectExecutableFlags INTERFACE -fsanitize=address)
126+
target_link_options(ProjectExecutableFlags INTERFACE -fsanitize=address)
127+
endif ()
128+
129+
# Flag for undefined behaviour sanitizer
130+
option(ENABLE_UBSAN "Enable Undefined Behaviour Sanitizer" OFF)
131+
if (ENABLE_UBSAN)
132+
message(STATUS "Undefined behaviour sanitizer enabled.")
133+
target_compile_options(ProjectExecutableFlags INTERFACE -fsanitize=undefined)
134+
target_link_options(ProjectExecutableFlags INTERFACE -fsanitize=undefined)
135+
endif ()
136+
121137
# --- Find External Libraries ---
122138
# Find COPT libraries
123139
find_package(COPT)

include/osp/bsp/scheduler/GreedySchedulers/CilkScheduler.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ class CilkScheduler : public Scheduler<GraphT> {
171171

172172
// Find new ready jobs
173173
while (!finishTimes.empty() && finishTimes.begin()->first == time) {
174-
const TvPair &currentPair = *finishTimes.begin();
174+
const TvPair currentPair = *finishTimes.begin();
175175
finishTimes.erase(finishTimes.begin());
176176
const VertexIdxT<GraphT> &node = currentPair.second;
177177
if (node != std::numeric_limits<VertexIdxT<GraphT>>::max()) {

include/osp/bsp/scheduler/LocalSearch/HillClimbing/hill_climbing.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,7 @@ void HillClimbingScheduler<GraphT>::AddMoveOption(const VertexIdx node, const un
579579
template <typename GraphT>
580580
void HillClimbingScheduler<GraphT>::EraseMoveOption(VertexIdx node, unsigned proc, Direction dir) {
581581
canMove_[dir][node][proc] = false;
582-
if (nextMove_.first == dir && nextMove_.second->first == node && nextMove_.second->second == proc) {
582+
if (nextMove_.first == dir && nextMove_.second != moveOptions_[dir].end() && nextMove_.second->first == node && nextMove_.second->second == proc) {
583583
++nextMove_.second;
584584
}
585585
moveOptions_[dir].erase(movePointer_[dir][node][proc]);

include/osp/graph_implementations/eigen_matrix_adapter/eigen_sparse_iterator.hpp

Lines changed: 14 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,6 @@ limitations under the License.
2020

2121
#ifdef EIGEN_FOUND
2222

23-
# include <Eigen/SparseCore>
24-
25-
# include "osp/concepts/graph_traits.hpp"
26-
2723
namespace osp {
2824

2925
template <typename Graph, typename EigenIdxType>
@@ -37,12 +33,10 @@ class EigenCSRRange {
3733

3834
class Iterator {
3935
Inner it_;
40-
EigenIdxType skip_;
41-
bool atEnd_;
4236

4337
void SkipDiagonal() {
44-
while (((!atEnd_) && (it_.row() == skip_)) & (it_.col() == skip_)) {
45-
++(*this);
38+
while (it_ && (it_.row() == it_.col())) {
39+
++it_;
4640
}
4741
}
4842

@@ -55,28 +49,19 @@ class EigenCSRRange {
5549

5650
Iterator() = default;
5751

58-
Iterator(const Iterator &other) : it_(other.it_), skip_(other.skip_), atEnd_(other.atEnd_) {}
52+
Iterator(const Iterator &other) : it_(other.it_) {}
5953

6054
Iterator &operator=(const Iterator &other) {
6155
it_ = other.it_;
62-
skip_ = other.skip_;
63-
atEnd_ = other.atEnd_;
6456
return *this;
6557
}
6658

67-
Iterator(const CSRMatrix &mat, EigenIdxType idx, bool end = false) : skip_(idx), atEnd_(end) {
68-
if (!end) {
69-
it_ = Inner(mat, idx);
70-
atEnd_ = !it_;
71-
SkipDiagonal();
72-
}
73-
}
59+
Iterator(const CSRMatrix &mat, EigenIdxType idx) : it_(mat, idx) { SkipDiagonal(); }
7460

7561
reference operator*() const { return static_cast<std::size_t>(it_.col()); }
7662

7763
Iterator &operator++() {
7864
++it_;
79-
atEnd_ = !it_;
8065
SkipDiagonal();
8166
return *this;
8267
}
@@ -87,16 +72,15 @@ class EigenCSRRange {
8772
return temp;
8873
}
8974

90-
bool operator==(const Iterator &) const { return atEnd_; }
91-
92-
bool operator!=(const Iterator &) const { return !atEnd_; }
75+
bool operator==(const Iterator &other) const {return it_ == other.it_;}
76+
bool operator!=(const Iterator &other) const { return it_ != other.it_;}
9377
};
9478

9579
EigenCSRRange(const Graph &graph, EigenIdxType idx) : graph_(graph), index_(idx) {}
9680

9781
Iterator begin() const { return Iterator(*graph_.GetCSR(), index_); }
9882

99-
Iterator end() const { return Iterator(*graph_.GetCSR(), index_, true); }
83+
Iterator end() const { return Iterator(); }
10084
};
10185

10286
template <typename Graph, typename EigenIdxType>
@@ -110,12 +94,10 @@ class EigenCSCRange {
11094

11195
class Iterator {
11296
Inner it_;
113-
EigenIdxType skip_;
114-
bool atEnd_;
11597

11698
void SkipDiagonal() {
117-
while ((!atEnd_) & (it_.row() == skip_) & (it_.col() == skip_)) {
118-
++(*this);
99+
while (it_ && (it_.row() == it_.col())) {
100+
++it_;
119101
}
120102
}
121103

@@ -128,28 +110,19 @@ class EigenCSCRange {
128110

129111
Iterator() = default;
130112

131-
Iterator(const Iterator &other) : it_(other.it_), skip_(other.skip_), atEnd_(other.atEnd_) {}
113+
Iterator(const Iterator &other) : it_(other.it_) {}
132114

133115
Iterator &operator=(const Iterator &other) {
134116
it_ = other.it_;
135-
skip_ = other.skip_;
136-
atEnd_ = other.atEnd_;
137117
return *this;
138118
}
139119

140-
Iterator(const CSCMatrix &mat, EigenIdxType idx, bool end = false) : skip_(idx), atEnd_(end) {
141-
if (!end) {
142-
it_ = Inner(mat, idx);
143-
atEnd_ = !it_;
144-
SkipDiagonal();
145-
}
146-
}
120+
Iterator(const CSCMatrix &mat, EigenIdxType idx) : it_(mat, idx) { SkipDiagonal(); }
147121

148122
reference operator*() const { return static_cast<std::size_t>(it_.row()); }
149123

150124
Iterator &operator++() {
151125
++it_;
152-
atEnd_ = !it_;
153126
SkipDiagonal();
154127
return *this;
155128
}
@@ -160,16 +133,15 @@ class EigenCSCRange {
160133
return temp;
161134
}
162135

163-
bool operator==(const Iterator &) const { return atEnd_; }
164-
165-
bool operator!=(const Iterator &) const { return !atEnd_; }
136+
bool operator==(const Iterator &other) const {return it_ == other.it_;}
137+
bool operator!=(const Iterator &other) const { return it_ != other.it_;}
166138
};
167139

168140
EigenCSCRange(const Graph &graph, EigenIdxType idx) : graph_(graph), index_(idx) {}
169141

170142
Iterator begin() const { return Iterator(*graph_.GetCSC(), index_); }
171143

172-
Iterator end() const { return Iterator(*graph_.GetCSC(), index_, true); }
144+
Iterator end() const { return Iterator(); }
173145
};
174146

175147
} // namespace osp

0 commit comments

Comments
 (0)