Update tree_broadcast assigment for fall 2010.
[parallel_computing.git] / assignments / archive / tree_broadcast / index.shtml
index 81b8e1b5da48076030030288db1498028faec96e..fffbac5ca965a5fc687c6711e91a0c895538be04 100644 (file)
@@ -1,83 +1,64 @@
 <!--#set var="root_directory" value="../../.." --><!--#include virtual="$root_directory/shared/header.shtml"-->
 
-<h1>Assignment #3</h1>
-<p><em>Due Friday, October 26, 2007</em></p>
+<h1>Assignment #4</h1>
+<p><em>Due Friday, October 29, 2010</em></p>
 
 <h2>Purpose</h2>
 
-<p>To learn how to implement truly parallel algorithms.</p>
+<p>Learn how to implement a truly parallel algorithm.</p>
 
-<h2>Setup</h2>
+<p>Note: Please identify all your work.</p>
 
 <p>This assignment consists in building your own broadcast code based
-on a binary tree. The code <a href="src/print_tree.c">print_tree.c</a>
-provides a simple implementation of a binary tree based on node zero
-as being the root. It generates the node numbers from which any node
-is to receive the information and to which to send this
-information.</p>
+on a binary tree.  The code
+<a href="../../../content/global_operations/src/print_tree.c">print_tree.c</a>
+(see <a href="../../../content/global_operations/">Global
+Operations</a>) provides a simple implementation of a binary tree
+based on node zero as being the root.  It generates the node numbers
+from which any node is to receive the information and to which to send
+this information.</p>
 
-<h2>To do</h2>
+<h2>Part A</h2>
 
-<h3>Part A</h3>
+<p>Write a function <code>My_Bcast()</code> that performs a broadcast
+similar as the one provided by MPICH2. It should follow the same
+syntax as <code>MPI_Bcast()</code>, namely</p>
 
-<ol>
-  <li>Build a broadcast function based on the skeleton code
-    <a href="src/print_tree.c">print_tree.c</a>.</li>
-  <li>Call this function <code>my_broadcast()</code> with a calling
-    sequence
-    <pre>int my_broadcast( int my_rank, int size, int root, double *msg, int count )</pre>
-    In other words, restrict it to only <code>double</code> data type for
-    simplicity and to <code>root</code> pointing to node 0 only (via
-    an <code>if ( )</code>).</li>
-  <li>Move the inner parts of the loop
-    in <a href="src/print_tree.c">print_tree.c</a> over to a function
-    <code>my_broadcast</code> (still in a serial code).</li>
-  <li>Use an integer array <code>target[]</code> created by
-    <code>malloc()</code> to store the list of <code>to</code> target
-    nodes.</li>
-  <li>Include the MPI administrative calls
-    (<code>MPI_Init()</code>,
-     <code>MPI_Comm_size()</code>,
-     <code>MPI_Comm_rank()</code>,
-     <code>MPI_Finalize()</code>), and use the actual <code>size</code> and
-    <code>rank</code> of the virtual machine instead for the loop
-    over <code>rank</code>.</li>
-  <li>Implement the send and receive routines (<code>MPI_Recv()</code> and
-    <code>MPI_Ssend()</code>) to receive and transmit the message.</li>
-  <li>Put <code>printf()</code> statements in the main program to
-    check that the code is working correctly.</li>
-</ol>
+<pre>
+int My_Bcast(void *buffer, int count, MPI_Datatype datatype, int root,
+             MPI_Comm comm)
+</pre>
 
-<h3>Part B</h3>
+<p>This function should be based on the skeleton
+code <code>print_tree.c</code>. It should therefore assume that root
+is process zero (0). If not, it should print out an error message
+quoting this fact and return an exit code one (1).</p>
 
-<p>Use <code>MPI_Wtime()</code> to time three ways of "broadcasting" a
-message:</p>
-<ol>
-  <li>Using a <code>for</code> loop over the nodes to send the message
-  from the <code>root</code> node to the other nodes.</li>
-  <li>Using <code>my_broadcast()</code>.</li>
-  <li>Using <code>MPI_Bcast()</code>.</li>
-</ol>
+<p>Test your routine carefully for various process numbers and
+different <code>count</code> and <code>datatype</code> in the
+call.</p>
 
-<p>To do so, send a message of some length (at least 1000, 5000 and
-10000 double — filled with random numbers) over and over again
-100 times (using a <code>for</code> loop) to have good time
-statistics. Print the average of the times for each broadcast
-methods.</p>
+<h2>Part B</h2>
 
-<h3>Part C</h3>
+<p>Instrument your code for timing measurements. Modify your main code
+to broadcast the information three (3) different ways:</p>
 
-<p>Modify your function <code>my_broadcast()</code> to broadcast from
-an arbitrary <code>root</code> node, namely</p>
 <ol>
-  <li>Modify the algorithm (explain what you will implement).</li>
-  <li>Modify <a href="print_tree.c">print_tree.c</a> accordingly.</li>
-  <li>Modify <code>my_broadcast()</code> accordingly.</li>
-  <li>Fully check that <code>my_broadcast()</code> works properly by
-    inserting appropriate <code>printf()</code> in the main program and
-    running the code for different number of processes and
-    <code>root</code>.</li>
-  <li>Repeat the timing study in part B for this new function.</li>
+  <li>sequentially via a for loop,</li>
+  <li>via your <code>My_Bcast()</code>, and</li>
+  <li>via the MPICH2 <code>MPI_Bcast()</code>.</li>
 </ol>
 
+<p>Broadcast 10,000 integers 100 times and take an average over the
+100 broadcasts to smooth out the time fluctuations. Repeat for 10,000
+<code>double</code>. Tabulate your timings and comment on the
+results.</p>
+
+<h2>Part C</h2>
+
+<p>Modify <code>My_Bcast()</code> to be able to broadcast from any
+process (the root process) within the virtual machine. Check your code
+carefully for different <code>root</code> processes and various numbers
+of processes.</p>
+
 <!--#include virtual="$root_directory/shared/footer.shtml"-->