File: metis.rst

package info (click to toggle)
boost1.88 1.88.0-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 576,932 kB
  • sloc: cpp: 4,149,234; xml: 136,789; ansic: 35,092; python: 33,910; asm: 5,698; sh: 4,604; ada: 1,681; makefile: 1,633; pascal: 1,139; perl: 1,124; sql: 640; yacc: 478; ruby: 271; java: 77; lisp: 24; csh: 6
file content (320 lines) | stat: -rw-r--r-- 8,635 bytes parent folder | download | duplicates (14)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
.. Copyright (C) 2004-2008 The Trustees of Indiana University.
   Use, modification and distribution is subject to the Boost Software
   License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
   http://www.boost.org/LICENSE_1_0.txt)

=========================================
|Logo| METIS Input Routines
=========================================

:: 

  namespace boost { 
    namespace graph {
      class metis_reader;
      class metis_exception;
      class metis_input_exception;
      class metis_distribution;
    }
  }


METIS_ is a set of programs for partitioning graphs (among other
things). The Parallel BGL can read the METIS graph format and
partition format, allowing one to easily load METIS-partitioned
graphs into the Parallel BGL's data structures.

.. contents::

Where Defined
~~~~~~~~~~~~~
<``boost/graph/metis.hpp``>


Graph Reader
------------------

::

  class metis_reader
  {
   public:
    typedef std::size_t vertices_size_type;
    typedef std::size_t edges_size_type;
    typedef double vertex_weight_type;
    typedef double edge_weight_type;

    class edge_iterator;
    class edge_weight_iterator;
    
    metis_reader(std::istream& in);

    edge_iterator begin();
    edge_iterator end();
    edge_weight_iterator weight_begin();

    vertices_size_type num_vertices() const;
    edges_size_type num_edges() const;

    std::size_t num_vertex_weights() const;

    vertex_weight_type vertex_weight(vertices_size_type v, std::size_t n);

    bool has_edge_weights() const;
  };


Usage
~~~~~

The METIS reader provides an iterator interface to the METIS graph
file. The iterator interface is most useful when constructing Parallel
BGL graphs on-the-fly. For instance, the following code builds a graph
``g`` from a METIS graph stored in ``argv[1]``. 

::

  std::ifstream in_graph(argv[1]);
  metis_reader reader(in_graph);
  Graph g(reader.begin(), reader.end(),
          reader.weight_begin(),
          reader.num_vertices());


The calls to ``begin()`` and ``end()`` return an iterator range for
the edges in the graph; the call to ``weight_begin()`` returns an
iterator that will enumerate the weights of the edges in the
graph. For a distributed graph, the distribution will be determined
automatically by the graph; to use a METIS partitioning, see the
section `Partition Reader`_.

Associated Types 
~~~~~~~~~~~~~~~~

::

  metis_reader::edge_iterator

An `Input Iterator`_ that enumerates the edges in the METIS graph, and
is suitable for use as the ``EdgeIterator`` of an adjacency_list_.
The ``value_type`` of this iterator is a pair of vertex numbers.

-----------------------------------------------------------------------------

::

  metis_reader::edge_weight_iterator

An `Input Iterator`_ that enumerates the edge weights in the METIS
graph. The ``value_type`` of this iterator is ``edge_weight_type``. If
the edges in the METIS graph are unweighted, the result of
dereferencing this iterator will always be zero.

Member Functions
~~~~~~~~~~~~~~~~

::

  metis_reader(std::istream& in);

Constructs a new METIS reader that will retrieve edges from the input
stream ``in``. If any errors are encountered while initially parsing
``in``, ``metis_input_exception`` will be thrown.

-----------------------------------------------------------------------------

::

  edge_iterator begin();

Returns an iterator to the first edge in the METIS file. 

-----------------------------------------------------------------------------

::

  edge_iterator end();

Returns an iterator one past the last edge in the METIS file.

-----------------------------------------------------------------------------

::

  edge_weight_iterator weight_begin();

Returns an iterator to the first edge weight in the METIS file. The
weight iterator should be moved in concert with the edge iterator;
when the edge iterator moves, the edge weight changes. If the edges
in the graph are unweighted, the weight returned will always be zero.

-----------------------------------------------------------------------------

::

  vertices_size_type num_vertices() const;

Returns the number of vertices in the graph.


-----------------------------------------------------------------------------

::

    edges_size_type num_edges() const;

Returns the number of edges in the graph.

-----------------------------------------------------------------------------

::

    std::size_t num_vertex_weights() const;

Returns the number of weights attached to each vertex.

-----------------------------------------------------------------------------

::

    vertex_weight_type vertex_weight(vertices_size_type v, std::size_t n);

-----------------------------------------------------------------------------

::

    bool has_edge_weights() const;  

Returns ``true`` when the edges of the graph have weights, ``false``
otherwise. When ``false``, the edge weight iterator is still valid
but returns zero for the weight of each edge.


Partition Reader
----------------

::

  class metis_distribution
  {
   public:  
    typedef int process_id_type;
    typedef std::size_t size_type;

    metis_distribution(std::istream& in, process_id_type my_id);
    
    size_type block_size(process_id_type id, size_type) const;
    process_id_type operator()(size_type n);
    size_type local(size_type n) const;
    size_type global(size_type n) const;
    size_type global(process_id_type id, size_type n) const;

   private:
    std::istream& in;
    process_id_type my_id;
    std::vector<process_id_type> vertices;
  };


Usage
~~~~~

The class ``metis_distribution`` loads a METIS partition file and
makes it available as a Distribution suitable for use with the
`distributed adjacency list`_ graph type. To load a METIS graph using
a METIS partitioning, use a ``metis_reader`` object for the graph and
a ``metis_distribution`` object for the distribution, as in the
following example.

::

  std::ifstream in_graph(argv[1]);
  metis_reader reader(in_graph);

  std::ifstream in_partitions(argv[2]);
  metis_distribution dist(in_partitions, process_id(pg));
  Graph g(reader.begin(), reader.end(),
          reader.weight_begin(),
          reader.num_vertices(),
          pg,
          dist);

In this example, ``argv[1]`` is the graph and ``argv[2]`` is the
partition file generated by ``pmetis``. The ``dist`` object loads the
partitioning information from the input stream it is given and uses
that to distributed the adjacency list. Note that the input stream
must be in the METIS partition file format and must have been
partitioned for the same number of processes are there are in the
process group ``pg``.

Member Functions
~~~~~~~~~~~~~~~~

::

  metis_distribution(std::istream& in, process_id_type my_id);

Creates a new METIS distribution from the input stream
``in``. ``my_id`` is the process ID of the current process in the
process group over which the graph will be distributed.

-----------------------------------------------------------------------------

::

  size_type block_size(process_id_type id, size_type) const;

Returns the number of vertices to be stored in the process
``id``. The second parameter, ``size_type``, is unused and may be any
value. 

-----------------------------------------------------------------------------

::

  process_id_type operator()(size_type n);

Returns the ID for the process that will store vertex number ``n``.

-----------------------------------------------------------------------------

::

  size_type local(size_type n) const;

Returns the local index of vertex number ``n`` within its owning
process. 

-----------------------------------------------------------------------------

::

  size_type global(size_type n) const;

Returns the global index of the current processor's local vertex ``n``. 

-----------------------------------------------------------------------------


::

  size_type global(process_id_type id, size_type n) const;
  
Returns the global index of the process ``id``'s local vertex ``n``.

-----------------------------------------------------------------------------

Copyright (C) 2005 The Trustees of Indiana University.

Authors: Douglas Gregor and Andrew Lumsdaine

.. _METIS: http://www-users.cs.umn.edu/~karypis/metis/metis/
.. _distributed adjacency list: distributed_adjacency_list.html
.. _adjacency_list: http://www.boost.org/libs/graph/doc/adjacency_list.html
.. _input iterator: http://www.sgi.com/tech/stl/InputIterator.html

.. |Logo| image:: pbgl-logo.png
            :align: middle
            :alt: Parallel BGL
            :target: http://www.osl.iu.edu/research/pbgl