tsin_depth_first_visit.html 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. <?xml version="1.0" encoding="utf-8" ?>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  4. <head>
  5. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  6. <meta name="generator" content="Docutils 0.6: http://docutils.sourceforge.net/" />
  7. <title>Parallel BGL Depth-First Visit</title>
  8. <link rel="stylesheet" href="../../../../rst.css" type="text/css" />
  9. </head>
  10. <body>
  11. <div class="document" id="logo-depth-first-visit">
  12. <h1 class="title"><a class="reference external" href="http://www.osl.iu.edu/research/pbgl"><img align="middle" alt="Parallel BGL" class="align-middle" src="pbgl-logo.png" /></a> Depth-First Visit</h1>
  13. <!-- Copyright (C) 2004-2008 The Trustees of Indiana University.
  14. Use, modification and distribution is subject to the Boost Software
  15. License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  16. http://www.boost.org/LICENSE_1_0.txt) -->
  17. <pre class="literal-block">
  18. template&lt;typename DistributedGraph, typename DFSVisitor&gt;
  19. void
  20. depth_first_visit(const DistributedGraph&amp; g,
  21. typename graph_traits&lt;DistributedGraph&gt;::vertex_descriptor s,
  22. DFSVisitor vis);
  23. namespace graph {
  24. template&lt;typename DistributedGraph, typename DFSVisitor,
  25. typename VertexIndexMap&gt;
  26. void
  27. tsin_depth_first_visit(const DistributedGraph&amp; g,
  28. typename graph_traits&lt;DistributedGraph&gt;::vertex_descriptor s,
  29. DFSVisitor vis);
  30. template&lt;typename DistributedGraph, typename DFSVisitor,
  31. typename VertexIndexMap&gt;
  32. void
  33. tsin_depth_first_visit(const DistributedGraph&amp; g,
  34. typename graph_traits&lt;DistributedGraph&gt;::vertex_descriptor s,
  35. DFSVisitor vis, VertexIndexMap index_map);
  36. template&lt;typename DistributedGraph, typename ColorMap, typename ParentMap,
  37. typename ExploreMap, typename NextOutEdgeMap, typename DFSVisitor&gt;
  38. void
  39. tsin_depth_first_visit(const DistributedGraph&amp; g,
  40. typename graph_traits&lt;DistributedGraph&gt;::vertex_descriptor s,
  41. DFSVisitor vis, ColorMap color, ParentMap parent, ExploreMap explore,
  42. NextOutEdgeMap next_out_edge);
  43. }
  44. </pre>
  45. <p>The <tt class="docutils literal"><span class="pre">depth_first_visit()</span></tt> function performs a distributed
  46. depth-first traversal of an undirected graph using Tsin's corrections
  47. <a class="citation-reference" href="#tsin02" id="id1">[Tsin02]</a> to Cidon's algorithm <a class="citation-reference" href="#cidon88" id="id2">[Cidon88]</a>. The distributed DFS is
  48. syntactically similar to its <a class="reference external" href="http://www.boost.org/libs/graph/doc/depth_first_visit.html">sequential counterpart</a>, which provides
  49. additional background and discussion. Differences in semantics are
  50. highlighted here, and we refer the reader to the documentation of the
  51. <a class="reference external" href="http://www.boost.org/libs/graph/doc/depth_first_visit.html">sequential depth-first search</a> for the remainder of the
  52. details. Visitors passed to depth-first search need to account for the
  53. distribution of vertices across processes, because events will be
  54. triggered on certain processes but not others. See the section
  55. <a class="reference internal" href="#visitor-event-points">Visitor Event Points</a> for details.</p>
  56. <div class="section" id="where-defined">
  57. <h1>Where Defined</h1>
  58. <p>&lt;<tt class="docutils literal"><span class="pre">boost/graph/distributed/depth_first_search.hpp</span></tt>&gt;</p>
  59. <p>also available in</p>
  60. <p>&lt;<tt class="docutils literal"><span class="pre">boost/graph/depth_first_search.hpp</span></tt>&gt;</p>
  61. </div>
  62. <div class="section" id="parameters">
  63. <h1>Parameters</h1>
  64. <dl class="docutils">
  65. <dt>IN: <tt class="docutils literal"><span class="pre">const</span> <span class="pre">Graph&amp;</span> <span class="pre">g</span></tt></dt>
  66. <dd>The graph type must be a model of <a class="reference external" href="DistributedGraph.html">Distributed Graph</a>. The graph
  67. must be undirected.</dd>
  68. <dt>IN: <tt class="docutils literal"><span class="pre">vertex_descriptor</span> <span class="pre">s</span></tt></dt>
  69. <dd>The start vertex must be the same in every process.</dd>
  70. <dt>IN: <tt class="docutils literal"><span class="pre">DFSVisitor</span> <span class="pre">vis</span></tt></dt>
  71. <dd>The visitor must be a distributed DFS visitor. The suble differences
  72. between sequential and distributed DFS visitors are discussed in the
  73. section <a class="reference internal" href="#visitor-event-points">Visitor Event Points</a>.</dd>
  74. <dt>IN: <tt class="docutils literal"><span class="pre">VertexIndexMap</span> <span class="pre">map</span></tt></dt>
  75. <dd><p class="first">A model of <a class="reference external" href="http://www.boost.org/libs/property_map/ReadablePropertyMap.html">Readable Property Map</a> whose key type is the vertex
  76. descriptor type of the graph <tt class="docutils literal"><span class="pre">g</span></tt> and whose value type is an
  77. integral type. The property map should map from vertices to their
  78. (local) indices in the range <em>[0, num_vertices(g))</em>.</p>
  79. <p class="last"><strong>Default</strong>: <tt class="docutils literal"><span class="pre">get(vertex_index,</span> <span class="pre">g)</span></tt></p>
  80. </dd>
  81. <dt>UTIL/OUT: <tt class="docutils literal"><span class="pre">ColorMap</span> <span class="pre">color</span></tt></dt>
  82. <dd><p class="first">The color map must be a <a class="reference external" href="distributed_property_map.html">Distributed Property Map</a> with the same
  83. process group as the graph <tt class="docutils literal"><span class="pre">g</span></tt> whose colors must monotonically
  84. darken (white -&gt; gray -&gt; black).</p>
  85. <p class="last"><strong>Default</strong>: A distributed <tt class="docutils literal"><span class="pre">iterator_property_map</span></tt> created from a
  86. <tt class="docutils literal"><span class="pre">std::vector</span></tt> of <tt class="docutils literal"><span class="pre">default_color_type</span></tt>.</p>
  87. </dd>
  88. <dt>UTIL/OUT: <tt class="docutils literal"><span class="pre">ParentMap</span> <span class="pre">parent</span></tt></dt>
  89. <dd><p class="first">The parent map must be a <a class="reference external" href="distributed_property_map.html">Distributed Property Map</a> with the same
  90. process group as the graph <tt class="docutils literal"><span class="pre">g</span></tt> whose key and values types are the
  91. same as the vertex descriptor type of the graph <tt class="docutils literal"><span class="pre">g</span></tt>. This
  92. property map holds the parent of each vertex in the depth-first
  93. search tree.</p>
  94. <p class="last"><strong>Default</strong>: A distributed <tt class="docutils literal"><span class="pre">iterator_property_map</span></tt> created from a
  95. <tt class="docutils literal"><span class="pre">std::vector</span></tt> of the vertex descriptor type of the graph.</p>
  96. </dd>
  97. <dt>UTIL: <tt class="docutils literal"><span class="pre">ExploreMap</span> <span class="pre">explore</span></tt></dt>
  98. <dd><p class="first">The explore map must be a <a class="reference external" href="distributed_property_map.html">Distributed Property Map</a> with the same
  99. process group as the graph <tt class="docutils literal"><span class="pre">g</span></tt> whose key and values types are the
  100. same as the vertex descriptor type of the graph <tt class="docutils literal"><span class="pre">g</span></tt>.</p>
  101. <p class="last"><strong>Default</strong>: A distributed <tt class="docutils literal"><span class="pre">iterator_property_map</span></tt> created from a
  102. <tt class="docutils literal"><span class="pre">std::vector</span></tt> of the vertex descriptor type of the graph.</p>
  103. </dd>
  104. <dt>UTIL: <tt class="docutils literal"><span class="pre">NextOutEdgeMap</span> <span class="pre">next_out_edge</span></tt></dt>
  105. <dd><p class="first">The next out-edge map must be a <a class="reference external" href="distributed_property_map.html">Distributed Property Map</a> with the
  106. same process group as the graph <tt class="docutils literal"><span class="pre">g</span></tt> whose key type is the vertex
  107. descriptor of the graph <tt class="docutils literal"><span class="pre">g</span></tt> and whose value type is the
  108. <tt class="docutils literal"><span class="pre">out_edge_iterator</span></tt> type of the graph. It is used internally to
  109. keep track of the next edge that should be traversed from each
  110. vertex.</p>
  111. <p class="last"><strong>Default</strong>: A distributed <tt class="docutils literal"><span class="pre">iterator_property_map</span></tt> created from a
  112. <tt class="docutils literal"><span class="pre">std::vector</span></tt> of the <tt class="docutils literal"><span class="pre">out_edge_iterator</span></tt> type of the graph.</p>
  113. </dd>
  114. </dl>
  115. </div>
  116. <div class="section" id="complexity">
  117. <h1>Complexity</h1>
  118. <p>Depth-first search is inherently sequential, so parallel speedup is
  119. very poor. Regardless of the number of processors, the algorithm will
  120. not be faster than <em>O(V)</em>; see <a class="citation-reference" href="#tsin02" id="id3">[Tsin02]</a> for more details.</p>
  121. </div>
  122. <div class="section" id="visitor-event-points">
  123. <h1>Visitor Event Points</h1>
  124. <p>The <a class="reference external" href="http://www.boost.org/libs/graph/doc/DFSVisitor.html">DFS Visitor</a> concept defines 8 event points that will be
  125. triggered by the <a class="reference external" href="http://www.boost.org/libs/graph/doc/depth_first_visit.html">sequential depth-first search</a>. The distributed
  126. DFS retains these event points, but the sequence of events
  127. triggered and the process in which each event occurs will change
  128. depending on the distribution of the graph.</p>
  129. <dl class="docutils">
  130. <dt><tt class="docutils literal"><span class="pre">initialize_vertex(s,</span> <span class="pre">g)</span></tt></dt>
  131. <dd>This will be invoked by every process for each local vertex.</dd>
  132. <dt><tt class="docutils literal"><span class="pre">discover_vertex(u,</span> <span class="pre">g)</span></tt></dt>
  133. <dd>This will be invoked each time a process discovers a new vertex
  134. <tt class="docutils literal"><span class="pre">u</span></tt>.</dd>
  135. <dt><tt class="docutils literal"><span class="pre">examine_vertex(u,</span> <span class="pre">g)</span></tt></dt>
  136. <dd>This will be invoked by the process owning the vertex <tt class="docutils literal"><span class="pre">u</span></tt>.</dd>
  137. <dt><tt class="docutils literal"><span class="pre">examine_edge(e,</span> <span class="pre">g)</span></tt></dt>
  138. <dd>This will be invoked by the process owning the source vertex of
  139. <tt class="docutils literal"><span class="pre">e</span></tt>.</dd>
  140. <dt><tt class="docutils literal"><span class="pre">tree_edge(e,</span> <span class="pre">g)</span></tt></dt>
  141. <dd>Similar to <tt class="docutils literal"><span class="pre">examine_edge</span></tt>, this will be invoked by the process
  142. owning the source vertex and may be invoked only once.</dd>
  143. <dt><tt class="docutils literal"><span class="pre">back_edge(e,</span> <span class="pre">g)</span></tt></dt>
  144. <dd>Some edges that would be forward or cross edges in the sequential
  145. DFS may be detected as back edges by the distributed DFS, so extra
  146. <tt class="docutils literal"><span class="pre">back_edge</span></tt> events may be received.</dd>
  147. <dt><tt class="docutils literal"><span class="pre">forward_or_cross_edge(e,</span> <span class="pre">g)</span></tt></dt>
  148. <dd>Some edges that would be forward or cross edges in the sequential
  149. DFS may be detected as back edges by the distributed DFS, so fewer
  150. <tt class="docutils literal"><span class="pre">forward_or_cross_edge</span></tt> events may be received in the distributed
  151. algorithm than in the sequential case.</dd>
  152. <dt><tt class="docutils literal"><span class="pre">finish_vertex(e,</span> <span class="pre">g)</span></tt></dt>
  153. <dd>See documentation for <tt class="docutils literal"><span class="pre">examine_vertex</span></tt>.</dd>
  154. </dl>
  155. <div class="section" id="making-visitors-safe-for-distributed-dfs">
  156. <h2>Making Visitors Safe for Distributed DFS</h2>
  157. <p>The three most important things to remember when updating an existing
  158. DFS visitor for distributed DFS or writing a new distributed DFS
  159. visitor are:</p>
  160. <ol class="arabic simple">
  161. <li>Be sure that all state is either entirely local or in a
  162. distributed data structure (most likely a property map!) using
  163. the same process group as the graph.</li>
  164. <li>Be sure that the visitor doesn't require precise event sequences
  165. that cannot be guaranteed by distributed DFS, e.g., requiring
  166. <tt class="docutils literal"><span class="pre">back_edge</span></tt> and <tt class="docutils literal"><span class="pre">forward_or_cross_edge</span></tt> events to be completely
  167. distinct.</li>
  168. <li>Be sure that the visitor can operate on incomplete
  169. information. This often includes using an appropriate reduction
  170. operation in a <a class="reference external" href="distributed_property_map.html">distributed property map</a> and verifying that
  171. results written are &quot;better&quot; that what was previously written.</li>
  172. </ol>
  173. </div>
  174. </div>
  175. <div class="section" id="bibliography">
  176. <h1>Bibliography</h1>
  177. <table class="docutils citation" frame="void" id="cidon88" rules="none">
  178. <colgroup><col class="label" /><col /></colgroup>
  179. <tbody valign="top">
  180. <tr><td class="label"><a class="fn-backref" href="#id2">[Cidon88]</a></td><td>Isreal Cidon. Yet another distributed depth-first-search
  181. algorithm. Information Processing Letters, 26(6):301--305, 1988.</td></tr>
  182. </tbody>
  183. </table>
  184. <table class="docutils citation" frame="void" id="tsin02" rules="none">
  185. <colgroup><col class="label" /><col /></colgroup>
  186. <tbody valign="top">
  187. <tr><td class="label">[Tsin02]</td><td><em>(<a class="fn-backref" href="#id1">1</a>, <a class="fn-backref" href="#id3">2</a>)</em> Y. H. Tsin. Some remarks on distributed depth-first
  188. search. Information Processing Letters, 82(4):173--178, 2002.</td></tr>
  189. </tbody>
  190. </table>
  191. <hr class="docutils" />
  192. <p>Copyright (C) 2005 The Trustees of Indiana University.</p>
  193. <p>Authors: Douglas Gregor and Andrew Lumsdaine</p>
  194. </div>
  195. </div>
  196. <div class="footer">
  197. <hr class="footer" />
  198. Generated on: 2009-05-31 00:21 UTC.
  199. Generated by <a class="reference external" href="http://docutils.sourceforge.net/">Docutils</a> from <a class="reference external" href="http://docutils.sourceforge.net/rst.html">reStructuredText</a> source.
  200. </div>
  201. </body>
  202. </html>