22 class WeightMigration;
23 class MigrationTimers;
32 class Ngraph :
protected PNgraph {
37 friend Ngraph* createEmptyGraph();
46 void constructVerts(
bool isHG,
47 std::vector<gid_t>& verts,
48 std::vector<wgt_t>& weights);
49 void constructVerts(
bool isHG, lid_t num_verts,
50 gid_t* verts, wgt_t* weights = NULL);
59 etype constructEdges(std::vector<gid_t>& edge_ids,
60 std::vector<lid_t>& degs,
61 std::vector<gid_t>& pins_to_verts,
62 std::vector<wgt_t>& e_weights);
63 etype constructEdges(gid_t num_edges, gid_t* edge_ids,
64 lid_t* degs, gid_t* pins_to_verts,
65 wgt_t* e_weights = NULL);
71 void constructGhosts(std::unordered_map<gid_t,part_t>& owns);
72 void constructGhosts(lid_t num_ghosts, gid_t* vert_ids, part_t* owns);
85 void constructGraph(
bool isHG,
86 std::vector<gid_t>& verts,
87 std::vector<wgt_t>& weights,
88 std::vector<gid_t>& edge_ids,
89 std::vector<lid_t>& degs,
90 std::vector<gid_t>& pins_to_verts,
91 std::unordered_map<gid_t,part_t>& owns);
95 void makeUndirectedGraph();
102 void removeEdges(etype t);
105 PNgraph* publicize() {
return this;}
114 void saveToFile(
const char* prefix);
121 void loadFromFile(
const char* prefix);
128 gid_t numGlobalVtxs()
const {
return num_global_verts;}
131 gid_t numGlobalEdges(etype t=0)
const {
return num_global_edges[t];}
134 gid_t numGlobalPins(etype t=0)
const {
return num_global_pins[t];}
136 bool isHyper()
const {
return isHyperGraph;}
141 lid_t numLocalVtxs()
const {
return num_local_verts;}
143 lid_t numGhostVtxs()
const {
return num_ghost_verts;}
145 lid_t numTotalVtxs()
const {
return num_local_verts+num_ghost_verts;}
147 int numEdgeTypes()
const {
return num_types;}
150 lid_t numLocalEdges(etype t=0)
const {
return num_local_edges[t];}
153 lid_t numLocalPins(etype t=0)
const {
return num_local_pins[t];}
162 wgt_t weight(GraphVertex* vtx)
const;
166 bool hasCoords()
const;
171 const coord_t& coord(GraphVertex* vtx)
const;
175 void setCoords(coord_t* cs);
179 void setWeights(wgt_t* wgts);
184 part_t owner(GraphVertex* vtx)
const;
186 part_t originalOwner(GraphVertex* vtx)
const;
187 void setOriginalOwners();
188 void setOriginalOwners(std::vector<part_t>&);
189 void resetOwnership();
190 void resetPartition();
196 void getResidence(GraphEdge* e,Peers& residence)
const;
202 bool isResidentOn(GraphEdge* e,part_t peer)
const;
207 bool isCut(GraphEdge* e)
const;
212 lid_t localID(GraphVertex* vtx)
const;
217 gid_t globalID(GraphVertex* vtx)
const;
219 GraphVertex* find(GraphVertex* vtx)
const;
228 double weight(GraphEdge* edge)
const;
233 lid_t localID(GraphEdge* e)
const;
238 gid_t globalID(GraphEdge* e)
const;
240 lid_t u(lid_t,etype t =0)
const;
246 GraphVertex* u(GraphEdge* edge)
const;
251 GraphVertex* v(GraphEdge* edge)
const;
256 void setEdgeWeights(std::vector<wgt_t>& wgts, etype t);
266 lid_t degree(GraphVertex* vtx,etype t=0)
const;
272 EdgeIterator* edges(GraphVertex* vtx,etype t=0)
const;
279 GraphIterator* adjacent(GraphVertex* vtx, etype t=0)
const;
285 lid_t degree(GraphEdge* edge)
const;
290 PinIterator* pins(GraphEdge* edge)
const;
296 void create_vev_adjacency(etype t,
bool compress =
true);
301 void create_eve_adjacency(etype t,
bool compress =
true);
309 VEVIterator* vev_begin(GraphVertex* vtx, etype t=0)
const;
310 VEVIterator* vev_end(GraphVertex* vtx, etype t=0)
const;
316 EVEIterator* eve_begin(GraphEdge* edge)
const;
317 EVEIterator* eve_end(GraphEdge* edge)
const;
327 GraphTag* createIntTag(etype t=VTX_TYPE);
332 GraphTag* createDoubleTag(etype t=VTX_TYPE);
337 GraphTag* createLongTag(etype t=VTX_TYPE);
339 typedef int (*IntGhostTag)(Ngraph*, GraphVertex*);
340 GraphTag* createIntGhostTag(IntGhostTag callback);
341 typedef double (*DoubleGhostTag)(Ngraph*, GraphVertex*);
342 GraphTag* createDoubleGhostTag(DoubleGhostTag callback);
343 typedef long (*LongGhostTag)(Ngraph*, GraphVertex*);
344 GraphTag* createLongGhostTag(LongGhostTag callback);
348 void destroyTag(GraphTag* t);
354 int getIntTag(GraphTag* tag,GraphVertex* v)
const;
360 int getIntTag(GraphTag* tag,GraphEdge* e)
const;
366 double getDoubleTag(GraphTag* tag,GraphVertex* v)
const;
372 double getDoubleTag(GraphTag* tag,GraphEdge* e)
const;
378 long getLongTag(GraphTag* tag,GraphVertex* v)
const;
384 long getLongTag(GraphTag* tag,GraphEdge* e)
const;
390 void setIntTag(GraphTag* tag,GraphVertex* v,
int val);
396 void setIntTag(GraphTag* tag,GraphEdge* e,
int val);
402 void setDoubleTag(GraphTag* tag,GraphVertex* v,
double val);
408 void setDoubleTag(GraphTag* tag,GraphEdge* e,
double val);
414 void setLongTag(GraphTag* tag,GraphVertex* v,
long val);
420 void setLongTag(GraphTag* tag,GraphEdge* e,
long val);
429 void shareTag(GraphTag* tag, etype t=VTX_TYPE);
437 VertexIterator* begin()
const;
441 GhostIterator* beginGhosts()
const;
443 GraphVertex* findGID(gid_t gid)
const;
449 EdgeIterator* begin(etype t)
const;
454 GraphVertex* iterate(VertexIterator*& vitr)
const;
459 GraphVertex* iterate(GhostIterator*& vitr)
const;
461 GraphVertex* iterate(VEVIterator*& vevItr)
const;
466 GraphEdge* iterate(EdgeIterator*& eitr)
const;
471 GraphVertex* iterate(PinIterator*& pitr)
const;
476 GraphVertex* iterate(GraphIterator*& gitr)
const;
481 GraphEdge* edge(GraphIterator* gitr)
const;
482 GraphEdge* iterate(EVEIterator*& eveItr)
const;
487 void destroy(EdgeIterator* eitr)
const;
492 void destroy(PinIterator* eitr)
const;
496 void destroy(GraphIterator* gitr)
const;
504 bool isEqual(GraphVertex* vtx1,GraphVertex* vtx2)
const;
509 bool isEqual(GraphEdge* edge1,GraphEdge* edge2)
const;
517 virtual PartitionMap* getPartition();
518 WeightPartitionMap* getWeightPartition();
521 void migrate(Migration* plan, MigrationTimers* mt = NULL);
522 void migrate(WeightMigration* plan, MigrationTimers* mt = NULL);
524 void repartition(part_t* partition);
526 void changeOwners(
int* newRanks);
528 void printStats()
const;
531 GraphTag* ghost_weights;
535 Ngraph(
const Ngraph&) {
throw std::runtime_error(
"Copying Ngraph not supported");}
536 Ngraph& operator=(
const Ngraph&) {
537 throw std::runtime_error(
"Assignment of Ngraph not supported");
546 etype addEdgeType() {assert(num_types!=MAX_TYPES);
return num_types++;}
552 void makeEdgeArray(etype t,
int count);
559 void setEdge(lid_t l,gid_t g,wgt_t w,etype t);
565 void updateGhostOwners(Migration*);
566 void sendVertex(GraphVertex*, part_t);
567 void recvVertex(std::vector<gid_t>&,std::vector<wgt_t>&,
568 std::vector<part_t>&);
569 void sendCoord(GraphVertex*, part_t);
570 void recvCoord(coord_t*,lid_t& size);
571 void sendEdges(Migration*,std::unordered_set<GraphEdge*>&);
572 void recvEdges(std::unordered_set<gid_t>&,std::vector<gid_t>&,
573 std::vector<wgt_t>&,std::vector<lid_t>&,
574 std::vector<gid_t>&,std::unordered_map<gid_t,part_t>&,
577 WeightPartitionMap wp_map;
583 Ngraph* createEmptyGraph();
588 void destroyGraph(Ngraph* g);
593 bool checkValidity(Ngraph* g);
595 void writeVTK(Ngraph* g,
const char* prefix,GraphTag* tag=NULL,etype t=NO_TYPE);