22 class WeightMigration;
23 class MigrationTimers;
32 class Ngraph :
protected PNgraph {
38 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);
261 void setEdgeWeights(wgt_t wgt, etype t);
271 lid_t degree(GraphVertex* vtx,etype t=0)
const;
277 EdgeIterator* edges(GraphVertex* vtx,etype t=0)
const;
284 GraphIterator* adjacent(GraphVertex* vtx, etype t=0)
const;
290 lid_t degree(GraphEdge* edge)
const;
295 PinIterator* pins(GraphEdge* edge)
const;
301 void create_vev_adjacency(etype t,
bool compress =
true);
306 void create_eve_adjacency(etype t,
bool compress =
true);
314 VEVIterator* vev_begin(GraphVertex* vtx, etype t=0)
const;
315 VEVIterator* vev_end(GraphVertex* vtx, etype t=0)
const;
321 EVEIterator* eve_begin(GraphEdge* edge)
const;
322 EVEIterator* eve_end(GraphEdge* edge)
const;
332 GraphTag* createIntTag(etype t=VTX_TYPE);
337 GraphTag* createDoubleTag(etype t=VTX_TYPE);
342 GraphTag* createLongTag(etype t=VTX_TYPE);
344 typedef int (*IntGhostTag)(Ngraph*, GraphVertex*);
345 GraphTag* createIntGhostTag(IntGhostTag callback);
346 typedef double (*DoubleGhostTag)(Ngraph*, GraphVertex*);
347 GraphTag* createDoubleGhostTag(DoubleGhostTag callback);
348 typedef long (*LongGhostTag)(Ngraph*, GraphVertex*);
349 GraphTag* createLongGhostTag(LongGhostTag callback);
353 void destroyTag(GraphTag* t);
359 int getIntTag(GraphTag* tag,GraphVertex* v)
const;
365 int getIntTag(GraphTag* tag,GraphEdge* e)
const;
371 double getDoubleTag(GraphTag* tag,GraphVertex* v)
const;
377 double getDoubleTag(GraphTag* tag,GraphEdge* e)
const;
383 long getLongTag(GraphTag* tag,GraphVertex* v)
const;
389 long getLongTag(GraphTag* tag,GraphEdge* e)
const;
395 void setIntTag(GraphTag* tag,GraphVertex* v,
int val);
401 void setIntTag(GraphTag* tag,GraphEdge* e,
int val);
407 void setDoubleTag(GraphTag* tag,GraphVertex* v,
double val);
413 void setDoubleTag(GraphTag* tag,GraphEdge* e,
double val);
419 void setLongTag(GraphTag* tag,GraphVertex* v,
long val);
425 void setLongTag(GraphTag* tag,GraphEdge* e,
long val);
434 void shareTag(GraphTag* tag, etype t=VTX_TYPE);
442 VertexIterator* begin()
const;
446 GhostIterator* beginGhosts()
const;
448 GraphVertex* findGID(gid_t gid)
const;
454 EdgeIterator* begin(etype t)
const;
459 GraphVertex* iterate(VertexIterator*& vitr)
const;
464 GraphVertex* iterate(GhostIterator*& vitr)
const;
466 GraphVertex* iterate(VEVIterator*& vevItr)
const;
471 GraphEdge* iterate(EdgeIterator*& eitr)
const;
476 GraphVertex* iterate(PinIterator*& pitr)
const;
481 GraphVertex* iterate(GraphIterator*& gitr)
const;
486 GraphEdge* edge(GraphIterator* gitr)
const;
487 GraphEdge* iterate(EVEIterator*& eveItr)
const;
492 void destroy(EdgeIterator* eitr)
const;
497 void destroy(PinIterator* eitr)
const;
501 void destroy(GraphIterator* gitr)
const;
509 bool isEqual(GraphVertex* vtx1,GraphVertex* vtx2)
const;
514 bool isEqual(GraphEdge* edge1,GraphEdge* edge2)
const;
522 virtual PartitionMap* getPartition();
523 WeightPartitionMap* getWeightPartition();
526 void migrate(Migration* plan, MigrationTimers* mt = NULL);
527 void migrate(WeightMigration* plan, MigrationTimers* mt = NULL);
529 void repartition(part_t* partition);
531 void changeOwners(
int* newRanks);
533 void printStats()
const;
536 GraphTag* ghost_weights;
540 Ngraph(
const Ngraph&) {
throw std::runtime_error(
"Copying Ngraph not supported");}
541 Ngraph& operator=(
const Ngraph&) {
542 throw std::runtime_error(
"Assignment of Ngraph not supported");
551 etype addEdgeType() {assert(num_types!=MAX_TYPES);
return num_types++;}
557 void makeEdgeArray(etype t,
int count);
564 void setEdge(lid_t l,gid_t g,wgt_t w,etype t);
570 void updateGhostOwners(Migration*);
571 void sendVertex(GraphVertex*, part_t);
572 void recvVertex(std::vector<gid_t>&,std::vector<wgt_t>&,
573 std::vector<part_t>&);
574 void sendCoord(GraphVertex*, part_t);
575 void recvCoord(coord_t*,lid_t& size);
576 void sendEdges(Migration*,std::unordered_set<GraphEdge*>&);
577 void recvEdges(std::unordered_set<gid_t>&,std::vector<gid_t>&,
578 std::vector<wgt_t>&,std::vector<lid_t>&,
579 std::vector<gid_t>&,std::unordered_map<gid_t,part_t>&,
582 WeightPartitionMap wp_map;
588 Ngraph* createEmptyGraph();
593 void destroyGraph(Ngraph* g);
598 bool checkValidity(Ngraph* g);
600 void writeVTK(Ngraph* g,
const char* prefix,GraphTag* tag=NULL,etype t=NO_TYPE);