Skip to content

Commit

Permalink
replace ERROR macro with exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
kittobi1992 committed Aug 11, 2023
1 parent b65c042 commit aa73caa
Show file tree
Hide file tree
Showing 34 changed files with 339 additions and 121 deletions.
5 changes: 3 additions & 2 deletions mt-kahypar/application/mt_kahypar.cc.in
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include "mt-kahypar/utils/delete.h"
#include "mt-kahypar/utils/randomize.h"
#include "mt-kahypar/utils/utilities.h"
#include "mt-kahypar/utils/exception.h"

using namespace mt_kahypar;

Expand Down Expand Up @@ -67,7 +68,7 @@ int main(int argc, char* argv[]) {
context.partition.preset_file = getPresetFile(context);
processCommandLineInput(context, argc, argv);
} else {
ERR("No preset specified");
throw InvalidInputException("No preset specified");
}
}

Expand Down Expand Up @@ -125,7 +126,7 @@ int main(int argc, char* argv[]) {
io::readInputFile<ds::StaticGraph>(
context.mapping.target_graph_file, FileFormat::Metis, true));
} else {
ERR("No target graph file specified (use -g <file> or --target-graph-file=<file>)!");
throw InvalidInputException("No target graph file specified (use -g <file> or --target-graph-file=<file>)!");
}
}

Expand Down
3 changes: 2 additions & 1 deletion mt-kahypar/datastructures/array.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include "mt-kahypar/macros.h"
#include "mt-kahypar/parallel/memory_pool.h"
#include "mt-kahypar/parallel/stl/scalable_unique_ptr.h"
#include "mt-kahypar/utils/exception.h"

namespace mt_kahypar {
namespace ds {
Expand Down Expand Up @@ -293,7 +294,7 @@ class Array {
const value_type init_value = value_type(),
const bool assign_parallel = true) {
if ( _data || _underlying_data ) {
ERR("Memory of vector already allocated");
throw SystemException("Memory of vector already allocated");
}
allocate_data(size);
assign(size, init_value, assign_parallel);
Expand Down
7 changes: 4 additions & 3 deletions mt-kahypar/datastructures/delta_partitioned_graph.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include "mt-kahypar/datastructures/connectivity_set.h"
#include "mt-kahypar/parallel/stl/scalable_vector.h"
#include "mt-kahypar/partition/context.h"
#include "mt-kahypar/utils/exception.h"

namespace mt_kahypar {
namespace ds {
Expand Down Expand Up @@ -265,19 +266,19 @@ class DeltaPartitionedGraph {

// ! Returns an iterator over the connectivity set of hyperedge he (not supported)
IteratorRange<ConnectivitySetIterator> connectivitySet(const HyperedgeID e) const {
ERR("Not supported for graphs");
throw NonSupportedOperationException("Not supported for graphs");
return _dummy_connectivity_set.connectivitySet(e);
}

// ! Returns the number of blocks contained in hyperedge he (not supported)
PartitionID connectivity(const HyperedgeID e) const {
ERR("Not supported for graphs");
throw NonSupportedOperationException("Not supported for graphs");
return _dummy_connectivity_set.connectivity(e);
}

// ! Creates a deep copy of the connectivity set of hyperedge he (not supported)
Bitset& deepCopyOfConnectivitySet(const HyperedgeID he) const {
ERR("Not supported for graphs");
throw NonSupportedOperationException("Not supported for graphs");
return _dummy_connectivity_set.deepCopy(he);
}

Expand Down
19 changes: 13 additions & 6 deletions mt-kahypar/datastructures/dynamic_graph.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
#include "mt-kahypar/datastructures/thread_safe_fast_reset_flag_array.h"
#include "mt-kahypar/parallel/stl/scalable_vector.h"
#include "mt-kahypar/utils/memory_tree.h"
#include "mt-kahypar/utils/exception.h"

namespace mt_kahypar {
namespace ds {
Expand Down Expand Up @@ -598,7 +599,8 @@ class DynamicGraph {

// ! Enables a hyperedge (must be disabled before)
void enableHyperedge(const HyperedgeID) {
ERR("enableHyperedge() is not supported in dynamic graph");
throw NonSupportedOperationException(
"enableHyperedge() is not supported in dynamic graph");
}

HyperedgeID edgeSource(const HyperedgeID e) const {
Expand Down Expand Up @@ -679,7 +681,8 @@ class DynamicGraph {
// ####################### Contract / Uncontract #######################

DynamicGraph contract(parallel::scalable_vector<HypernodeID>&) {
ERR("contract(c, id) is not supported in dynamic graph");
throw NonSupportedOperationException(
"contract(c, id) is not supported in dynamic graph");
return DynamicGraph();
}

Expand Down Expand Up @@ -764,21 +767,24 @@ class DynamicGraph {
* (Not supported.)
*/
void removeEdge(const HyperedgeID) {
ERR("removeEdge is not supported in dynamic graph");
throw NonSupportedOperationException(
"removeEdge is not supported in dynamic graph");
}

/*!
* (Not supported.)
*/
void removeLargeEdge(const HyperedgeID) {
ERR("removeLargeEdge is not supported in dynamic graph");
throw NonSupportedOperationException(
"removeLargeEdge is not supported in dynamic graph");
}

/*!
* (Not supported.)
*/
void restoreLargeEdge(const HyperedgeID&) {
ERR("restoreLargeEdge is not supported in dynamic graph");
throw NonSupportedOperationException(
"restoreLargeEdge is not supported in dynamic graph");
}

/**
Expand Down Expand Up @@ -814,7 +820,8 @@ class DynamicGraph {
}

void freeTmpContractionBuffer() {
ERR("freeTmpContractionBuffer() is not supported in dynamic hypergraph");
throw NonSupportedOperationException(
"freeTmpContractionBuffer() is not supported in dynamic hypergraph");
}

void memoryConsumption(utils::MemoryTreeNode* parent) const;
Expand Down
4 changes: 3 additions & 1 deletion mt-kahypar/datastructures/dynamic_graph_factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include "mt-kahypar/parallel/parallel_prefix_sum.h"
#include "mt-kahypar/parallel/stl/scalable_vector.h"
#include "mt-kahypar/utils/timer.h"
#include "mt-kahypar/utils/exception.h"

namespace mt_kahypar::ds {

Expand All @@ -51,7 +52,8 @@ DynamicGraph DynamicGraphFactory::construct(
tbb::parallel_for(UL(0), edge_vector.size(), [&](const size_t i) {
const auto& e = edge_vector[i];
if (e.size() != 2) {
ERR("Using graph data structure; but the input hypergraph is not a graph.");
throw InvalidInputException(
"Using graph data structure; but the input hypergraph is not a graph.");
}
edges[i] = std::make_pair(e[0], e[1]);
});
Expand Down
7 changes: 5 additions & 2 deletions mt-kahypar/datastructures/dynamic_hypergraph.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
#include "mt-kahypar/datastructures/thread_safe_fast_reset_flag_array.h"
#include "mt-kahypar/parallel/stl/scalable_vector.h"
#include "mt-kahypar/utils/memory_tree.h"
#include "mt-kahypar/utils/exception.h"

namespace mt_kahypar {
namespace ds {
Expand Down Expand Up @@ -774,7 +775,8 @@ class DynamicHypergraph {
// ####################### Contract / Uncontract #######################

DynamicHypergraph contract(parallel::scalable_vector<HypernodeID>&) {
ERR("contract(c, id) is not supported in dynamic hypergraph");
throw NonSupportedOperationException(
"contract(c, id) is not supported in dynamic hypergraph");
return DynamicHypergraph();
}

Expand Down Expand Up @@ -949,7 +951,8 @@ class DynamicHypergraph {
}

void freeTmpContractionBuffer() {
ERR("freeTmpContractionBuffer() is not supported in dynamic hypergraph");
throw NonSupportedOperationException(
"freeTmpContractionBuffer() is not supported in dynamic hypergraph");
}

void memoryConsumption(utils::MemoryTreeNode* parent) const;
Expand Down
3 changes: 2 additions & 1 deletion mt-kahypar/datastructures/graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include "mt-kahypar/parallel/atomic_wrapper.h"
#include "mt-kahypar/utils/timer.h"
#include "mt-kahypar/parallel/parallel_counting_sort.h"
#include "mt-kahypar/utils/exception.h"

namespace mt_kahypar::ds {

Expand Down Expand Up @@ -82,7 +83,7 @@ namespace mt_kahypar::ds {
break;
case LouvainEdgeWeight::hybrid:
case LouvainEdgeWeight::UNDEFINED:
ERR("No valid louvain edge weight");
throw InvalidInputException("No valid louvain edge weight");
}
}

Expand Down
10 changes: 7 additions & 3 deletions mt-kahypar/datastructures/partitioned_hypergraph.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
#include "mt-kahypar/parallel/stl/thread_locals.h"
#include "mt-kahypar/utils/range.h"
#include "mt-kahypar/utils/timer.h"
#include "mt-kahypar/utils/exception.h"

namespace mt_kahypar {

Expand Down Expand Up @@ -384,19 +385,22 @@ class PartitionedHypergraph {

// ! Target of an edge
HypernodeID edgeTarget(const HyperedgeID) const {
ERR("edgeTarget(e) is only supported on graph data structure");
throw NonSupportedOperationException(
"edgeTarget(e) is only supported on graph data structure");
return kInvalidHypernode;
}

// ! Source of an edge
HypernodeID edgeSource(const HyperedgeID) const {
ERR("edgeSource(e) is only supported on graph data structure");
throw NonSupportedOperationException(
"edgeSource(e) is only supported on graph data structure");
return kInvalidHypernode;
}

// ! Whether the edge is a single pin edge
bool isSinglePin(const HyperedgeID) const {
ERR("isSinglePin(e) is only supported on graph data structure");
throw NonSupportedOperationException(
"isSinglePin(e) is only supported on graph data structure");
return false;
}

Expand Down
31 changes: 21 additions & 10 deletions mt-kahypar/datastructures/static_graph.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
#include "mt-kahypar/partition/context_enum_classes.h"
#include "mt-kahypar/utils/memory_tree.h"
#include "mt-kahypar/utils/range.h"
#include "mt-kahypar/utils/exception.h"

namespace mt_kahypar {
namespace ds {
Expand Down Expand Up @@ -702,7 +703,8 @@ class StaticGraph {

// ! Enables a hyperedge (must be disabled before)
void enableHyperedge(const HyperedgeID) {
ERR("enableHyperedge() is not supported in static graph");
throw NonSupportedOperationException(
"enableHyperedge() is not supported in static graph");
}

// ! Community id which hypernode u is assigned to
Expand Down Expand Up @@ -768,14 +770,16 @@ class StaticGraph {
StaticGraph contract(parallel::scalable_vector<HypernodeID>& communities);

bool registerContraction(const HypernodeID, const HypernodeID) {
ERR("registerContraction(u, v) is not supported in static graph");
throw NonSupportedOperationException(
"registerContraction(u, v) is not supported in static graph");
return false;
}

size_t contract(const HypernodeID,
const HypernodeWeight max_node_weight = std::numeric_limits<HypernodeWeight>::max()) {
unused(max_node_weight);
ERR("contract(v, max_node_weight) is not supported in static graph");
throw NonSupportedOperationException(
"contract(v, max_node_weight) is not supported in static graph");
return 0;
}

Expand All @@ -786,11 +790,13 @@ class StaticGraph {
unused(mark_edge);
unused(case_one_func);
unused(case_two_func);
ERR("uncontract(batch) is not supported in static graph");
throw NonSupportedOperationException(
"uncontract(batch) is not supported in static graph");
}

VersionedBatchVector createBatchUncontractionHierarchy(const size_t) {
ERR("createBatchUncontractionHierarchy(batch_size) is not supported in static graph");
throw NonSupportedOperationException(
"createBatchUncontractionHierarchy(batch_size) is not supported in static graph");
return { };
}

Expand All @@ -805,23 +811,27 @@ class StaticGraph {
* setting.
*/
void removeLargeEdge(const HyperedgeID) {
ERR("removeLargeEdge() is not supported in static graph");
throw NonSupportedOperationException(
"removeLargeEdge() is not supported in static graph");
}

/*!
* Restores a large hyperedge previously removed from the hypergraph.
*/
void restoreLargeEdge(const HyperedgeID&) {
ERR("restoreLargeEdge() is not supported in static graph");
throw NonSupportedOperationException(
"restoreLargeEdge() is not supported in static graph");
}

parallel::scalable_vector<ParallelHyperedge> removeSinglePinAndParallelHyperedges() {
ERR("removeSinglePinAndParallelHyperedges() is not supported in static graph");
throw NonSupportedOperationException(
"removeSinglePinAndParallelHyperedges() is not supported in static graph");
return { };
}

void restoreSinglePinAndParallelNets(const parallel::scalable_vector<ParallelHyperedge>&) {
ERR("restoreSinglePinAndParallelNets(hes_to_restore) is not supported in static graph");
throw NonSupportedOperationException(
"restoreSinglePinAndParallelNets(hes_to_restore) is not supported in static graph");
}

// ####################### Initialization / Reset Functions #######################
Expand Down Expand Up @@ -868,7 +878,8 @@ class StaticGraph {

// ! Only for testing
bool verifyIncidenceArrayAndIncidentNets() {
ERR("verifyIncidenceArrayAndIncidentNets() not supported in static graph");
throw NonSupportedOperationException(
"verifyIncidenceArrayAndIncidentNets() not supported in static graph");
return false;
}

Expand Down
4 changes: 3 additions & 1 deletion mt-kahypar/datastructures/static_graph_factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include "mt-kahypar/parallel/parallel_prefix_sum.h"
#include "mt-kahypar/parallel/stl/scalable_vector.h"
#include "mt-kahypar/utils/timer.h"
#include "mt-kahypar/utils/exception.h"

namespace mt_kahypar::ds {
void StaticGraphFactory::sort_incident_edges(StaticGraph& graph) {
Expand Down Expand Up @@ -78,7 +79,8 @@ namespace mt_kahypar::ds {
tbb::parallel_for(UL(0), edge_vector.size(), [&](const size_t i) {
const auto& e = edge_vector[i];
if (e.size() != 2) {
ERR("Using graph data structure; but the input hypergraph is not a graph.");
throw InvalidInputException(
"Using graph data structure; but the input hypergraph is not a graph.");
}
edges[i] = std::make_pair(e[0], e[1]);
});
Expand Down
4 changes: 3 additions & 1 deletion mt-kahypar/datastructures/static_graph_factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

#include "mt-kahypar/datastructures/static_graph.h"
#include "mt-kahypar/parallel/atomic_wrapper.h"
#include "mt-kahypar/utils/exception.h"


namespace mt_kahypar {
Expand Down Expand Up @@ -63,7 +64,8 @@ class StaticGraphFactory {
const bool stable_construction_of_incident_edges = false);

static std::pair<StaticGraph, parallel::scalable_vector<HypernodeID> > compactify(const StaticGraph&) {
ERR("Compactify not implemented for static graph.");
throw NonSupportedOperationException(
"Compactify not implemented for static graph.");
}

private:
Expand Down
Loading

0 comments on commit aa73caa

Please sign in to comment.