00001 #ifndef SPANNING_TREE_VERTEX
00002 #define SPANNING_TREE_VERTEX
00003
00004 #include "TopoManager.h"
00005 #define __DEBUG_SPANNING_TREE_ 0
00006
00007 namespace topo {
00008
00010 typedef int vtxType;
00011
00019 class SpanningTreeVertex
00020 {
00021 public:
00023 vtxType id;
00025
00027 std::vector<int> X;
00029 std::vector<int> childIndex;
00031 SpanningTreeVertex(const vtxType _id=-1): id(_id) {}
00032
00033 inline bool sameCoordinates(const SpanningTreeVertex &v) const
00034 { return (X == v.X); }
00035
00038 inline friend bool operator== (const SpanningTreeVertex &obj, const vtxType vtxID)
00039 { return (obj.id == vtxID); }
00040
00041 inline friend bool operator== (const vtxType vtxID, const SpanningTreeVertex &obj)
00042 { return (obj.id == vtxID); }
00043
00044 inline friend bool operator< (const SpanningTreeVertex &obj, const vtxType vtxID)
00045 { return (obj.id < vtxID); }
00046
00047 inline friend bool operator< (const vtxType vtxID, const SpanningTreeVertex &obj)
00048 { return (vtxID < obj.id); }
00050
00052 friend std::ostream& operator<< (std::ostream &out, const SpanningTreeVertex &obj)
00053 {
00054 out<<" "<<obj.id;
00055 if (obj.X.size()>0)
00056 {
00057 out<<"("<<obj.X[0];
00058 for (int i=1,cSize=obj.X.size(); i<cSize; i++)
00059 out<<","<<obj.X[i];
00060 out<<") ";
00061 }
00062 return out;
00063 }
00064 };
00065
00066 inline int getProcID(const vtxType vtx) { return vtx; }
00067 inline int getProcID(const SpanningTreeVertex &vtx) { return vtx.id; }
00068
00070 inline int numHops(const SpanningTreeVertex &vtx1, const SpanningTreeVertex &vtx2)
00071 {
00073
00074
00075 return TopoManager::getTopoManager()->getHopsBetweenRanks(getProcID(vtx1), getProcID(vtx2));
00076 }
00077
00079 template <typename Iterator>
00080 inline Iterator pickClosest(const SpanningTreeVertex &parent, const Iterator start, const Iterator end)
00081 {
00083 Iterator itr = start;
00084 Iterator closest = itr++;
00085 int minHops = numHops(parent,*closest);
00087 for (; itr != end; itr++)
00088 {
00089 int hops = numHops(parent,*itr);
00090 if (hops < minHops)
00091 {
00092 closest = itr;
00093 minHops = hops;
00094 }
00095 }
00096 return closest;
00097 }
00098
00099 }
00100
00101 #endif // SPANNING_TREE_VERTEX
00102