summaryrefslogtreecommitdiff
path: root/src/mem/ruby/network/simple/Topology.cc
diff options
context:
space:
mode:
authorNathan Binkert <nate@binkert.org>2010-03-31 16:56:45 -0700
committerNathan Binkert <nate@binkert.org>2010-03-31 16:56:45 -0700
commitbe10204729c107b41d5d7487323c732e9fa09df5 (patch)
tree5c8f4001c490c4d777e8756e536cd2f2340c9ebb /src/mem/ruby/network/simple/Topology.cc
parent60ae1d2b10002bb73b420fce91c4b74397c55457 (diff)
downloadgem5-be10204729c107b41d5d7487323c732e9fa09df5.tar.xz
style: another ruby style pass
Diffstat (limited to 'src/mem/ruby/network/simple/Topology.cc')
-rw-r--r--src/mem/ruby/network/simple/Topology.cc546
1 files changed, 295 insertions, 251 deletions
diff --git a/src/mem/ruby/network/simple/Topology.cc b/src/mem/ruby/network/simple/Topology.cc
index a8ce4db84..3d7aa35d0 100644
--- a/src/mem/ruby/network/simple/Topology.cc
+++ b/src/mem/ruby/network/simple/Topology.cc
@@ -1,4 +1,3 @@
-
/*
* Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
* All rights reserved.
@@ -27,27 +26,18 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-/*
- * Topology.cc
- *
- * Description: See Topology.hh
- *
- * $Id$
- *
- * */
-
-#include "mem/ruby/network/simple/Topology.hh"
-#include "mem/ruby/common/NetDest.hh"
-#include "mem/ruby/network/Network.hh"
-#include "mem/ruby/slicc_interface/AbstractController.hh"
-#include "mem/protocol/TopologyType.hh"
#include "mem/gems_common/util.hh"
#include "mem/protocol/MachineType.hh"
#include "mem/protocol/Protocol.hh"
+#include "mem/protocol/TopologyType.hh"
+#include "mem/ruby/common/NetDest.hh"
+#include "mem/ruby/network/Network.hh"
+#include "mem/ruby/network/simple/Topology.hh"
+#include "mem/ruby/slicc_interface/AbstractController.hh"
#include "mem/ruby/system/System.hh"
-static const int INFINITE_LATENCY = 10000; // Yes, this is a big hack
-static const int DEFAULT_BW_MULTIPLIER = 1; // Just to be consistent with above :)
+const int INFINITE_LATENCY = 10000; // Yes, this is a big hack
+const int DEFAULT_BW_MULTIPLIER = 1; // Just to be consistent with above :)
// Note: In this file, we use the first 2*m_nodes SwitchIDs to
// represent the input and output endpoint links. These really are
@@ -57,10 +47,14 @@ static const int DEFAULT_BW_MULTIPLIER = 1; // Just to be consistent with above
// of the network.
// Helper functions based on chapter 29 of Cormen et al.
-static void extend_shortest_path(Matrix& current_dist, Matrix& latencies, Matrix& inter_switches);
-static Matrix shortest_path(const Matrix& weights, Matrix& latencies, Matrix& inter_switches);
-static bool link_is_shortest_path_to_node(SwitchID src, SwitchID next, SwitchID final, const Matrix& weights, const Matrix& dist);
-static NetDest shortest_path_to_node(SwitchID src, SwitchID next, const Matrix& weights, const Matrix& dist);
+void extend_shortest_path(Matrix& current_dist, Matrix& latencies,
+ Matrix& inter_switches);
+Matrix shortest_path(const Matrix& weights, Matrix& latencies,
+ Matrix& inter_switches);
+bool link_is_shortest_path_to_node(SwitchID src, SwitchID next,
+ SwitchID final, const Matrix& weights, const Matrix& dist);
+NetDest shortest_path_to_node(SwitchID src, SwitchID next,
+ const Matrix& weights, const Matrix& dist);
Topology::Topology(const Params *p)
: SimObject(p)
@@ -71,306 +65,356 @@ Topology::Topology(const Params *p)
m_component_latencies.setSize(0);
m_component_inter_switches.setSize(0);
- //
// Total nodes/controllers in network
// Must make sure this is called after the State Machine constructors
- //
m_nodes = MachineType_base_number(MachineType_NUM);
assert(m_nodes > 1);
- if (m_nodes != params()->ext_links.size()) {
+ if (m_nodes != params()->ext_links.size() &&
+ m_nodes != params()->ext_links.size()) {
fatal("m_nodes (%d) != ext_links vector length (%d)\n",
- m_nodes != params()->ext_links.size());
+ m_nodes != params()->ext_links.size());
}
- //
- // First create the links between the endpoints (i.e. controllers) and the
- // network.
- //
- for (vector<ExtLink*>::const_iterator i = params()->ext_links.begin();
- i != params()->ext_links.end(); ++i)
- {
- const ExtLinkParams *p = (*i)->params();
- AbstractController *c = p->ext_node;
-
- // Store the controller pointers for later
- m_controller_vector.insertAtBottom(c);
-
- int ext_idx1 =
- MachineType_base_number(c->getMachineType()) + c->getVersion();
- int ext_idx2 = ext_idx1 + m_nodes;
- int int_idx = p->int_node + 2*m_nodes;
-
- // create the links in both directions
- addLink(ext_idx1, int_idx, p->latency, p->bw_multiplier, p->weight);
- addLink(int_idx, ext_idx2, p->latency, p->bw_multiplier, p->weight);
- }
-
- for (vector<IntLink*>::const_iterator i = params()->int_links.begin();
- i != params()->int_links.end(); ++i)
- {
- const IntLinkParams *p = (*i)->params();
- int a = p->node_a + 2*m_nodes;
- int b = p->node_b + 2*m_nodes;
-
- // create the links in both directions
- addLink(a, b, p->latency, p->bw_multiplier, p->weight);
- addLink(b, a, p->latency, p->bw_multiplier, p->weight);
- }
+ // First create the links between the endpoints (i.e. controllers)
+ // and the network.
+ for (vector<ExtLink*>::const_iterator i = params()->ext_links.begin();
+ i != params()->ext_links.end(); ++i) {
+ const ExtLinkParams *p = (*i)->params();
+ AbstractController *c = p->ext_node;
+
+ // Store the controller pointers for later
+ m_controller_vector.insertAtBottom(c);
+
+ int ext_idx1 =
+ MachineType_base_number(c->getMachineType()) + c->getVersion();
+ int ext_idx2 = ext_idx1 + m_nodes;
+ int int_idx = p->int_node + 2*m_nodes;
+
+ // create the links in both directions
+ addLink(ext_idx1, int_idx, p->latency, p->bw_multiplier, p->weight);
+ addLink(int_idx, ext_idx2, p->latency, p->bw_multiplier, p->weight);
+ }
+
+ for (vector<IntLink*>::const_iterator i = params()->int_links.begin();
+ i != params()->int_links.end(); ++i) {
+ const IntLinkParams *p = (*i)->params();
+ int a = p->node_a + 2*m_nodes;
+ int b = p->node_b + 2*m_nodes;
+
+ // create the links in both directions
+ addLink(a, b, p->latency, p->bw_multiplier, p->weight);
+ addLink(b, a, p->latency, p->bw_multiplier, p->weight);
+ }
}
-void Topology::initNetworkPtr(Network* net_ptr)
+void
+Topology::initNetworkPtr(Network* net_ptr)
{
- for (int cntrl = 0; cntrl < m_controller_vector.size(); cntrl++)
- {
+ for (int cntrl = 0; cntrl < m_controller_vector.size(); cntrl++) {
m_controller_vector[cntrl]->initNetworkPtr(net_ptr);
}
}
-
-void Topology::createLinks(Network *net, bool isReconfiguration)
+void
+Topology::createLinks(Network *net, bool isReconfiguration)
{
- // Find maximum switchID
-
- SwitchID max_switch_id = 0;
- for (int i=0; i<m_links_src_vector.size(); i++) {
- max_switch_id = max(max_switch_id, m_links_src_vector[i]);
- max_switch_id = max(max_switch_id, m_links_dest_vector[i]);
- }
-
- // Initialize weight vector
- Matrix topology_weights;
- Matrix topology_latency;
- Matrix topology_bw_multis;
- int num_switches = max_switch_id+1;
- topology_weights.setSize(num_switches);
- topology_latency.setSize(num_switches);
- topology_bw_multis.setSize(num_switches);
- m_component_latencies.setSize(num_switches); // FIXME setting the size of a member variable here is a HACK!
- m_component_inter_switches.setSize(num_switches); // FIXME setting the size of a member variable here is a HACK!
- for(int i=0; i<topology_weights.size(); i++) {
- topology_weights[i].setSize(num_switches);
- topology_latency[i].setSize(num_switches);
- topology_bw_multis[i].setSize(num_switches);
- m_component_latencies[i].setSize(num_switches);
- m_component_inter_switches[i].setSize(num_switches); // FIXME setting the size of a member variable here is a HACK!
- for(int j=0; j<topology_weights[i].size(); j++) {
- topology_weights[i][j] = INFINITE_LATENCY;
- topology_latency[i][j] = -1; // initialize to an invalid value
- topology_bw_multis[i][j] = -1; // initialize to an invalid value
- m_component_latencies[i][j] = -1; // initialize to an invalid value
- m_component_inter_switches[i][j] = 0; // initially assume direct connections / no intermediate switches between components
+ // Find maximum switchID
+ SwitchID max_switch_id = 0;
+ for (int i = 0; i < m_links_src_vector.size(); i++) {
+ max_switch_id = max(max_switch_id, m_links_src_vector[i]);
+ max_switch_id = max(max_switch_id, m_links_dest_vector[i]);
}
- }
-
- // Set identity weights to zero
- for(int i=0; i<topology_weights.size(); i++) {
- topology_weights[i][i] = 0;
- }
-
- // Fill in the topology weights and bandwidth multipliers
- for (int i=0; i<m_links_src_vector.size(); i++) {
- topology_weights[m_links_src_vector[i]][m_links_dest_vector[i]] = m_links_weight_vector[i];
- topology_latency[m_links_src_vector[i]][m_links_dest_vector[i]] = m_links_latency_vector[i];
- m_component_latencies[m_links_src_vector[i]][m_links_dest_vector[i]] = m_links_latency_vector[i]; // initialize to latency vector
- topology_bw_multis[m_links_src_vector[i]][m_links_dest_vector[i]] = m_bw_multiplier_vector[i];
- }
-
- // Walk topology and hookup the links
- Matrix dist = shortest_path(topology_weights, m_component_latencies, m_component_inter_switches);
- for(int i=0; i<topology_weights.size(); i++) {
- for(int j=0; j<topology_weights[i].size(); j++) {
- int weight = topology_weights[i][j];
- int bw_multiplier = topology_bw_multis[i][j];
- int latency = topology_latency[i][j];
- if (weight > 0 && weight != INFINITE_LATENCY) {
- NetDest destination_set = shortest_path_to_node(i, j, topology_weights, dist);
- assert(latency != -1);
- makeLink(net, i, j, destination_set, latency, weight, bw_multiplier, isReconfiguration);
- }
+
+ // Initialize weight vector
+ Matrix topology_weights;
+ Matrix topology_latency;
+ Matrix topology_bw_multis;
+ int num_switches = max_switch_id+1;
+ topology_weights.setSize(num_switches);
+ topology_latency.setSize(num_switches);
+ topology_bw_multis.setSize(num_switches);
+
+ // FIXME setting the size of a member variable here is a HACK!
+ m_component_latencies.setSize(num_switches);
+
+ // FIXME setting the size of a member variable here is a HACK!
+ m_component_inter_switches.setSize(num_switches);
+
+ for (int i = 0; i < topology_weights.size(); i++) {
+ topology_weights[i].setSize(num_switches);
+ topology_latency[i].setSize(num_switches);
+ topology_bw_multis[i].setSize(num_switches);
+ m_component_latencies[i].setSize(num_switches);
+
+ // FIXME setting the size of a member variable here is a HACK!
+ m_component_inter_switches[i].setSize(num_switches);
+
+ for (int j = 0; j < topology_weights[i].size(); j++) {
+ topology_weights[i][j] = INFINITE_LATENCY;
+
+ // initialize to invalid values
+ topology_latency[i][j] = -1;
+ topology_bw_multis[i][j] = -1;
+ m_component_latencies[i][j] = -1;
+
+ // initially assume direct connections / no intermediate
+ // switches between components
+ m_component_inter_switches[i][j] = 0;
+ }
+ }
+
+ // Set identity weights to zero
+ for (int i = 0; i < topology_weights.size(); i++) {
+ topology_weights[i][i] = 0;
+ }
+
+ // Fill in the topology weights and bandwidth multipliers
+ for (int i = 0; i < m_links_src_vector.size(); i++) {
+ int src = m_links_src_vector[i];
+ int dst = m_links_dest_vector[i];
+ topology_weights[src][dst] = m_links_weight_vector[i];
+ topology_latency[src][dst] = m_links_latency_vector[i];
+ m_component_latencies[src][dst] = m_links_latency_vector[i];
+ topology_bw_multis[src][dst] = m_bw_multiplier_vector[i];
+ }
+
+ // Walk topology and hookup the links
+ Matrix dist = shortest_path(topology_weights, m_component_latencies,
+ m_component_inter_switches);
+ for (int i = 0; i < topology_weights.size(); i++) {
+ for (int j = 0; j < topology_weights[i].size(); j++) {
+ int weight = topology_weights[i][j];
+ int bw_multiplier = topology_bw_multis[i][j];
+ int latency = topology_latency[i][j];
+ if (weight > 0 && weight != INFINITE_LATENCY) {
+ NetDest destination_set = shortest_path_to_node(i, j,
+ topology_weights, dist);
+ assert(latency != -1);
+ makeLink(net, i, j, destination_set, latency, weight,
+ bw_multiplier, isReconfiguration);
+ }
+ }
}
- }
}
-SwitchID Topology::newSwitchID()
+SwitchID
+Topology::newSwitchID()
{
- m_number_of_switches++;
- return m_number_of_switches-1+m_nodes+m_nodes;
+ m_number_of_switches++;
+ return m_number_of_switches-1+m_nodes+m_nodes;
}
-void Topology::addLink(SwitchID src, SwitchID dest, int link_latency)
+void
+Topology::addLink(SwitchID src, SwitchID dest, int link_latency)
{
- addLink(src, dest, link_latency, DEFAULT_BW_MULTIPLIER, link_latency);
+ addLink(src, dest, link_latency, DEFAULT_BW_MULTIPLIER, link_latency);
}
-void Topology::addLink(SwitchID src, SwitchID dest, int link_latency, int bw_multiplier)
+void
+Topology::addLink(SwitchID src, SwitchID dest, int link_latency,
+ int bw_multiplier)
{
- addLink(src, dest, link_latency, bw_multiplier, link_latency);
+ addLink(src, dest, link_latency, bw_multiplier, link_latency);
}
-void Topology::addLink(SwitchID src, SwitchID dest, int link_latency, int bw_multiplier, int link_weight)
+void
+Topology::addLink(SwitchID src, SwitchID dest, int link_latency,
+ int bw_multiplier, int link_weight)
{
- ASSERT(src <= m_number_of_switches+m_nodes+m_nodes);
- ASSERT(dest <= m_number_of_switches+m_nodes+m_nodes);
- m_links_src_vector.insertAtBottom(src);
- m_links_dest_vector.insertAtBottom(dest);
- m_links_latency_vector.insertAtBottom(link_latency);
- m_links_weight_vector.insertAtBottom(link_weight);
- m_bw_multiplier_vector.insertAtBottom(bw_multiplier);
+ ASSERT(src <= m_number_of_switches+m_nodes+m_nodes);
+ ASSERT(dest <= m_number_of_switches+m_nodes+m_nodes);
+ m_links_src_vector.insertAtBottom(src);
+ m_links_dest_vector.insertAtBottom(dest);
+ m_links_latency_vector.insertAtBottom(link_latency);
+ m_links_weight_vector.insertAtBottom(link_weight);
+ m_bw_multiplier_vector.insertAtBottom(bw_multiplier);
}
-void Topology::makeLink(Network *net, SwitchID src, SwitchID dest, const NetDest& routing_table_entry, int link_latency, int link_weight, int bw_multiplier, bool isReconfiguration)
+void
+Topology::makeLink(Network *net, SwitchID src, SwitchID dest,
+ const NetDest& routing_table_entry, int link_latency, int link_weight,
+ int bw_multiplier, bool isReconfiguration)
{
- // Make sure we're not trying to connect two end-point nodes directly together
- assert((src >= 2*m_nodes) || (dest >= 2*m_nodes));
-
- if (src < m_nodes) {
- net->makeInLink(src, dest-(2*m_nodes), routing_table_entry, link_latency, bw_multiplier, isReconfiguration);
- } else if (dest < 2*m_nodes) {
- assert(dest >= m_nodes);
- NodeID node = dest-m_nodes;
- net->makeOutLink(src-(2*m_nodes), node, routing_table_entry, link_latency, link_weight, bw_multiplier, isReconfiguration);
- } else {
- assert((src >= 2*m_nodes) && (dest >= 2*m_nodes));
- net->makeInternalLink(src-(2*m_nodes), dest-(2*m_nodes), routing_table_entry, link_latency, link_weight, bw_multiplier, isReconfiguration);
- }
+ // Make sure we're not trying to connect two end-point nodes
+ // directly together
+ assert(src >= 2 * m_nodes || dest >= 2 * m_nodes);
+
+ if (src < m_nodes) {
+ net->makeInLink(src, dest-(2*m_nodes), routing_table_entry,
+ link_latency, bw_multiplier, isReconfiguration);
+ } else if (dest < 2*m_nodes) {
+ assert(dest >= m_nodes);
+ NodeID node = dest-m_nodes;
+ net->makeOutLink(src-(2*m_nodes), node, routing_table_entry,
+ link_latency, link_weight, bw_multiplier, isReconfiguration);
+ } else {
+ assert((src >= 2*m_nodes) && (dest >= 2*m_nodes));
+ net->makeInternalLink(src-(2*m_nodes), dest-(2*m_nodes),
+ routing_table_entry, link_latency, link_weight, bw_multiplier,
+ isReconfiguration);
+ }
}
-void Topology::printStats(std::ostream& out) const
+void
+Topology::printStats(std::ostream& out) const
{
for (int cntrl = 0; cntrl < m_controller_vector.size(); cntrl++) {
- m_controller_vector[cntrl]->printStats(out);
+ m_controller_vector[cntrl]->printStats(out);
}
}
-void Topology::clearStats()
+void
+Topology::clearStats()
{
for (int cntrl = 0; cntrl < m_controller_vector.size(); cntrl++) {
m_controller_vector[cntrl]->clearStats();
}
}
-void Topology::printConfig(std::ostream& out) const
+void
+Topology::printConfig(std::ostream& out) const
{
- using namespace std;
-
- if (m_print_config == false) return;
-
- assert(m_component_latencies.size() > 0);
-
- out << "--- Begin Topology Print ---" << endl;
- out << endl;
- out << "Topology print ONLY indicates the _NETWORK_ latency between two machines" << endl;
- out << "It does NOT include the latency within the machines" << endl;
- out << endl;
- for (int m=0; m<MachineType_NUM; m++) {
- for (int i=0; i<MachineType_base_count((MachineType)m); i++) {
- MachineID cur_mach = {(MachineType)m, i};
- out << cur_mach << " Network Latencies" << endl;
- for (int n=0; n<MachineType_NUM; n++) {
- for (int j=0; j<MachineType_base_count((MachineType)n); j++) {
- MachineID dest_mach = {(MachineType)n, j};
- if (cur_mach != dest_mach) {
- int link_latency = m_component_latencies[MachineType_base_number((MachineType)m)+i][MachineType_base_number(MachineType_NUM)+MachineType_base_number((MachineType)n)+j];
- int intermediate_switches = m_component_inter_switches[MachineType_base_number((MachineType)m)+i][MachineType_base_number(MachineType_NUM)+MachineType_base_number((MachineType)n)+j];
- out << " " << cur_mach << " -> " << dest_mach << " net_lat: "
- << link_latency+intermediate_switches << endl; // NOTE switches are assumed to have single cycle latency
- }
+ using namespace std;
+
+ if (m_print_config == false)
+ return;
+
+ assert(m_component_latencies.size() > 0);
+
+ out << "--- Begin Topology Print ---" << endl
+ << endl
+ << "Topology print ONLY indicates the _NETWORK_ latency between two "
+ << "machines" << endl
+ << "It does NOT include the latency within the machines" << endl
+ << endl;
+
+ for (int m = 0; m < MachineType_NUM; m++) {
+ int i_end = MachineType_base_count((MachineType)m);
+ for (int i = 0; i < i_end; i++) {
+ MachineID cur_mach = {(MachineType)m, i};
+ out << cur_mach << " Network Latencies" << endl;
+ for (int n = 0; n < MachineType_NUM; n++) {
+ int j_end = MachineType_base_count((MachineType)n);
+ for (int j = 0; j < j_end; j++) {
+ MachineID dest_mach = {(MachineType)n, j};
+ if (cur_mach == dest_mach)
+ continue;
+
+ int src = MachineType_base_number((MachineType)m) + i;
+ int dst = MachineType_base_number(MachineType_NUM) +
+ MachineType_base_number((MachineType)n) + j;
+ int link_latency = m_component_latencies[src][dst];
+ int intermediate_switches =
+ m_component_inter_switches[src][dst];
+
+ // NOTE switches are assumed to have single
+ // cycle latency
+ out << " " << cur_mach << " -> " << dest_mach
+ << " net_lat: "
+ << link_latency + intermediate_switches << endl;
+ }
+ }
+ out << endl;
}
- }
- out << endl;
}
- }
- out << "--- End Topology Print ---" << endl;
+ out << "--- End Topology Print ---" << endl;
}
-/**************************************************************************/
-
// The following all-pairs shortest path algorithm is based on the
// discussion from Cormen et al., Chapter 26.1.
-
-static void extend_shortest_path(Matrix& current_dist, Matrix& latencies, Matrix& inter_switches)
+void
+extend_shortest_path(Matrix& current_dist, Matrix& latencies,
+ Matrix& inter_switches)
{
- bool change = true;
- int nodes = current_dist.size();
-
- while (change) {
- change = false;
- for (int i=0; i<nodes; i++) {
- for (int j=0; j<nodes; j++) {
- int minimum = current_dist[i][j];
- int previous_minimum = minimum;
- int intermediate_switch = -1;
- for (int k=0; k<nodes; k++) {
- minimum = min(minimum, current_dist[i][k] + current_dist[k][j]);
- if (previous_minimum != minimum) {
- intermediate_switch = k;
- inter_switches[i][j] = inter_switches[i][k] + inter_switches[k][j] + 1;
- }
- previous_minimum = minimum;
+ bool change = true;
+ int nodes = current_dist.size();
+
+ while (change) {
+ change = false;
+ for (int i = 0; i < nodes; i++) {
+ for (int j = 0; j < nodes; j++) {
+ int minimum = current_dist[i][j];
+ int previous_minimum = minimum;
+ int intermediate_switch = -1;
+ for (int k = 0; k < nodes; k++) {
+ minimum = min(minimum,
+ current_dist[i][k] + current_dist[k][j]);
+ if (previous_minimum != minimum) {
+ intermediate_switch = k;
+ inter_switches[i][j] =
+ inter_switches[i][k] +
+ inter_switches[k][j] + 1;
+ }
+ previous_minimum = minimum;
+ }
+ if (current_dist[i][j] != minimum) {
+ change = true;
+ current_dist[i][j] = minimum;
+ assert(intermediate_switch >= 0);
+ assert(intermediate_switch < latencies[i].size());
+ latencies[i][j] = latencies[i][intermediate_switch] +
+ latencies[intermediate_switch][j];
+ }
+ }
}
- if (current_dist[i][j] != minimum) {
- change = true;
- current_dist[i][j] = minimum;
- assert(intermediate_switch >= 0);
- assert(intermediate_switch < latencies[i].size());
- latencies[i][j] = latencies[i][intermediate_switch] + latencies[intermediate_switch][j];
- }
- }
}
- }
}
-static Matrix shortest_path(const Matrix& weights, Matrix& latencies, Matrix& inter_switches)
+Matrix
+shortest_path(const Matrix& weights, Matrix& latencies, Matrix& inter_switches)
{
- Matrix dist = weights;
- extend_shortest_path(dist, latencies, inter_switches);
- return dist;
+ Matrix dist = weights;
+ extend_shortest_path(dist, latencies, inter_switches);
+ return dist;
}
-static bool link_is_shortest_path_to_node(SwitchID src, SwitchID next, SwitchID final,
- const Matrix& weights, const Matrix& dist)
+bool
+link_is_shortest_path_to_node(SwitchID src, SwitchID next, SwitchID final,
+ const Matrix& weights, const Matrix& dist)
{
- return (weights[src][next] + dist[next][final] == dist[src][final]);
+ return weights[src][next] + dist[next][final] == dist[src][final];
}
-static NetDest shortest_path_to_node(SwitchID src, SwitchID next,
- const Matrix& weights, const Matrix& dist)
+NetDest
+shortest_path_to_node(SwitchID src, SwitchID next, const Matrix& weights,
+ const Matrix& dist)
{
- NetDest result;
- int d = 0;
- int machines;
- int max_machines;
-
- machines = MachineType_NUM;
- max_machines = MachineType_base_number(MachineType_NUM);
-
- for (int m=0; m<machines; m++) {
- for (int i=0; i<MachineType_base_count((MachineType)m); i++) {
- // we use "d+max_machines" below since the "destination" switches for the machines are numbered
- // [MachineType_base_number(MachineType_NUM)...2*MachineType_base_number(MachineType_NUM)-1]
- // for the component network
- if (link_is_shortest_path_to_node(src, next,
- d+max_machines,
- weights, dist)) {
- MachineID mach = {(MachineType)m, i};
- result.add(mach);
- }
- d++;
+ NetDest result;
+ int d = 0;
+ int machines;
+ int max_machines;
+
+ machines = MachineType_NUM;
+ max_machines = MachineType_base_number(MachineType_NUM);
+
+ for (int m = 0; m < machines; m++) {
+ for (int i = 0; i < MachineType_base_count((MachineType)m); i++) {
+ // we use "d+max_machines" below since the "destination"
+ // switches for the machines are numbered
+ // [MachineType_base_number(MachineType_NUM)...
+ // 2*MachineType_base_number(MachineType_NUM)-1] for the
+ // component network
+ if (link_is_shortest_path_to_node(src, next, d + max_machines,
+ weights, dist)) {
+ MachineID mach = {(MachineType)m, i};
+ result.add(mach);
+ }
+ d++;
+ }
}
- }
- DEBUG_MSG(NETWORK_COMP, MedPrio, "returning shortest path");
- DEBUG_EXPR(NETWORK_COMP, MedPrio, (src-(2*max_machines)));
- DEBUG_EXPR(NETWORK_COMP, MedPrio, (next-(2*max_machines)));
- DEBUG_EXPR(NETWORK_COMP, MedPrio, src);
- DEBUG_EXPR(NETWORK_COMP, MedPrio, next);
- DEBUG_EXPR(NETWORK_COMP, MedPrio, result);
- DEBUG_NEWLINE(NETWORK_COMP, MedPrio);
+ DEBUG_MSG(NETWORK_COMP, MedPrio, "returning shortest path");
+ DEBUG_EXPR(NETWORK_COMP, MedPrio, (src-(2*max_machines)));
+ DEBUG_EXPR(NETWORK_COMP, MedPrio, (next-(2*max_machines)));
+ DEBUG_EXPR(NETWORK_COMP, MedPrio, src);
+ DEBUG_EXPR(NETWORK_COMP, MedPrio, next);
+ DEBUG_EXPR(NETWORK_COMP, MedPrio, result);
+ DEBUG_NEWLINE(NETWORK_COMP, MedPrio);
- return result;
+ return result;
}
Topology *