Skip to content

Commit

Permalink
Finished Activity #1 of Matrix Multiplication
Browse files Browse the repository at this point in the history
  • Loading branch information
henricasanova committed Jun 30, 2016
1 parent 4e50a70 commit 1148264
Show file tree
Hide file tree
Showing 5 changed files with 167 additions and 11 deletions.
6 changes: 3 additions & 3 deletions topic_rigid_programs/matrixmultiplication/2d_matrices.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div class="ui container segment raised">In this activity we distributed the matrices across the MPI processes, which
entails dealing with local vs. global indexing. As opposed to what was seen in previous topics, we now use a 2-D data distribution,
which complicates indexing a bit. We multiply square matrices: <i>A = B x C</i>.
<div class="ui container segment raised">In this activity we distribute the matrices across the MPI processes, which
entails dealing with local vs. global indexing. Recall that we consider 3 NxN matrices (A, B, and C). This
activity consists of a single step, as described below.
</div>

<div class="ui top attached tabular menu">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version='1.0'?>
<!DOCTYPE platform SYSTEM "http://simgrid.gforge.inria.fr/simgrid.dtd">
<platform version="3">
<AS id="AS0" routing="Full">
<cluster id="cluster" prefix="host-" suffix=".hawaii.edu" radical="0-63" power="1" bw="10Gbps" lat="20us"/>
</AS>
</platform>
90 changes: 87 additions & 3 deletions topic_rigid_programs/matrixmultiplication/data_distribution.html
Original file line number Diff line number Diff line change
@@ -1,12 +1,96 @@
<p class="ui">
Implement a program called <code>matmul_init</code> (<code>matmul_init.c</code>) that takes a
Implement an MPI program called <code>matmul_init</code> (<code>matmul_init.c</code>) that takes a
single command-line argument, <i>N</i>, which is a strictly positive integer. <i>N</i> is the
dimension of the square matrices that we multiply.
dimension of the square matrices that we multiply. Your program should check that the number of processes
is a perfect square, and that its square root divides N (printing an error message and exiting if this is
not the case).
</p>

<p class="ui">
The objective of the program is for each process to allocate and initialize its block of each matrix.
We multiply particular matrices, defined by:
</p>
<p class="ui">
<i>A<sub>i,j</sub> = i</i> &nbsp; and &nbsp; <i>B<sub>i,j</sub> = i + j</i>.
</p>



<p class="ui">
<b>The above is with global indices, which go from 0 to N-1.</b>
</p>


<p class="ui">
Given the above definitions of A and B, there is a simple analytical solution
for C. There is thus a closed-form expression for the sum of the
elements of C: <b><i>N<sup>3</sup> (N - 1)<sup>2</sup> / 2</i></b>.
You will use this formula to check the validity of your matrix
multiplication implementation in Activity #2.
</p>

<p class="ui">
Have each process allocate its blocks of A, B, and C, initialize its blocks
of A and B to the appropriate values, and then print out the content of
these blocks. Each process should print its MPI rank (the "linear rank")
as well as its
2-D rank, which is easy to determine based on the linear rank. Note that MPI
provides a set of functions for handling Cartesian coordinates, which you
can also use (see the documentation for <code>MPI_Cart_rank</code> and
related functions).
</p>

<p class="ui">
For instance, here is an excerpt from the output (that generated by the process of rank 2)
for p=4 and N=8, using
<a href="./cluster_crossbar_64.xml">cluster_crossbar_64.xml</a> as a platform file
and <a href="./hostfile_64.txt">hostfile_64.txt</a> as a hostfile (since this module is
about correctness, you can use pretty much any such valid files).
</p>

<div class="ui container raised segment">
{% highlight text %}
% smpirun --cfg=smpi/running_power:1Gf -np 4 \
-platform cluster_crossbar_64.xml \
-hostfile hostfile_64.txt \
./matmul_init 8
[...]
Process rank 2 (coordinates: 1,0), block of A:
4.0 4.0 4.0 4.0
5.0 5.0 5.0 5.0
6.0 6.0 6.0 6.0
7.0 7.0 7.0 7.0
Process rank 2 (coordinates: 1,0), block of A:
4.0 5.0 6.0 7.0
5.0 6.0 7.0 8.0
6.0 7.0 8.0 9.0
7.0 8.0 9.0 10.0
[...]
{% endhighlight %}
</div>



<p class="ui">
YYY
Note that due to the convenience of simulation,
the output from one process will never be interleaved with the output of
another process. If you run this code "for real" with MPI instead of SMPI
output will be interleaved and additional synchronization will be needed
to make the output look nice.
The order in which the processes output their blocks is inconsequential.
You may want to use a barrier synchronization
to first see all blocks of A and then all blocks of B.

</p>

<p class="ui">
Obviously, we won’t run this program for large N.
The goal is simply to make sure that matrix blocks are initialized
correctly on all processes. You can run this program on any XML
platform file.

</p>




64 changes: 64 additions & 0 deletions topic_rigid_programs/matrixmultiplication/hostfile_64.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
host-0.hawaii.edu
host-1.hawaii.edu
host-2.hawaii.edu
host-3.hawaii.edu
host-4.hawaii.edu
host-5.hawaii.edu
host-6.hawaii.edu
host-7.hawaii.edu
host-8.hawaii.edu
host-9.hawaii.edu
host-10.hawaii.edu
host-11.hawaii.edu
host-12.hawaii.edu
host-13.hawaii.edu
host-14.hawaii.edu
host-15.hawaii.edu
host-16.hawaii.edu
host-17.hawaii.edu
host-18.hawaii.edu
host-19.hawaii.edu
host-20.hawaii.edu
host-21.hawaii.edu
host-22.hawaii.edu
host-23.hawaii.edu
host-24.hawaii.edu
host-25.hawaii.edu
host-26.hawaii.edu
host-27.hawaii.edu
host-28.hawaii.edu
host-29.hawaii.edu
host-30.hawaii.edu
host-31.hawaii.edu
host-32.hawaii.edu
host-33.hawaii.edu
host-34.hawaii.edu
host-35.hawaii.edu
host-36.hawaii.edu
host-37.hawaii.edu
host-38.hawaii.edu
host-39.hawaii.edu
host-40.hawaii.edu
host-41.hawaii.edu
host-42.hawaii.edu
host-43.hawaii.edu
host-44.hawaii.edu
host-45.hawaii.edu
host-46.hawaii.edu
host-47.hawaii.edu
host-48.hawaii.edu
host-49.hawaii.edu
host-50.hawaii.edu
host-51.hawaii.edu
host-52.hawaii.edu
host-53.hawaii.edu
host-54.hawaii.edu
host-55.hawaii.edu
host-56.hawaii.edu
host-57.hawaii.edu
host-58.hawaii.edu
host-59.hawaii.edu
host-60.hawaii.edu
host-61.hawaii.edu
host-62.hawaii.edu
host-63.hawaii.edu
11 changes: 6 additions & 5 deletions topic_rigid_programs/matrixmultiplication/introduction.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,16 @@ <h3 class="ui header">Overview</h3>
<h3 class="ui header">2-D Data Distribution</h3>

<p class="ui">
We consider the standard outer-product parallel matrix multiplication, as described throughout this module,
for a <i>2-D block data distribution</i>. More precisely, we consider the C = A×B multiplication
where all three matrices are square of dimensions N×N, and contain double precision floating point numbers.
As opposed to what was seen in previous topics, we now use a <i>2-D block data distribution</i>,
which complicates indexing a bit.
More precisely, we consider the C = A×B multiplication
where all three matrices are square of dimensions N×N.
The execution takes place on p processors, <b>where p is a perfect square and √p
divides N</b>. Each processor thus holds a
N/√p × N/√p square block of each matrix. </p>

<p class="ui">
For instance, with N=6, consider example matrix A as shown below:
For instance, with N=6, consider the example matrix A as shown below:
</p>

<p style="text-align:center;" class="ui">
Expand Down Expand Up @@ -83,7 +84,7 @@ <h3 class="ui header">2-D Data Distribution</h3>
</pre>
</p>

<p>At process #2, element with value 54 has local indices (1,1), but its global indices are (5,5), assuming that
<p>At process #2, element with value 54 has local indices (1,1), but its global indices are (4,4), assuming that
indices start at 0.
</p>

Expand Down

0 comments on commit 1148264

Please sign in to comment.