mt-Metis
graph.h
Go to the documentation of this file.
1 
13 #ifndef MTMETIS_GRAPH_H
14 #define MTMETIS_GRAPH_H
15 
16 
17 
18 
19 #include "base.h"
20 #include "ctrl.h"
21 
22 
23 
24 
25 /******************************************************************************
26 * TYPES ***********************************************************************
27 ******************************************************************************/
28 
29 
30 typedef struct graphdist_type {
31  tid_type nthreads;
32  vtx_type mask;
33  int shift;
34  vtx_type offset;
36 
37 
38 typedef struct graph_type {
39  /* global counts */
40  vtx_type nvtxs;
41  vtx_type gnvtxs;
42  adj_type nedges;
43  /* distribution information */
44  dlthread_comm_t comm;
45  graphdist_type dist;
46  /* pre partitioning info */
47  pid_type ** group;
48  pid_type ngroup;
49  /* distributed graph structure */
50  vtx_type * mynvtxs;
51  adj_type * mynedges;
52  adj_type ** xadj;
53  wgt_type ** vwgt;
54  vtx_type ** adjncy;
55  wgt_type ** adjwgt;
56  /* graph info */
57  int uniformvwgt;
58  int uniformadjwgt;
59  vtx_type * nislands;
60  /* coarsening info */
61  size_t level;
62  vtx_type ** cmap;
63  /* partition information */
64  wgt_type * pwgts;
65  pid_type ** where;
66  struct kwinfo_type * kwinfo;
67  struct esinfo_type * esinfo;
68  struct vsinfo_type * vsinfo;
69  /* total weight */
70  twgt_type tvwgt, tadjwgt;
71  real_type invtvwgt;
72  /* aliasing */
73  vtx_type ** rename;
74  vtx_type ** label;
75  /* metrics */
76  wgt_type mincut, minsep;
77  vtx_type minvol;
78  /* "To free, or not free" */
79  int free_xadj, free_vwgt, free_vsize, free_adjncy, free_adjwgt;
80  /* graphs in the heirarchy */
81  struct graph_type *coarser, *finer;
82 } graph_type;
83 
84 
85 
86 
87 /******************************************************************************
88 * SERIAL FUNCTION PROTOTYPES **************************************************
89 ******************************************************************************/
90 
91 
92 #define graph_create MTMETIS_graph_create
93 
101  tid_type nthreads);
102 
103 
104 #define graph_setup MTMETIS_graph_setup
105 
118  vtx_type * nvtxs,
119  adj_type ** xadj,
120  vtx_type ** adjncy,
121  wgt_type ** adjwgt,
122  wgt_type ** vwgt,
123  tid_type nthreads);
124 
125 
126 #define graph_distribute MTMETIS_graph_distribute
127 
141  int dist,
142  vtx_type nvtxs,
143  adj_type const * xadj,
144  vtx_type const * adjncy,
145  wgt_type const * vwgt,
146  wgt_type const * adjwgt,
147  tid_type nthreads);
148 
149 
150 #define graph_gather MTMETIS_graph_gather
151 
162 void graph_gather(
163  graph_type const * graph,
164  adj_type ** r_xadj,
165  vtx_type ** r_adjncy,
166  wgt_type ** r_vwgt,
167  wgt_type ** r_adjwgt,
168  vtx_type ** r_voff);
169 
170 
171 #define graph_setup_coarse MTMETIS_graph_setup_coarse
172 
182  graph_type * graph,
183  vtx_type * cnvtxs);
184 
185 
186 #define graph_setup_twgts MTMETIS_graph_setup_twgts
187 
192 void graph_setup_twgts(
193  graph_type * graph);
194 
195 
196 #define graph_alloc_partmemory MTMETIS_graph_alloc_partmemory
197 
204  ctrl_type * ctrl,
205  graph_type * graph);
206 
207 #define graph_free MTMETIS_graph_free
208 
213 void graph_free(
214  graph_type * graph);
215 
216 
217 #define graph_free_rdata MTMETIS_graph_free_rdata
218 
223 void graph_free_rdata(
224  graph_type * graph);
225 
226 
227 #define graph_imbalance MTMETIS_graph_imbalance
228 
237 double graph_imbalance(
238  graph_type const * graph,
239  pid_type nparts,
240  real_type const * pijbm);
241 
242 
243 #define graph_imbalance_diff MTMETIS_graph_imbalance_diff
244 
255 double graph_imbalance_diff(
256  graph_type const * const graph,
257  pid_type const nparts,
258  real_type const * const pijbm,
259  real_type const ubfactor);
260 
261 
262 #define graph_cut MTMETIS_graph_cut
263 
271 wgt_type graph_cut(
272  graph_type const * graph,
273  pid_type const * const * where);
274 
275 
276 #define graph_isbalanced MTMETIS_graph_isbalanced
277 
287 int graph_isbalanced(
288  ctrl_type const * ctrl,
289  graph_type const * graph,
290  real_type ffactor);
291 
292 
293 #define graph_readjust_memory MTMETIS_graph_readjust_memory
294 
301  graph_type * const graph,
302  adj_type adjsize);
303 
304 
305 #define graph_extract_halves MTMETIS_graph_extract_halves
306 
318  graph_type * graph,
319  pid_type const * const * where,
320  graph_type ** halves);
321 
322 
323 #define graph_size MTMETIS_graph_size
324 
331 size_t graph_size(
332  graph_type const * graph);
333 
334 
335 #define graph_calc_dist MTMETIS_graph_calc_dist
336 
343 void graph_calc_dist(
344  vtx_type maxnvtxs,
345  tid_type nthreads,
346  graphdist_type * dist);
347 
348 
349 
350 
351 /******************************************************************************
352 * PARALLEL FUNCTION PROTOTYPES ************************************************
353 ******************************************************************************/
354 
355 
356 #define par_graph_create MTMETIS_par_graph_create
357 
365  dlthread_comm_t comm);
366 
367 
368 #define par_graph_setup MTMETIS_par_graph_setup
369 
382  vtx_type nvtxs,
383  adj_type * xadj,
384  vtx_type * adjncy,
385  wgt_type * adjwgt,
386  wgt_type * vwgt,
387  dlthread_comm_t comm);
388 
389 
390 #define par_graph_gather MTMETIS_par_graph_gather
391 
402 void par_graph_gather(
403  graph_type const * graph,
404  adj_type ** r_xadj,
405  vtx_type ** r_adjncy,
406  wgt_type ** r_vwgt,
407  wgt_type ** r_adjwgt,
408  vtx_type * r_voff);
409 
410 
411 #define par_graph_shuffle MTMETIS_par_graph_shuffle
412 
421 void par_graph_shuffle(
422  ctrl_type * ctrl,
423  graph_type * graph,
424  pid_type const * const * where,
425  int wgts);
426 
427 
428 #define par_graph_setup_coarse MTMETIS_par_graph_setup_coarse
429 
439  graph_type * const graph,
440  vtx_type cnvtxs);
441 
442 
443 #define par_graph_setup_twgts MTMETIS_par_graph_setup_twgts
444 
450  graph_type * graph);
451 
452 
453 #define par_graph_alloc_partmemory MTMETIS_par_graph_alloc_partmemory
454 
461  ctrl_type * ctrl,
462  graph_type * graph);
463 
464 
465 #define par_graph_free MTMETIS_par_graph_free
466 
471 void par_graph_free(
472  graph_type * graph);
473 
474 
475 #define par_graph_free_rdata MTMETIS_par_graph_free_rdata
476 
482  graph_type * graph);
483 
484 
485 #define par_graph_readjust_memory MTMETIS_par_graph_readjust_memory
486 
493  graph_type * const graph,
494  adj_type adjsize);
495 
496 
497 #define par_graph_extract_halves MTMETIS_par_graph_extract_halves
498 
511 tid_type par_graph_extract_halves(
512  graph_type * graph,
513  pid_type const * const * where,
514  graph_type ** halves);
515 
516 
517 #define par_graph_extract_boundary MTMETIS_par_graph_extract_boundary
518 
533  ctrl_type const * ctrl,
534  graph_type const * graph,
535  vtx_iset_t const * bnd);
536 
537 
538 #define par_graph_extract_separator MTMETIS_par_graph_extract_separator
539 
553  ctrl_type const * ctrl,
554  graph_type const * graph,
555  vtx_iset_t const * bnd);
556 
557 
558 #define par_graph_extract_aseparator MTMETIS_par_graph_extract_aseparator
559 
573  ctrl_type const * ctrl,
574  graph_type const * graph,
575  vtx_iset_t const * bnd);
576 
577 
578 #define par_graph_build_radj MTMETIS_par_graph_build_radj
579 
586 adj_type * par_graph_build_radj(
587  graph_type const * graph);
588 
589 
590 #define par_graph_contract MTMETIS_par_graph_contract
591 
602 void par_graph_contract(
603  ctrl_type * ctrl,
604  graph_type * graph,
605  vtx_type const cnvtxs,
606  vtx_type const * const * gmatch,
607  vtx_type const * fcmap);
608 
609 
610 #define par_graph_intext_vtx MTMETIS_par_graph_intext_vtx
611 
620  graph_type const * const graph,
621  vtx_type * const r_nint,
622  vtx_type * const r_next);
623 
624 
625 #define par_graph_cut MTMETIS_par_graph_cut
626 
634 wgt_type par_graph_cut(
635  graph_type const * graph,
636  pid_type const * const * where);
637 
638 
639 #define par_graph_removeislands MTMETIS_par_graph_removeislands
640 
647  ctrl_type * ctrl,
648  graph_type * graph);
649 
650 
651 #define par_graph_restoreislands MTMETIS_par_graph_restoreislands
652 
661  ctrl_type * ctrl,
662  graph_type * graph,
663  pid_type * const * gwhere);
664 
665 
666 #define par_graph_extract_parts MTMETIS_par_graph_extract_parts
667 
680  graph_type * const graph,
681  pid_type const * const * const gwhere,
682  pid_type const nparts,
683  graph_type ** const parts);
684 
685 
686 #define par_graph_distribute MTMETIS_par_graph_distribute
687 
701  int distribution,
702  vtx_type nvtxs,
703  adj_type const * xadj,
704  vtx_type const * adjncy,
705  wgt_type const * vwgt,
706  wgt_type const * adjwgt,
707  dlthread_comm_t comm);
708 
709 
710 
711 #endif
Type and function prototypes for the ctrl structure.
Definition: graph.h:38
void par_graph_restoreislands(ctrl_type *ctrl, graph_type *graph, pid_type *const *gwhere)
Restore island vertices and parameters to a graph.
Definition: graph.c:3105
Definition: ctrl.h:48
void par_graph_removeislands(ctrl_type *ctrl, graph_type *graph)
Remove island vertices from a graph and adjust parameters.
Definition: graph.c:2946
graph_type * par_graph_extract_separator(ctrl_type const *ctrl, graph_type const *graph, vtx_iset_t const *bnd)
Extract a subgraph consisting only the current separator and two super vertices representing each hal...
wgt_type par_graph_cut(graph_type const *graph, pid_type const *const *where)
Compute the edgecut of a partitioning in parallel.
Definition: graph.c:2886
void graph_gather(graph_type const *graph, adj_type **r_xadj, vtx_type **r_adjncy, wgt_type **r_vwgt, wgt_type **r_adjwgt, vtx_type **r_voff)
Gather a copy of the graph to each thread. Alias is private to each thread where the other three arra...
Definition: graph.c:1664
void par_graph_intext_vtx(graph_type const *const graph, vtx_type *const r_nint, vtx_type *const r_next)
Count the number of internal and external (interface) vertices owned by this thread.
Definition: graph.c:2846
void par_graph_free_rdata(graph_type *graph)
Free partition/refinement data associated with a graph.
Definition: graph.c:2310
void par_graph_free(graph_type *graph)
Free a graph structure and its associated memory.
Definition: graph.c:2276
int graph_isbalanced(ctrl_type const *ctrl, graph_type const *graph, real_type ffactor)
Check if a partitioning of a graph is balanced within the given constraint.
Definition: graph.c:2044
void graph_calc_dist(vtx_type maxnvtxs, tid_type nthreads, graphdist_type *dist)
Configure the distribution structure.
Definition: graph.c:2130
Definition: graph.h:30
graph_type * par_graph_create(dlthread_comm_t comm)
Allocate and initialize a graph structure.
Definition: graph.c:2153
void par_graph_setup_twgts(graph_type *graph)
Calculate and save the twgts of a new graph.
Definition: graph.c:2239
void par_graph_shuffle(ctrl_type *ctrl, graph_type *graph, pid_type const *const *where, int wgts)
Shuffle the vertices in a graph such that the partition matches the owning thread.
Definition: graph.c:2456
Definition: esinfo.h:39
void graph_extract_halves(graph_type *graph, pid_type const *const *where, graph_type **halves)
Pull out partition 0 and partition 1 from a vertex separated graph or edge bisected graph...
void graph_readjust_memory(graph_type *const graph, adj_type adjsize)
Re-adjust the memory used the by edge arrays of a graph.
Definition: graph.c:2054
graph_type * graph_create(tid_type nthreads)
Allocate and initialize a graph structure.
Definition: graph.c:1437
graph_type * graph_setup(vtx_type *nvtxs, adj_type **xadj, vtx_type **adjncy, wgt_type **adjwgt, wgt_type **vwgt, tid_type nthreads)
Setup a graph structure given this threads parts of the graph.
Definition: graph.c:1450
void graph_alloc_partmemory(ctrl_type *ctrl, graph_type *graph)
Allocate memory for partition informatin.
Definition: graph.c:1838
graph_type * par_graph_setup(vtx_type nvtxs, adj_type *xadj, vtx_type *adjncy, wgt_type *adjwgt, wgt_type *vwgt, dlthread_comm_t comm)
Setup a graph structure given this threads parts of the graph.
Definition: graph.c:2166
void par_graph_gather(graph_type const *graph, adj_type **r_xadj, vtx_type **r_adjncy, wgt_type **r_vwgt, wgt_type **r_adjwgt, vtx_type *r_voff)
Gather a copy of the graph to each thread. Alias is private to each thread where the other three arra...
Definition: graph.c:2359
double graph_imbalance_diff(graph_type const *const graph, pid_type const nparts, real_type const *const pijbm, real_type const ubfactor)
Compute the amount the load imbalance of the graph violates the constraint.
Definition: graph.c:1959
void graph_free_rdata(graph_type *graph)
Free partition/refinement data associated with a graph.
Definition: graph.c:1890
adj_type * par_graph_build_radj(graph_type const *graph)
Build a reverse adjacency index and store it in graph->radj.
Definition: graph.c:2795
void graph_free(graph_type *graph)
Free a graph structure and its associated memory.
Definition: graph.c:1856
graph_type * par_graph_extract_boundary(ctrl_type const *ctrl, graph_type const *graph, vtx_iset_t const *bnd)
Extract a subgraph exposing the boundary of a bisection, where the size of the boundary is determined...
size_t graph_size(graph_type const *graph)
Determine the amount of memory required to store the graph.
Definition: graph.c:2068
void par_graph_readjust_memory(graph_type *const graph, adj_type adjsize)
Re-adjust the memory used the by edge arrays of a graph.
Base types etc.
graph_type * par_graph_distribute(int distribution, vtx_type nvtxs, adj_type const *xadj, vtx_type const *adjncy, wgt_type const *vwgt, wgt_type const *adjwgt, dlthread_comm_t comm)
Distribute a csr based graph among a set of active threads.
Definition: graph.c:3451
void par_graph_alloc_partmemory(ctrl_type *ctrl, graph_type *graph)
Allocate memory for partition informatin.
Definition: graph.c:2758
graph_type * graph_setup_coarse(graph_type *graph, vtx_type *cnvtxs)
Setup a coarse graph given the fine graph and the number of coarse vertices.
Definition: graph.c:1750
void par_graph_extract_parts(graph_type *const graph, pid_type const *const *const gwhere, pid_type const nparts, graph_type **const parts)
Extract the partitions from a graph. If called with more threads than partitions, the number of threa...
Definition: graph.c:3210
Definition: kwinfo.h:45
graph_type * graph_distribute(int dist, vtx_type nvtxs, adj_type const *xadj, vtx_type const *adjncy, wgt_type const *vwgt, wgt_type const *adjwgt, tid_type nthreads)
Distribute a csr based graph among threads.
Definition: graph.c:1504
wgt_type graph_cut(graph_type const *graph, pid_type const *const *where)
Compute the edgecut of a partitioning.
Definition: graph.c:1983
void graph_setup_twgts(graph_type *graph)
Calculate and save the tvwgts of a new graph.
Definition: graph.c:1800
void par_graph_contract(ctrl_type *ctrl, graph_type *graph, vtx_type const cnvtxs, vtx_type const *const *gmatch, vtx_type const *fcmap)
Create a coarse graph given a matching using hash table to identify edges to be merged.
graph_type * par_graph_setup_coarse(graph_type *const graph, vtx_type cnvtxs)
Setup a coarse graph given the fine graph and the number of coarse vertices.
Definition: graph.c:2699
Definition: vsinfo.h:37
graph_type * par_graph_extract_aseparator(ctrl_type const *ctrl, graph_type const *graph, vtx_iset_t const *bnd)
Extract a subgraph consisting only the current separator and two super vertices representing each hal...
tid_type par_graph_extract_halves(graph_type *graph, pid_type const *const *where, graph_type **halves)
Pull out partition 0 and partition 1 from a vertex separated graph or edge bisected graph...
Definition: graph.c:2778
double graph_imbalance(graph_type const *graph, pid_type nparts, real_type const *pijbm)
Compute the load imbalance of a partitioning.
Definition: graph.c:1936