distributed_queue.html 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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 Distributed queue adaptor</title>
  8. <link rel="stylesheet" href="../../../../rst.css" type="text/css" />
  9. </head>
  10. <body>
  11. <div class="document" id="logo-distributed-queue-adaptor">
  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> Distributed queue adaptor</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 ProcessGroup, typename Buffer&gt;
  19. class distributed_queue
  20. {
  21. public:
  22. typedef ProcessGroup process_group_type;
  23. typedef Buffer buffer_type;
  24. typedef typename buffer_type::value_type value_type;
  25. typedef typename buffer_type::size_type size_type;
  26. explicit
  27. distributed_queue(const ProcessGroup&amp; process_group = ProcessGroup(),
  28. const Buffer&amp; buffer = Buffer(),
  29. bool polling = false);
  30. distributed_queue(const ProcessGroup&amp; process_group, bool polling);
  31. void push(const value_type&amp; x);
  32. void pop();
  33. value_type&amp; top();
  34. const value_type&amp; top() const;
  35. bool empty() const;
  36. size_type size() const;
  37. };
  38. template&lt;typename ProcessGroup, typename Buffer&gt;
  39. inline distributed_queue&lt;ProcessGroup, Buffer&gt;
  40. make_distributed_queue(const ProcessGroup&amp; process_group, const Buffer&amp; buffer,
  41. bool polling = false);
  42. </pre>
  43. <p>Class template <tt class="docutils literal"><span class="pre">distributed_queue</span></tt> implements a distributed queue
  44. across a process group. The distributed queue is an adaptor over an
  45. existing (local) queue, which must model the <a class="reference external" href="http://www.boost.org/libs/graph/doc/Buffer.html">Buffer</a> concept. Each
  46. process stores a distinct copy of the local queue, from which it draws
  47. or removes elements via the <tt class="docutils literal"><span class="pre">pop</span></tt> and <tt class="docutils literal"><span class="pre">top</span></tt> members.</p>
  48. <p>The value type of the local queue must be a model of the
  49. <a class="reference external" href="GlobalDescriptor.html">Global Descriptor</a> concept. The <tt class="docutils literal"><span class="pre">push</span></tt> operation of the
  50. distributed queue passes (via a message) the value to its owning
  51. processor. Thus, the elements within a particular local queue are
  52. guaranteed to have the process owning that local queue as an owner.</p>
  53. <p>Synchronization of distributed queues occurs in the <tt class="docutils literal"><span class="pre">empty</span></tt> and
  54. <tt class="docutils literal"><span class="pre">size</span></tt> functions, which will only return &quot;empty&quot; values (true or 0,
  55. respectively) when the entire distributed queue is empty. If the local
  56. queue is empty but the distributed queue is not, the operation will
  57. block until either condition changes. When the <tt class="docutils literal"><span class="pre">size</span></tt> function of a
  58. nonempty queue returns, it returns the size of the local queue. These
  59. semantics were selected so that sequential code that processes
  60. elements in the queue via the following idiom can be parallelized via
  61. introduction of a distributed queue:</p>
  62. <pre class="literal-block">
  63. distributed_queue&lt;...&gt; Q;
  64. Q.push(x);
  65. while (!Q.empty()) {
  66. // do something, that may push a value onto Q
  67. }
  68. </pre>
  69. <p>In the parallel version, the initial <tt class="docutils literal"><span class="pre">push</span></tt> operation will place
  70. the value <tt class="docutils literal"><span class="pre">x</span></tt> onto its owner's queue. All processes will
  71. synchronize at the call to empty, and only the process owning <tt class="docutils literal"><span class="pre">x</span></tt>
  72. will be allowed to execute the loop (<tt class="docutils literal"><span class="pre">Q.empty()</span></tt> returns
  73. false). This iteration may in turn push values onto other remote
  74. queues, so when that process finishes execution of the loop body
  75. and all processes synchronize again in <tt class="docutils literal"><span class="pre">empty</span></tt>, more processes
  76. may have nonempty local queues to execute. Once all local queues
  77. are empty, <tt class="docutils literal"><span class="pre">Q.empty()</span></tt> returns <tt class="docutils literal"><span class="pre">false</span></tt> for all processes.</p>
  78. <p>The distributed queue can receive messages at two different times:
  79. during synchronization and when polling <tt class="docutils literal"><span class="pre">empty</span></tt>. Messages are
  80. always received during synchronization, to ensure that accurate
  81. local queue sizes can be determines. However, whether <tt class="docutils literal"><span class="pre">empty</span></tt>
  82. should poll for messages is specified as an option to the
  83. constructor. Polling may be desired when the order in which
  84. elements in the queue are processed is not important, because it
  85. permits fewer synchronization steps and less communication
  86. overhead. However, when more strict ordering guarantees are
  87. required, polling may be semantically incorrect. By disabling
  88. polling, one ensures that parallel execution using the idiom above
  89. will not process an element at a later &quot;level&quot; before an earlier
  90. &quot;level&quot;.</p>
  91. <p>The distributed queue nearly models the <a class="reference external" href="http://www.boost.org/libs/graph/doc/Buffer.html">Buffer</a>
  92. concept. However, the <tt class="docutils literal"><span class="pre">push</span></tt> routine does not necessarily
  93. increase the result of <tt class="docutils literal"><span class="pre">size()</span></tt> by one (although the size of the
  94. global queue does increase by one).</p>
  95. <div class="section" id="member-functions">
  96. <h1>Member Functions</h1>
  97. <pre class="literal-block">
  98. explicit
  99. distributed_queue(const ProcessGroup&amp; process_group = ProcessGroup(),
  100. const Buffer&amp; buffer = Buffer(),
  101. bool polling = false);
  102. </pre>
  103. <p>Build a new distributed queue that communicates over the given
  104. <tt class="docutils literal"><span class="pre">process_group</span></tt>, whose local queue is initialized via <tt class="docutils literal"><span class="pre">buffer</span></tt> and
  105. which may or may not poll for messages.</p>
  106. <hr class="docutils" />
  107. <pre class="literal-block">
  108. distributed_queue(const ProcessGroup&amp; process_group, bool polling);
  109. </pre>
  110. <p>Build a new distributed queue that communicates over the given
  111. <tt class="docutils literal"><span class="pre">process_group</span></tt>, whose local queue is default-initalized and which
  112. may or may not poll for messages.</p>
  113. <hr class="docutils" />
  114. <pre class="literal-block">
  115. void push(const value_type&amp; x);
  116. </pre>
  117. <p>Push an element onto the distributed queue.</p>
  118. <p>The element will be sent to its owner process to be added to that
  119. process's local queue. If polling is enabled for this queue and
  120. the owner process is the current process, the value will be
  121. immediately pushed onto the local queue.</p>
  122. <p>Complexity: O(1) messages of size O(<tt class="docutils literal"><span class="pre">sizeof(value_type)</span></tt>) will be
  123. transmitted.</p>
  124. <hr class="docutils" />
  125. <pre class="literal-block">
  126. void pop();
  127. </pre>
  128. <p>Pop an element off the local queue. The queue must not be <tt class="docutils literal"><span class="pre">empty()</span></tt>.</p>
  129. <hr class="docutils" />
  130. <pre class="literal-block">
  131. value_type&amp; top();
  132. const value_type&amp; top();
  133. </pre>
  134. <p>Returns the top element in the local queue. The queue must not be
  135. <tt class="docutils literal"><span class="pre">empty()</span></tt>.</p>
  136. <hr class="docutils" />
  137. <pre class="literal-block">
  138. bool empty() const;
  139. </pre>
  140. <p>Determines if the queue is empty.</p>
  141. <p>When the local queue is nonempty, returns true. If the local queue is
  142. empty, synchronizes with all other processes in the process group
  143. until either (1) the local queue is nonempty (returns true) (2) the
  144. entire distributed queue is empty (returns false).</p>
  145. <hr class="docutils" />
  146. <pre class="literal-block">
  147. size_type size() const;
  148. </pre>
  149. <p>Determines the size of the local queue.</p>
  150. <p>The behavior of this routine is equivalent to the behavior of
  151. <tt class="docutils literal"><span class="pre">empty</span></tt>, except that when <tt class="docutils literal"><span class="pre">empty</span></tt> returns true this
  152. function returns the size of the local queue and when <tt class="docutils literal"><span class="pre">empty</span></tt>
  153. returns false this function returns zero.</p>
  154. </div>
  155. <div class="section" id="free-functions">
  156. <h1>Free Functions</h1>
  157. <pre class="literal-block">
  158. template&lt;typename ProcessGroup, typename Buffer&gt;
  159. inline distributed_queue&lt;ProcessGroup, Buffer&gt;
  160. make_distributed_queue(const ProcessGroup&amp; process_group, const Buffer&amp; buffer,
  161. bool polling = false);
  162. </pre>
  163. <p>Constructs a distributed queue.</p>
  164. <hr class="docutils" />
  165. <p>Copyright (C) 2004, 2005 The Trustees of Indiana University.</p>
  166. <p>Authors: Douglas Gregor and Andrew Lumsdaine</p>
  167. </div>
  168. </div>
  169. <div class="footer">
  170. <hr class="footer" />
  171. Generated on: 2009-05-31 00:22 UTC.
  172. 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.
  173. </div>
  174. </body>
  175. </html>