diff --git a/mt-kahypar/datastructures/static_graph.cpp b/mt-kahypar/datastructures/static_graph.cpp index a67f007ac..1cc70c6e0 100644 --- a/mt-kahypar/datastructures/static_graph.cpp +++ b/mt-kahypar/datastructures/static_graph.cpp @@ -47,7 +47,6 @@ namespace mt_kahypar::ds { * \param communities Community structure that should be contracted */ StaticGraph StaticGraph::contract(parallel::scalable_vector& communities, bool /*deterministic*/) { - std::cout << "contraction\n"; ASSERT(communities.size() == _num_nodes); if ( !_tmp_contraction_buffer ) { @@ -90,11 +89,11 @@ namespace mt_kahypar::ds { // Remap community ids tbb::parallel_for(ID(0), _num_nodes, [&](const HypernodeID& node) { - /*if ( nodeIsEnabled(node) ) { + if ( nodeIsEnabled(node) ) { communities[node] = mapping_prefix_sum[communities[node]]; } else { communities[node] = kInvalidHypernode; - }*/ + } // Reset tmp contraction buffer if ( node < coarsened_num_nodes ) { @@ -117,7 +116,7 @@ namespace mt_kahypar::ds { const HypernodeID coarse_node = map_to_coarse_graph(node); ASSERT(coarse_node < coarsened_num_nodes, V(coarse_node) << V(coarsened_num_nodes)); // Weight vector is atomic => thread-safe - node_weights[coarse_node].add_fetch(nodeWeight(node), std::memory_order_relaxed); + node_weights[coarse_node] += nodeWeight(node); // Aggregate upper bound for number of incident nets of the contracted vertex tmp_num_incident_edges[coarse_node] += nodeDegree(node); }); @@ -508,4 +507,4 @@ namespace mt_kahypar::ds { }, std::plus<>()); } -} // namespace +} // namespace \ No newline at end of file diff --git a/mt-kahypar/partition/coarsening/deterministic_multilevel_coarsener.cpp b/mt-kahypar/partition/coarsening/deterministic_multilevel_coarsener.cpp index cdaf5eaa8..8e3e9bbca 100644 --- a/mt-kahypar/partition/coarsening/deterministic_multilevel_coarsener.cpp +++ b/mt-kahypar/partition/coarsening/deterministic_multilevel_coarsener.cpp @@ -33,7 +33,7 @@ namespace mt_kahypar { template -bool DeterministicMultilevelCoarsener::coarseningPassImpl(std::string input) { +bool DeterministicMultilevelCoarsener::coarseningPassImpl() { auto& timer = utils::Utilities::instance().getTimer(_context.utility_id); const auto pass_start_time = std::chrono::high_resolution_clock::now(); timer.start_timer("coarsening_pass", "Clustering"); diff --git a/mt-kahypar/partition/coarsening/deterministic_multilevel_coarsener.h b/mt-kahypar/partition/coarsening/deterministic_multilevel_coarsener.h index 9a87f4e10..3796ba940 100644 --- a/mt-kahypar/partition/coarsening/deterministic_multilevel_coarsener.h +++ b/mt-kahypar/partition/coarsening/deterministic_multilevel_coarsener.h @@ -101,7 +101,7 @@ class DeterministicMultilevelCoarsener : public ICoarsener, } } - bool coarseningPassImpl(std::string input) override; + bool coarseningPassImpl() override; bool shouldNotTerminateImpl() const override { return Base::currentNumNodes() > _context.coarsening.contraction_limit; diff --git a/mt-kahypar/partition/coarsening/i_coarsener.h b/mt-kahypar/partition/coarsening/i_coarsener.h index 7cd4bc173..c54644769 100644 --- a/mt-kahypar/partition/coarsening/i_coarsener.h +++ b/mt-kahypar/partition/coarsening/i_coarsener.h @@ -27,7 +27,6 @@ #pragma once #include -#include #include "include/libmtkahypartypes.h" @@ -45,30 +44,19 @@ class ICoarsener { ICoarsener & operator= (const ICoarsener &) = delete; ICoarsener & operator= (ICoarsener &&) = delete; - void coarsen(std::string ipf) { + void coarsen() { initialize(); bool should_continue = true; int pass_nr = 0; - std::ifstream myfile; - myfile.open(ipf); - HypernodeID hn = 0; - while(myfile){ - std::string nextline; - std::getline(myfile, nextline); - if(nextline.rfind("IP") == 0 || nextline.rfind(" ") == -1) break; - coarseningPassImpl(nextline); - } - myfile.close(); - // Coarsening algorithms proceed in passes where each pass computes a clustering // of the nodes and subsequently contracts it. Each pass induces one level of the // hierarchy. The coarsening algorithms proceeds until the number of nodes equals // a predefined contraction limit (!shouldNotTerminate) or the number of nodes could // not be significantly reduced within one coarsening pass (should_continue). - /*while ( shouldNotTerminate() && should_continue ) { + while ( shouldNotTerminate() && should_continue ) { /*timer.start_timer("coarsening pass " + pass_nr, "CoarseningPass" + pass_nr);*/ - /*should_continue = coarseningPass(); - }*/ + should_continue = coarseningPass(); + } terminate(); } @@ -77,11 +65,11 @@ class ICoarsener { } bool shouldNotTerminate() const { - return false/*shouldNotTerminateImpl()*/; + return shouldNotTerminateImpl(); } bool coarseningPass() { - return coarseningPassImpl(""); + return coarseningPassImpl(); } void terminate() { @@ -109,7 +97,7 @@ class ICoarsener { private: virtual void initializeImpl() = 0; virtual bool shouldNotTerminateImpl() const = 0; - virtual bool coarseningPassImpl(std::string input) = 0; + virtual bool coarseningPassImpl() = 0; virtual void terminateImpl() = 0; virtual HypernodeID currentNumberOfNodesImpl() const = 0; virtual mt_kahypar_hypergraph_t coarsestHypergraphImpl() = 0; diff --git a/mt-kahypar/partition/coarsening/multilevel_coarsener.h b/mt-kahypar/partition/coarsening/multilevel_coarsener.h index bb447f65a..cf9194906 100644 --- a/mt-kahypar/partition/coarsening/multilevel_coarsener.h +++ b/mt-kahypar/partition/coarsening/multilevel_coarsener.h @@ -139,7 +139,7 @@ class MultilevelCoarsener : public ICoarsener, return Base::currentNumNodes() > _context.coarsening.contraction_limit; } - bool coarseningPassImpl(std::string input) override { + bool coarseningPassImpl() override { HighResClockTimepoint round_start = std::chrono::high_resolution_clock::now(); Hypergraph& current_hg = Base::currentHypergraph(); DBG << V(_pass_nr) @@ -150,15 +150,7 @@ class MultilevelCoarsener : public ICoarsener, // Random shuffle vertices of current hypergraph _current_vertices.resize(current_hg.initialNumNodes()); parallel::scalable_vector cluster_ids(current_hg.initialNumNodes()); - std::vector ctmp(current_hg.initialNumNodes()); - std::stringstream ss(input); - std::string word; - for(HypernodeID hn = 0; hn < current_hg.initialNumNodes(); hn++){ - ss >> word; - cluster_ids[hn] = stoi(word); - ctmp[hn] = stoi(word); - } - /*tbb::parallel_for(ID(0), current_hg.initialNumNodes(), [&](const HypernodeID hn) { + tbb::parallel_for(ID(0), current_hg.initialNumNodes(), [&](const HypernodeID hn) { ASSERT(hn < _current_vertices.size()); // Reset clustering _current_vertices[hn] = hn; @@ -218,32 +210,10 @@ class MultilevelCoarsener : public ICoarsener, return false; } _progress_bar += (num_hns_before_pass - current_num_nodes); - */ + _timer.start_timer("contraction", "Contraction"); // Perform parallel contraction - std::cout << "c0: \n"; /*current_hg.nodeWeight(0).weights[0] << " " << current_hg.nodeWeight(0).weights[1] << "\n";*/ - for(int i = 0; i < cluster_ids.size(); i++){ - std::cout << cluster_ids[i] << " "; - } - _uncoarseningData.performMultilevelContraction(std::move(cluster_ids), true /* deterministic */, round_start); - Hypergraph& chg = Base::currentHypergraph(); - //if(chg.initialNumNodes() == current_hg.initialNumNodes()) std::cout << 1/0 << "\n"; - std::vector tmp(chg.initialNumNodes(), 0); - std::cout << "sizes: " << current_hg.initialNumNodes() << " " << chg.initialNumNodes() << "\n"; - for(HypernodeID hn : current_hg.nodes()){ - //if(current_hg.nodeWeight(hn).weights[1] == 0) std::cout << 1/0; - } - std::cout << "c0: \n"; /*current_hg.nodeWeight(0).weights[0] << " " << current_hg.nodeWeight(0).weights[1] << "\n";*/ - /*for(int i = 0; i < cluster_ids.size(); i++){ - std::cout << cluster_ids[i] << " "; - if(cluster_ids[i] != ctmp[i]) std::cout << 1/0 << "\n"; - tmp[cluster_ids[i]] += current_hg.nodeWeight(i); - } - for(int i = 0; i < tmp.size(); i++){ - if(tmp[i] != chg.nodeWeight(i)){ - std::cout << "difference:" << i << " " << tmp[i].weights[0] << " " << tmp[i].weights[1] << " " << chg.nodeWeight(i).weights[0] << " " << chg.nodeWeight(i).weights[1] << "\n"; - while(true){}} - }*/ + _uncoarseningData.performMultilevelContraction(std::move(cluster_ids), false /* deterministic */, round_start); _timer.stop_timer("contraction"); ++_pass_nr; @@ -534,4 +504,4 @@ class MultilevelCoarsener : public ICoarsener, bool _enable_randomization; }; -} // namespace mt_kahypar +} // namespace mt_kahypar \ No newline at end of file diff --git a/mt-kahypar/partition/coarsening/nlevel_uncoarsener.cpp b/mt-kahypar/partition/coarsening/nlevel_uncoarsener.cpp index a4eeb0de1..1cca04fbe 100644 --- a/mt-kahypar/partition/coarsening/nlevel_uncoarsener.cpp +++ b/mt-kahypar/partition/coarsening/nlevel_uncoarsener.cpp @@ -230,7 +230,6 @@ namespace mt_kahypar { void NLevelUncoarsener::rebalancingImpl() { // If we reach the top-level hypergraph and the partition is still imbalanced, // we use a rebalancing algorithm to restore balance. - std::cout << "test we are here\n"; if ( _context.type == ContextType::main && !metrics::isBalanced(*_uncoarseningData.partitioned_hg, _context)) { const HyperedgeWeight quality_before = _current_metrics.quality; if ( _context.partition.verbose_output ) { diff --git a/mt-kahypar/partition/coarsening/nlevel_uncoarsener.h b/mt-kahypar/partition/coarsening/nlevel_uncoarsener.h index 2aee0dad8..7913dee5c 100644 --- a/mt-kahypar/partition/coarsening/nlevel_uncoarsener.h +++ b/mt-kahypar/partition/coarsening/nlevel_uncoarsener.h @@ -165,4 +165,4 @@ class NLevelUncoarsener : public IUncoarsener, bool _is_timer_disabled; bool _force_measure_timings; }; -} +} \ No newline at end of file diff --git a/mt-kahypar/partition/multilevel.cpp b/mt-kahypar/partition/multilevel.cpp index be90b23b2..7c651dbe4 100644 --- a/mt-kahypar/partition/multilevel.cpp +++ b/mt-kahypar/partition/multilevel.cpp @@ -82,6 +82,7 @@ namespace { const bool is_vcycle) { using Hypergraph = typename TypeTraits::Hypergraph; using PartitionedHypergraph = typename TypeTraits::PartitionedHypergraph; + PartitionedHypergraph partitioned_hg; // ################## COARSENING ################## mt_kahypar::io::printCoarseningBanner(context); @@ -96,7 +97,7 @@ namespace { context.coarsening.algorithm, utils::hypergraph_cast(hypergraph), context, uncoarsening::to_pointer(uncoarseningData)); - coarsener->coarsen(context.partition.contraction_input_file); + coarsener->coarsen(); if (context.partition.verbose_output) { mt_kahypar_hypergraph_t coarsestHypergraph = coarsener->coarsestHypergraph(); @@ -106,39 +107,16 @@ namespace { } } timer.stop_timer("coarsening"); - std::unique_ptr> uncoarsener(nullptr); + /*std::unique_ptr> uncoarsener(nullptr); if (uncoarseningData.nlevel) { - /*uncoarsener = std::make_unique>( - hypergraph, context, uncoarseningData, target_graph);*/ + uncoarsener = std::make_unique>( + hypergraph, context, uncoarseningData, target_graph); } else { uncoarsener = std::make_unique>( hypergraph, context, uncoarseningData, target_graph); } - /*PartitionedHypergraph partitioned_hg; - int initial_num = hypergraph.initialNumEdges(); - partitioned_hg = PartitionedHypergraph(context.partition.k, hypergraph); - - - std::ifstream myfile; - myfile.open(context.partition.partition_input_file); - HypernodeID hn = 0; - while(myfile){ - std::string nextline; - std::getline(myfile, nextline); - if(nextline != ""){ - ASSERT(stoi(nextline) < partitioned_hg.k()); - partitioned_hg.setOnlyNodePart(hn, stoi(nextline)); - } - hn++; - } - myfile.close(); - partitioned_hg.initializePartition();*/ - - /*for(HypernodeID hn : partitioned_hg.nodes()){ - std::cout << partitioned_hg.partID(hn) << "\n"; - }*/ PartitionedHypergraph& partitioned_hg = uncoarseningData.coarsestPartitionedHypergraph(); - std::ifstream myfile; + /*std::ifstream myfile; myfile.open(context.partition.contraction_input_file); HypernodeID hn = 0; bool is_partfile = false; @@ -176,11 +154,11 @@ namespace { PartitionedHypergraph back = uncoarsener->uncoarsen(); /*partitioned_hg = uncoarsener->doLastRefine(&partitioned_hg);*/ - io::printPartitioningResults(back, context, "Local Search Results:"); - return back; + /*io::printPartitioningResults(back, context, "Local Search Results:"); + return back;*/ - /*// ################## INITIAL PARTITIONING ################## + // ################## INITIAL PARTITIONING ################## io::printInitialPartitioningBanner(context); timer.start_timer("initial_partitioning", "Initial Partitioning"); PartitionedHypergraph& phg = uncoarseningData.coarsestPartitionedHypergraph(); @@ -267,17 +245,17 @@ namespace { timer.start_timer("refinement", "Refinement"); std::unique_ptr> uncoarsener(nullptr); if (uncoarseningData.nlevel) { - uncoarsener = std::make_unique>( - hypergraph, context, uncoarseningData, target_graph); + /*uncoarsener = std::make_unique>( + hypergraph, context, uncoarseningData, target_graph);*/ } else { uncoarsener = std::make_unique>( hypergraph, context, uncoarseningData, target_graph); } partitioned_hg = uncoarsener->uncoarsen(); - partitioned_hg = uncoarsener->doLastRefine(); + /*partitioned_hg = uncoarsener->doLastRefine();*/ io::printPartitioningResults(partitioned_hg, context, "Local Search Results:"); timer.stop_timer("refinement"); - return partitioned_hg;*/ + return partitioned_hg; } }