00001
00015
00016 #include "ObjGraph.h"
00017
00018 static const double alpha = 30.e-6;
00019 static const double beta = 3.e-9;
00020
00021 ObjGraph::ObjGraph(int count, BaseLB::LDStats* _stats)
00022 {
00023 stats = _stats;
00024
00025
00026
00027
00028
00029 for(int i=0; i < hash_max; i++)
00030 node_table[i] = 0;
00031
00032 nodelist = 0;
00033
00034
00035 n_objs = stats->n_objs;
00036 n_edges = 0;
00037
00038 int index;
00039 for(index = 0; index < stats->n_comm; index++) {
00040 const LDCommData newedgedata = stats->commData[index];
00041
00042
00043 if (!newedgedata.from_proc() && newedgedata.recv_type() == LD_OBJ_MSG)
00044 n_edges++;
00045 }
00046 nodelist = new Node[n_objs];
00047 edgelist = new Edge[n_edges];
00048
00049
00050 int cur_node = 0;
00051 int cur_edge = 0;
00052
00053 for(index = 0; index < stats->n_objs; index++) {
00054 LDObjData &odata = stats->objData[index];
00055 if(cur_node >= n_objs)
00056 CkPrintf("Error %d %d\n",cur_node,n_objs);
00057 Node* thisnode = nodelist + cur_node;
00058 thisnode->node_index = cur_node;
00059 thisnode->proc = stats->from_proc[index];
00060 thisnode->index = index;
00061 thisnode->n_out = 0;
00062 thisnode->outEdge = 0;
00063 thisnode->n_in = 0;
00064 thisnode->inEdge = 0;
00065 cur_node++;
00066 const int hashval = calc_hashval(odata.omID(),
00067 odata.objID());
00068 thisnode->nxt_hash = node_table[hashval];
00069 node_table[hashval] = thisnode;
00070 }
00071
00072
00073 for(index=0; index < stats->n_comm; index++) {
00074 LDCommData &newedgedata = stats->commData[index];
00075
00076
00077 if (newedgedata.from_proc() || newedgedata.recv_type()!=LD_OBJ_MSG)
00078 continue;
00079
00080 if(cur_edge >= n_edges)
00081 CkPrintf("Error %d %d\n",cur_edge,n_edges);
00082
00083 Edge* thisedge = edgelist + cur_edge;
00084 thisedge->edge_index = cur_edge;
00085 thisedge->index = index;
00086 thisedge->from_node = -1;
00087 thisedge->to_node = -1;
00088 thisedge->nxt_out = 0;
00089 thisedge->nxt_in = 0;
00090 cur_edge++;
00091 }
00092 if(cur_node != n_objs)
00093 CkPrintf("did not fill table %d %d\n",cur_node,n_objs);
00094
00095 if(cur_edge != n_edges)
00096 CkPrintf("did not fill edge table %d %d\n",cur_edge,n_edges);
00097
00098
00099 for(cur_edge = 0; cur_edge < n_edges; cur_edge++) {
00100 Edge* newedge = edgelist + cur_edge;
00101 int index = newedge->index;
00102 const LDCommData newedgedata = stats->commData[index];
00103
00104 Node* from_node = find_node(newedgedata.sender);
00105 if (from_node == 0) {
00106 if (!_lb_args.ignoreBgLoad() && _stats->complete_flag)
00107 CkPrintf("ObjGraph::find_node: Didn't locate from node match!\n");
00108 continue;
00109 }
00110
00111 Node* to_node = find_node(newedgedata.receiver.get_destObj());
00112 if (to_node == 0) {
00113 if (!_lb_args.migObjOnly() && _stats->complete_flag)
00114 CkPrintf("ObjGraph::find_node: Didn't locate to node match!\n");
00115 continue;
00116 }
00117
00118
00119 newedge->from_node = from_node->node_index;
00120 newedge->to_node = to_node->node_index;
00121 newedge->nxt_out = from_node->outEdge;
00122 from_node->outEdge = newedge;
00123 from_node->n_out++;
00124 newedge->nxt_in = to_node->inEdge;
00125 to_node->inEdge = newedge;
00126 to_node->n_in++;
00127 }
00128 }
00129
00130 ObjGraph::~ObjGraph()
00131 {
00132 delete [] nodelist;
00133 delete [] edgelist;
00134 }
00135
00136 double ObjGraph::EdgeWeight(Edge* e) {
00137 LDCommData commData = stats->commData[e->index];
00138 return commData.messages * alpha + commData.bytes * beta;
00139 }
00140
00141 int ObjGraph::calc_hashval(LDOMid omid, CmiUInt8 id)
00142 {
00143 int hashval = omid.id.idx + (int)id;
00144 hashval %= hash_max;
00145 return hashval;
00146 }
00147
00148 ObjGraph::Node* ObjGraph::find_node(const LDObjKey &edge_key)
00149 {
00150 const LDOMid &edge_omid = edge_key.omID();
00151 const CmiUInt8 &edge_id = edge_key.objID();
00152 const int from_hashval = calc_hashval(edge_omid,edge_id);
00153
00154 Node* from_node = node_table[from_hashval];
00155
00156 while (from_node != 0) {
00157 const LDOMid omid =
00158 stats->objData[from_node->index].omID();
00159 const CmiUInt8 objid =
00160 stats->objData[from_node->index].objID();
00161
00162 if (LDOMidEqual(omid,edge_omid) && objid == edge_id )
00163 break;
00164 from_node = from_node->nxt_hash;
00165 }
00166
00167 return from_node;
00168 }
00169
00170
00171
00172
00173