Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 7 additions & 24 deletions include/CXXGraph/Partitioning/CoordinatedPartitionState.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#pragma once

#include <algorithm>
#include <memory>
#include <mutex>
#include <set>
Expand Down Expand Up @@ -136,10 +137,7 @@ void CoordinatedPartitionState<T>::incrementMachineLoad(
const int m, shared<const Edge<T>> e) {
std::lock_guard<std::mutex> lock(*machines_load_edges_mutex);
machines_load_edges[m] = machines_load_edges[m] + 1;
int new_value = machines_load_edges.at(m);
if (new_value > MAX_LOAD) {
MAX_LOAD = new_value;
}
MAX_LOAD = std::max(MAX_LOAD, machines_load_edges.at(m));
partition_map[m]->addEdge(e);
}
template <typename T>
Expand All @@ -161,14 +159,8 @@ void CoordinatedPartitionState<T>::incrementMachineWeight(
template <typename T>
int CoordinatedPartitionState<T>::getMinLoad() const {
std::lock_guard<std::mutex> lock(*machines_load_edges_mutex);
int MIN_LOAD = std::numeric_limits<int>::max();
for (const auto &machines_load_edges_it : machines_load_edges) {
int loadi = machines_load_edges_it;
if (loadi < MIN_LOAD) {
MIN_LOAD = loadi;
}
}
return MIN_LOAD;
return *std::min_element(machines_load_edges.begin(),
machines_load_edges.end());
}
template <typename T>
int CoordinatedPartitionState<T>::getMaxLoad() const {
Expand All @@ -177,18 +169,9 @@ int CoordinatedPartitionState<T>::getMaxLoad() const {
template <typename T>
int CoordinatedPartitionState<T>::getMachineWithMinWeight() const {
std::lock_guard<std::mutex> lock(*machines_weight_edges_mutex);

double MIN_LOAD = std::numeric_limits<double>::max();
int machine_id = 0;
for (size_t i = 0; i < machines_weight_edges.size(); ++i) {
double loadi = machines_weight_edges[i];
if (loadi < MIN_LOAD) {
MIN_LOAD = loadi;
machine_id = i;
}
}

return machine_id;
return std::distance(machines_weight_edges.begin(),
std::min_element(machines_weight_edges.begin(),
machines_weight_edges.end()));
}
template <typename T>
int CoordinatedPartitionState<T>::getMachineWithMinWeight(
Expand Down
7 changes: 2 additions & 5 deletions include/CXXGraph/Partitioning/HDRF.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,8 @@ void HDRF<T>::performStep(shared<const Edge<T>> e,
fv = 1 + (1 - fv);
}
int load = state->getMachineLoad(m);
double bal = (MAX_LOAD - load);
bal /= (epsilon + MAX_LOAD - MIN_LOAD);
if (bal < 0) {
bal = 0;
}
const double bal =
std::max(0.0, (MAX_LOAD - load) / (epsilon + MAX_LOAD - MIN_LOAD));
double SCORE_m = fu + fv + lambda * bal;
if (SCORE_m < 0) {
std::cout << "ERRORE: SCORE_m<0" << std::endl;
Expand Down
Loading