\documentclass[twocolumn]{article}
% \documentclass{article}

\setlength{\oddsidemargin}{-0.5in}
\setlength{\evensidemargin}{-0.5in}
\setlength{\topmargin}{0.0in}
\setlength{\headheight}{0in}
\setlength{\headsep}{0in}
\setlength{\textwidth}{7.0in}
\setlength{\textheight}{9.5in}
\setlength{\parindent}{0in}
\setlength{\parskip}{0.05in}
\setlength{\columnseprule}{0.3pt}

\setlength\columnsep{25pt}

\usepackage{fancyvrb}
\usepackage{relsize}
\usepackage{hyperref}

\usepackage{listings}
\usepackage{amsmath}

\begin{document}

\lstset{xleftmargin=5mm,framexleftmargin=10mm,basicstyle=\footnotesize}

Name: \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_

Directions: MAKE SURE TO COPY YOUR ANSWERS TO A SEPARATE SHEET FOR SENDING
ME AN ELECTRONIC COPY LATER.

{\bf 1.} (10) Fill in the blanks:  We are considering using MPI or {\bf
snow} on a certain app, with 8 workers.  For MPI, the number of sockets
used at each worker will be [  blank (a)  ] while for {\bf snow} it will
be [  blank (b)  ].

{\bf 2.} Suppose we have partitioned matrices $A$ and $B$, written in
partitioned form:

\begin{equation}
\left (
\begin{array}{rr}
A_1 & A_2 \\
0 & A_3
\end{array}
\right )
\end{equation}

\begin{equation}
\left (
\begin{array}{rr}
B_1 & B_2 \\
0 & B_3
\end{array}
\right )
\end{equation}

Here each of the submatrices in $A$ and $B$, including the one drawn as
``,0'' are $m \times m$.

\begin{itemize}

\item [(a)] (20) Let $C = AB$, with 

\begin{equation}
C =
\left (
\begin{array}{rr}
C_1 & C_2 \\
0 & C_3
\end{array}
\right )
\end{equation}

Express $C_2$ in terms of the submatrices in $A$ and $B$.  (In your
electronic submission, use ``A1'' for $A_1$ etc.  Use ' for transpose,
and {\bf use juxtaposition for multiplication}.

\item [(b)] (20) Assume all the $A_i$ are invertible (you may not need all
of them to be so), with $V_i = A_i^{-1}$.  $A^{-1}$ will then exist, and
we'll write the inverse as

\begin{equation}
Q =
\left (
\begin{array}{rr}
Q_1 & Q_2 \\
0 & Q_3
\end{array}
\right )
\end{equation}

Show $Q_2$ in terms of the $A_i$ and $V_i$.  Again, write $V_1$ as
``V1,'' etc.

\end{itemize}

{\bf 3.} (15) Consider the matrix-vector multiply {\bf snow} code on p.22.
If we were to convert it to a matrix-matrix multiply, everything in {\bf
mmul()} would pretty much carry over, except for the call to {\bf
Reduce()} in line 10.  Show what the new contents of that line would be.

{\bf 4.} Consider the MPI code on pp.19ff. Suppose {\bf N} is 10.
(Note: The fact that this latter point is stated outside of (a) and (b)
implies that it applies to both parts.  Please keep this in mind in
future quizzes.)

\begin{itemize}

\item [(a)] (20) 
How many times will Node 1 call {\bf MPI\_Send()}?

\item [(b)] (15) Suppose in line 31 we were to accidentally write 1
instead of 0.  What would happen?  Choose one of the following:

   \begin{itemize}

   \item [(i)] One of the nodes will have an execution error, e.g.
   divide by 0.

   \item [(ii)] Two of the nodes will have an execution error.

   \item [(iii)] Three of the nodes will have an execution error. 

   \item [(iv)] One of the nodes will hang.

   \item [(v)] Two of the nodes will hang.

   \item [(vi)] Three of the nodes will hang.

   \item [(vii)] No node will have an execution error or hang, but the
   printed answer will be incorrect.

   \item [(viii)] The correct answer will be printed out.

   \end{itemize}

\end{itemize}

\onecolumn

\newpage

{\bf Solutions:}

{\bf 1.a}  8 (7 worker connections, 1 manager)

{\bf 1.b}  1 manager connection

{\bf 2.a}  $A_1 B_2 + A_2 B_3$

{\bf 2.b}  We have

\begin{equation}
\left (
\begin{array}{rr}
A_1 & A_2 \\
0 & A_3
\end{array}
\right )
\left (
\begin{array}{rr}
Q_1 & Q_2 \\
0 & Q_3
\end{array}
\right )
=
\left (
\begin{array}{rr}
I & 0 \\
0 & I
\end{array}
\right )
\end{equation}

Thus $A_3 Q_3 = I$, so $Q_3 = A_3^{-1}$.

We also have $A_1 Q_2 + A_2 Q_3 = 0$.  Solving for $Q_2$, we get

\begin{equation}
Q_2 = A_1^{-1} (-A_2 Q_3) = -A_1^{-1} A_2 A_3^{-1}
\end{equation}

{\bf 3.}

\begin{lstlisting}
Reduce(rbind,mout)
\end{lstlisting}

{\bf 4.a} Node 0 will check values, 3, 5, 7 and 9 for divisibility by 3,
with 5 and 7 surviving to go on to Node 1.  The latter will take the 5
as {\bf Divisor}, and then check 7 for divisibility by 5.  The 7
survives this check and goes on to Node 2.  That accounts for one call
by Node 1 to {\bf MPI\_Send()}.  Later it will make another such call,
for END\_MSG, thus a total of 2 calls.

{\bf 4.b} The PIPE\_MSG messages become END\_MSGs.  Node 0 will send
three of them to Node 1.  The latter will use the first to set {\bf
Divisor}, and upon receiving the second, will send {\bf Dummy} to Node
2.  That node will use that message to set {\bf StartDivisor}, then wait
for a message to use for {\bf ToCheck} --- but that message will never
come.  So, the answer is (iv).

\end{document}


