Skip to content

Commit

Permalink
Add NETWORKIT_SANITY_CHECKS flag for further expensive checks
Browse files Browse the repository at this point in the history
  • Loading branch information
angriman committed Dec 9, 2020
1 parent 4d47e19 commit d93bc34
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 12 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/scripts/cpp_only.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
$CXX --version

mkdir debug_test && cd "$_"
cmake -GNinja -DNETWORKIT_BUILD_TESTS=ON -DNETWORKIT_MONOLITH=$MONOLITH -DNETWORKIT_CXX_STANDARD=$CXX_STANDARD -DNETWORKIT_WARNINGS=ON -DCMAKE_BUILD_TYPE=Debug ..
cmake -GNinja -DNETWORKIT_BUILD_TESTS=ON -DNETWORKIT_MONOLITH=$MONOLITH -DNETWORKIT_CXX_STANDARD=$CXX_STANDARD -DNETWORKIT_WARNINGS=ON -DCMAKE_BUILD_TYPE=Debug -DNETWORKIT_SANITY_CHECKS=ON..
ninja

ctest -V
ctest -V
8 changes: 8 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ option(NETWORKIT_WARNINGS_AS_ERRORS "Treat warnings as errors (except deprecated
option(NETWORKIT_CLANG_TIDY "Check code with clang-tidy" OFF)
option(NETWORKIT_FLATINSTALL "Install into a flat directory structure (useful when building a Python package)" OFF)
option(NETWORKIT_COVERAGE "Build with support for coverage" OFF)
option(NETWORKIT_SANITY_CHECKS "Algorithms will perform further (expensive) checks" OFF)
set(NETWORKIT_PYTHON "" CACHE STRING "Directory containing Python.h. Implies MONOLITH=TRUE")
set(NETWORKIT_PYTHON_SOABI "" CACHE STRING "Platform specific file extension. Implies MONOLITH=TRUE")
set(NETWORKIT_WITH_SANITIZERS "" CACHE STRING "Uses sanitizers during the compilation")
Expand Down Expand Up @@ -118,6 +119,13 @@ if (NETWORKIT_COVERAGE)
set(NETWORKIT_LINK_FLAGS "${NETWORKIT_LINK_FLAGS} --coverage")
endif()

################################################################################
# ENABLE ADDITIONAL SANITY CHECKS
if (NETWORKIT_SANITY_CHECKS)
set(NETWORKIT_CXX_FLAGS "${NETWORKIT_CXX_FLAGS} -DNETWORKIT_SANITY_CHECKS")
endif()


# finding or creating OpenMP target. This is likely to fail for CMake Version < 3.12.
find_package(OpenMP)

Expand Down
4 changes: 2 additions & 2 deletions include/networkit/centrality/ApproxElectricalCloseness.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,13 +144,13 @@ class ApproxElectricalCloseness final : public Centrality {

count computeNumberOfUSTs() const;

#ifndef NDEBUG
#ifdef NETWORKIT_SANITY_CHECKS
// Debugging methods
void checkBFSTree() const;
void checkUST() const;
void checkTwoNodesSequence(const std::vector<node> &sequence) const;
void checkTimeStamps() const;
#endif // NDEBUG
#endif // NETWORKIT_SANITY_CHECKS
};

} // namespace NetworKit
Expand Down
16 changes: 8 additions & 8 deletions networkit/cpp/centrality/ApproxElectricalCloseness.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ void ApproxElectricalCloseness::computeNodeSequence() {
biAnchor.resize(bcc.numberOfComponents(), none);
biParent.resize(bcc.numberOfComponents(), none);

#ifndef NDEBUG
#ifdef NETWORKIT_SANITY_CHECKS
G.forNodes([&](node u) { assert(status[u] == NodeStatus::NOT_VISITED); });
#endif

Expand Down Expand Up @@ -218,7 +218,7 @@ void ApproxElectricalCloseness::computeNodeSequence() {
});
} while (!q.empty());

#ifndef NDEBUG
#ifdef NETWORKIT_SANITY_CHECKS
G.forNodes([&](node u) { assert(status[u] == NodeStatus::VISITED); });
assert(topOrder.size() == bcc.numberOfComponents());
assert(std::unordered_set<index>(topOrder.begin(), topOrder.end()).size()
Expand Down Expand Up @@ -247,7 +247,7 @@ void ApproxElectricalCloseness::computeBFSTree() {
});
} while (!queue.empty());

#ifndef NDEBUG
#ifdef NETWORKIT_SANITY_CHECKS
checkBFSTree();
#endif
}
Expand Down Expand Up @@ -300,7 +300,7 @@ void ApproxElectricalCloseness::sampleUST() {
if (parent[curAnchor] == none)
updateParentOfAnchor();
}
#ifndef NDEBUG
#ifdef NETWORKIT_SANITY_CHECKS
checkTwoNodesSequence(sequence);
#endif
continue;
Expand Down Expand Up @@ -404,7 +404,7 @@ void ApproxElectricalCloseness::sampleUST() {
break;
}

#ifndef NDEBUG
#ifdef NETWORKIT_SANITY_CHECKS
checkUST();
#endif
}
Expand Down Expand Up @@ -437,7 +437,7 @@ void ApproxElectricalCloseness::dfsUST() {
}

void ApproxElectricalCloseness::aggregateUST() {
#ifndef NDEBUG
#ifdef NETWORKIT_SANITY_CHECKS
checkTimeStamps();
#endif

Expand Down Expand Up @@ -594,7 +594,7 @@ std::vector<double> ApproxElectricalCloseness::computeExactDiagonal(double tol)
return diag;
}

#ifndef NDEBUG
#ifdef NETWORKIT_SANITY_CHECKS
/*
* Methods for sanity check.
*/
Expand Down Expand Up @@ -664,6 +664,6 @@ void ApproxElectricalCloseness::checkTimeStamps() const {
});
}

#endif // NDEBUG
#endif // NETWORKIT_SANITY_CHECKS

} // namespace NetworKit

0 comments on commit d93bc34

Please sign in to comment.