metis.rst 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  1. .. Copyright (C) 2004-2008 The Trustees of Indiana University.
  2. Use, modification and distribution is subject to the Boost Software
  3. License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  4. http://www.boost.org/LICENSE_1_0.txt)
  5. =========================================
  6. |Logo| METIS Input Routines
  7. =========================================
  8. ::
  9. namespace boost {
  10. namespace graph {
  11. class metis_reader;
  12. class metis_exception;
  13. class metis_input_exception;
  14. class metis_distribution;
  15. }
  16. }
  17. METIS_ is a set of programs for partitioning graphs (among other
  18. things). The Parallel BGL can read the METIS graph format and
  19. partition format, allowing one to easily load METIS-partitioned
  20. graphs into the Parallel BGL's data structures.
  21. .. contents::
  22. Where Defined
  23. ~~~~~~~~~~~~~
  24. <``boost/graph/metis.hpp``>
  25. Graph Reader
  26. ------------------
  27. ::
  28. class metis_reader
  29. {
  30. public:
  31. typedef std::size_t vertices_size_type;
  32. typedef std::size_t edges_size_type;
  33. typedef double vertex_weight_type;
  34. typedef double edge_weight_type;
  35. class edge_iterator;
  36. class edge_weight_iterator;
  37. metis_reader(std::istream& in);
  38. edge_iterator begin();
  39. edge_iterator end();
  40. edge_weight_iterator weight_begin();
  41. vertices_size_type num_vertices() const;
  42. edges_size_type num_edges() const;
  43. std::size_t num_vertex_weights() const;
  44. vertex_weight_type vertex_weight(vertices_size_type v, std::size_t n);
  45. bool has_edge_weights() const;
  46. };
  47. Usage
  48. ~~~~~
  49. The METIS reader provides an iterator interface to the METIS graph
  50. file. The iterator interface is most useful when constructing Parallel
  51. BGL graphs on-the-fly. For instance, the following code builds a graph
  52. ``g`` from a METIS graph stored in ``argv[1]``.
  53. ::
  54. std::ifstream in_graph(argv[1]);
  55. metis_reader reader(in_graph);
  56. Graph g(reader.begin(), reader.end(),
  57. reader.weight_begin(),
  58. reader.num_vertices());
  59. The calls to ``begin()`` and ``end()`` return an iterator range for
  60. the edges in the graph; the call to ``weight_begin()`` returns an
  61. iterator that will enumerate the weights of the edges in the
  62. graph. For a distributed graph, the distribution will be determined
  63. automatically by the graph; to use a METIS partitioning, see the
  64. section `Partition Reader`_.
  65. Associated Types
  66. ~~~~~~~~~~~~~~~~
  67. ::
  68. metis_reader::edge_iterator
  69. An `Input Iterator`_ that enumerates the edges in the METIS graph, and
  70. is suitable for use as the ``EdgeIterator`` of an adjacency_list_.
  71. The ``value_type`` of this iterator is a pair of vertex numbers.
  72. -----------------------------------------------------------------------------
  73. ::
  74. metis_reader::edge_weight_iterator
  75. An `Input Iterator`_ that enumerates the edge weights in the METIS
  76. graph. The ``value_type`` of this iterator is ``edge_weight_type``. If
  77. the edges in the METIS graph are unweighted, the result of
  78. dereferencing this iterator will always be zero.
  79. Member Functions
  80. ~~~~~~~~~~~~~~~~
  81. ::
  82. metis_reader(std::istream& in);
  83. Constructs a new METIS reader that will retrieve edges from the input
  84. stream ``in``. If any errors are encountered while initially parsing
  85. ``in``, ``metis_input_exception`` will be thrown.
  86. -----------------------------------------------------------------------------
  87. ::
  88. edge_iterator begin();
  89. Returns an iterator to the first edge in the METIS file.
  90. -----------------------------------------------------------------------------
  91. ::
  92. edge_iterator end();
  93. Returns an iterator one past the last edge in the METIS file.
  94. -----------------------------------------------------------------------------
  95. ::
  96. edge_weight_iterator weight_begin();
  97. Returns an iterator to the first edge weight in the METIS file. The
  98. weight iterator should be moved in concert with the edge iterator;
  99. when the edge iterator moves, the edge weight changes. If the edges
  100. in the graph are unweighted, the weight returned will always be zero.
  101. -----------------------------------------------------------------------------
  102. ::
  103. vertices_size_type num_vertices() const;
  104. Returns the number of vertices in the graph.
  105. -----------------------------------------------------------------------------
  106. ::
  107. edges_size_type num_edges() const;
  108. Returns the number of edges in the graph.
  109. -----------------------------------------------------------------------------
  110. ::
  111. std::size_t num_vertex_weights() const;
  112. Returns the number of weights attached to each vertex.
  113. -----------------------------------------------------------------------------
  114. ::
  115. vertex_weight_type vertex_weight(vertices_size_type v, std::size_t n);
  116. -----------------------------------------------------------------------------
  117. ::
  118. bool has_edge_weights() const;
  119. Returns ``true`` when the edges of the graph have weights, ``false``
  120. otherwise. When ``false``, the edge weight iterator is still valid
  121. but returns zero for the weight of each edge.
  122. Partition Reader
  123. ----------------
  124. ::
  125. class metis_distribution
  126. {
  127. public:
  128. typedef int process_id_type;
  129. typedef std::size_t size_type;
  130. metis_distribution(std::istream& in, process_id_type my_id);
  131. size_type block_size(process_id_type id, size_type) const;
  132. process_id_type operator()(size_type n);
  133. size_type local(size_type n) const;
  134. size_type global(size_type n) const;
  135. size_type global(process_id_type id, size_type n) const;
  136. private:
  137. std::istream& in;
  138. process_id_type my_id;
  139. std::vector<process_id_type> vertices;
  140. };
  141. Usage
  142. ~~~~~
  143. The class ``metis_distribution`` loads a METIS partition file and
  144. makes it available as a Distribution suitable for use with the
  145. `distributed adjacency list`_ graph type. To load a METIS graph using
  146. a METIS partitioning, use a ``metis_reader`` object for the graph and
  147. a ``metis_distribution`` object for the distribution, as in the
  148. following example.
  149. ::
  150. std::ifstream in_graph(argv[1]);
  151. metis_reader reader(in_graph);
  152. std::ifstream in_partitions(argv[2]);
  153. metis_distribution dist(in_partitions, process_id(pg));
  154. Graph g(reader.begin(), reader.end(),
  155. reader.weight_begin(),
  156. reader.num_vertices(),
  157. pg,
  158. dist);
  159. In this example, ``argv[1]`` is the graph and ``argv[2]`` is the
  160. partition file generated by ``pmetis``. The ``dist`` object loads the
  161. partitioning information from the input stream it is given and uses
  162. that to distributed the adjacency list. Note that the input stream
  163. must be in the METIS partition file format and must have been
  164. partitioned for the same number of processes are there are in the
  165. process group ``pg``.
  166. Member Functions
  167. ~~~~~~~~~~~~~~~~
  168. ::
  169. metis_distribution(std::istream& in, process_id_type my_id);
  170. Creates a new METIS distribution from the input stream
  171. ``in``. ``my_id`` is the process ID of the current process in the
  172. process group over which the graph will be distributed.
  173. -----------------------------------------------------------------------------
  174. ::
  175. size_type block_size(process_id_type id, size_type) const;
  176. Returns the number of vertices to be stored in the process
  177. ``id``. The second parameter, ``size_type``, is unused and may be any
  178. value.
  179. -----------------------------------------------------------------------------
  180. ::
  181. process_id_type operator()(size_type n);
  182. Returns the ID for the process that will store vertex number ``n``.
  183. -----------------------------------------------------------------------------
  184. ::
  185. size_type local(size_type n) const;
  186. Returns the local index of vertex number ``n`` within its owning
  187. process.
  188. -----------------------------------------------------------------------------
  189. ::
  190. size_type global(size_type n) const;
  191. Returns the global index of the current processor's local vertex ``n``.
  192. -----------------------------------------------------------------------------
  193. ::
  194. size_type global(process_id_type id, size_type n) const;
  195. Returns the global index of the process ``id``'s local vertex ``n``.
  196. -----------------------------------------------------------------------------
  197. Copyright (C) 2005 The Trustees of Indiana University.
  198. Authors: Douglas Gregor and Andrew Lumsdaine
  199. .. _METIS: http://www-users.cs.umn.edu/~karypis/metis/metis/
  200. .. _distributed adjacency list: distributed_adjacency_list.html
  201. .. _adjacency_list: http://www.boost.org/libs/graph/doc/adjacency_list.html
  202. .. _input iterator: http://www.sgi.com/tech/stl/InputIterator.html
  203. .. |Logo| image:: pbgl-logo.png
  204. :align: middle
  205. :alt: Parallel BGL
  206. :target: http://www.osl.iu.edu/research/pbgl