tsin_depth_first_visit.rst 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  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| Depth-First Visit
  7. ========================
  8. ::
  9. template<typename DistributedGraph, typename DFSVisitor>
  10. void
  11. depth_first_visit(const DistributedGraph& g,
  12. typename graph_traits<DistributedGraph>::vertex_descriptor s,
  13. DFSVisitor vis);
  14. namespace graph {
  15. template<typename DistributedGraph, typename DFSVisitor,
  16. typename VertexIndexMap>
  17. void
  18. tsin_depth_first_visit(const DistributedGraph& g,
  19. typename graph_traits<DistributedGraph>::vertex_descriptor s,
  20. DFSVisitor vis);
  21. template<typename DistributedGraph, typename DFSVisitor,
  22. typename VertexIndexMap>
  23. void
  24. tsin_depth_first_visit(const DistributedGraph& g,
  25. typename graph_traits<DistributedGraph>::vertex_descriptor s,
  26. DFSVisitor vis, VertexIndexMap index_map);
  27. template<typename DistributedGraph, typename ColorMap, typename ParentMap,
  28. typename ExploreMap, typename NextOutEdgeMap, typename DFSVisitor>
  29. void
  30. tsin_depth_first_visit(const DistributedGraph& g,
  31. typename graph_traits<DistributedGraph>::vertex_descriptor s,
  32. DFSVisitor vis, ColorMap color, ParentMap parent, ExploreMap explore,
  33. NextOutEdgeMap next_out_edge);
  34. }
  35. The ``depth_first_visit()`` function performs a distributed
  36. depth-first traversal of an undirected graph using Tsin's corrections
  37. [Tsin02]_ to Cidon's algorithm [Cidon88]_. The distributed DFS is
  38. syntactically similar to its `sequential counterpart`_, which provides
  39. additional background and discussion. Differences in semantics are
  40. highlighted here, and we refer the reader to the documentation of the
  41. `sequential depth-first search`_ for the remainder of the
  42. details. Visitors passed to depth-first search need to account for the
  43. distribution of vertices across processes, because events will be
  44. triggered on certain processes but not others. See the section
  45. `Visitor Event Points`_ for details.
  46. Where Defined
  47. -------------
  48. <``boost/graph/distributed/depth_first_search.hpp``>
  49. also available in
  50. <``boost/graph/depth_first_search.hpp``>
  51. Parameters
  52. ----------
  53. IN: ``const Graph& g``
  54. The graph type must be a model of `Distributed Graph`_. The graph
  55. must be undirected.
  56. IN: ``vertex_descriptor s``
  57. The start vertex must be the same in every process.
  58. IN: ``DFSVisitor vis``
  59. The visitor must be a distributed DFS visitor. The suble differences
  60. between sequential and distributed DFS visitors are discussed in the
  61. section `Visitor Event Points`_.
  62. IN: ``VertexIndexMap map``
  63. A model of `Readable Property Map`_ whose key type is the vertex
  64. descriptor type of the graph ``g`` and whose value type is an
  65. integral type. The property map should map from vertices to their
  66. (local) indices in the range *[0, num_vertices(g))*.
  67. **Default**: ``get(vertex_index, g)``
  68. UTIL/OUT: ``ColorMap color``
  69. The color map must be a `Distributed Property Map`_ with the same
  70. process group as the graph ``g`` whose colors must monotonically
  71. darken (white -> gray -> black).
  72. **Default**: A distributed ``iterator_property_map`` created from a
  73. ``std::vector`` of ``default_color_type``.
  74. UTIL/OUT: ``ParentMap parent``
  75. The parent map must be a `Distributed Property Map`_ with the same
  76. process group as the graph ``g`` whose key and values types are the
  77. same as the vertex descriptor type of the graph ``g``. This
  78. property map holds the parent of each vertex in the depth-first
  79. search tree.
  80. **Default**: A distributed ``iterator_property_map`` created from a
  81. ``std::vector`` of the vertex descriptor type of the graph.
  82. UTIL: ``ExploreMap explore``
  83. The explore map must be a `Distributed Property Map`_ with the same
  84. process group as the graph ``g`` whose key and values types are the
  85. same as the vertex descriptor type of the graph ``g``.
  86. **Default**: A distributed ``iterator_property_map`` created from a
  87. ``std::vector`` of the vertex descriptor type of the graph.
  88. UTIL: ``NextOutEdgeMap next_out_edge``
  89. The next out-edge map must be a `Distributed Property Map`_ with the
  90. same process group as the graph ``g`` whose key type is the vertex
  91. descriptor of the graph ``g`` and whose value type is the
  92. ``out_edge_iterator`` type of the graph. It is used internally to
  93. keep track of the next edge that should be traversed from each
  94. vertex.
  95. **Default**: A distributed ``iterator_property_map`` created from a
  96. ``std::vector`` of the ``out_edge_iterator`` type of the graph.
  97. Complexity
  98. ----------
  99. Depth-first search is inherently sequential, so parallel speedup is
  100. very poor. Regardless of the number of processors, the algorithm will
  101. not be faster than *O(V)*; see [Tsin02]_ for more details.
  102. Visitor Event Points
  103. --------------------
  104. The `DFS Visitor`_ concept defines 8 event points that will be
  105. triggered by the `sequential depth-first search`_. The distributed
  106. DFS retains these event points, but the sequence of events
  107. triggered and the process in which each event occurs will change
  108. depending on the distribution of the graph.
  109. ``initialize_vertex(s, g)``
  110. This will be invoked by every process for each local vertex.
  111. ``discover_vertex(u, g)``
  112. This will be invoked each time a process discovers a new vertex
  113. ``u``.
  114. ``examine_vertex(u, g)``
  115. This will be invoked by the process owning the vertex ``u``.
  116. ``examine_edge(e, g)``
  117. This will be invoked by the process owning the source vertex of
  118. ``e``.
  119. ``tree_edge(e, g)``
  120. Similar to ``examine_edge``, this will be invoked by the process
  121. owning the source vertex and may be invoked only once.
  122. ``back_edge(e, g)``
  123. Some edges that would be forward or cross edges in the sequential
  124. DFS may be detected as back edges by the distributed DFS, so extra
  125. ``back_edge`` events may be received.
  126. ``forward_or_cross_edge(e, g)``
  127. Some edges that would be forward or cross edges in the sequential
  128. DFS may be detected as back edges by the distributed DFS, so fewer
  129. ``forward_or_cross_edge`` events may be received in the distributed
  130. algorithm than in the sequential case.
  131. ``finish_vertex(e, g)``
  132. See documentation for ``examine_vertex``.
  133. Making Visitors Safe for Distributed DFS
  134. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  135. The three most important things to remember when updating an existing
  136. DFS visitor for distributed DFS or writing a new distributed DFS
  137. visitor are:
  138. 1. Be sure that all state is either entirely local or in a
  139. distributed data structure (most likely a property map!) using
  140. the same process group as the graph.
  141. 2. Be sure that the visitor doesn't require precise event sequences
  142. that cannot be guaranteed by distributed DFS, e.g., requiring
  143. ``back_edge`` and ``forward_or_cross_edge`` events to be completely
  144. distinct.
  145. 3. Be sure that the visitor can operate on incomplete
  146. information. This often includes using an appropriate reduction
  147. operation in a `distributed property map`_ and verifying that
  148. results written are "better" that what was previously written.
  149. Bibliography
  150. ------------
  151. .. [Cidon88] Isreal Cidon. Yet another distributed depth-first-search
  152. algorithm. Information Processing Letters, 26(6):301--305, 1988.
  153. .. [Tsin02] Y. H. Tsin. Some remarks on distributed depth-first
  154. search. Information Processing Letters, 82(4):173--178, 2002.
  155. -----------------------------------------------------------------------------
  156. Copyright (C) 2005 The Trustees of Indiana University.
  157. Authors: Douglas Gregor and Andrew Lumsdaine
  158. .. |Logo| image:: pbgl-logo.png
  159. :align: middle
  160. :alt: Parallel BGL
  161. :target: http://www.osl.iu.edu/research/pbgl
  162. .. _sequential counterpart: http://www.boost.org/libs/graph/doc/depth_first_visit.html
  163. .. _sequential depth-first search: http://www.boost.org/libs/graph/doc/depth_first_visit.html
  164. .. _Distributed Graph: DistributedGraph.html
  165. .. _Immediate Process Group: concepts/ImmediateProcessGroup.html
  166. .. _Distributed Property Map: distributed_property_map.html
  167. .. _DFS Visitor: http://www.boost.org/libs/graph/doc/DFSVisitor.html
  168. .. _Readable Property Map: http://www.boost.org/libs/property_map/ReadablePropertyMap.html