
\documentclass[twocolumn]{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}
\usepackage{fancyvrb}
\usepackage{relsize}
\usepackage{hyperref}

\begin{document}

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

Directions: {\bf Work only on this sheet} (on both sides, if needed); do
not turn in any supplementary sheets of paper. There is actually plenty
of room for your answers, as long as you organize yourself BEFORE
starting writing.

{\bf \Large Answers to fill-ins must be result in one (not more)
grammatically correct sentence.}

{\bf 1.} (15) Consider a network for communication among PEs in the form
of a ring.  PE0 is connected to PE1, PE1 to PE2, and so on, and finally
PE(n-1) is connected to PE0.  At every clock cycle, PEi sends a packet
to PE[(i+1) mod n], i = 0,1,...,n-1.  Give the entries for the table on
p.21 for this new network.

{\bf 2.} (15) Fill the blank: Consider a function {\bf f()} in a threaded
program.  If it does not access any globals, its memory accesses should
not cause cache coherency problems, because each thread has
\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_.

{\bf 3.} The Intel instruction set includes MOVS (``move string''),
which will copy a specified number of bytes from one location in memory
to another.  However, the LOCK prefix is not allowed here. 

\begin{itemize}

\item [(a)] (10) Show exactly where in our book this disallowance is
confirmed.

\item [(b)] (15) Fill the blank:  It is disallowed because allowing it 
would cause \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_. 

\end{itemize}

{\bf 4.} (15) Suppose you see code, written by someone else, that includes
a very long {\bf int} array {\bf z} on a shared-memory, 64-bit machine.  
References to {\bf z} are only of the form {\bf z[128*i]}, {\bf z[128*j]}
and so on.  Fill in the blanks:  The likely motivation for this odd code
is that the programmer is trying to avoid
\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_,
and the size of this machine's 
\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_
is
\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_.

{\bf 5.} This problem concerns the OpenMP example implementing the
Dijkstra algorithm, pages 40ff.

\begin{itemize}

\item [(a)] (20) Unlike the pseudocode on p.42, there is no {\bf Done}
array in the actual code.  Suppose we were to add code to have such an
array, named {\bf done}.  We could declare it between lines 17 and 18,
allocate it between lines 33 and 34, and initialize its values to all 0s
between lines 44 and 45.  State the line number(s) at which we could
change the code so to assign {\bf done}' elements, and state the code
needed for that.

\item [(b)] (10) Suppose I had forgotten to write line 77.  Which of the
following would then be true?  (i) The program would still work
correctly.  (ii) The program might or might not work correctly,
depending on which random numbers were generated in {\bf init()}.  (iii)
The program would definitely give incorrect results.  (iv) The program
would trigger a seg fault. (v) None of the above.

\end{itemize}

{\bf Solutions:}

{\bf 1.} latency $O(n)$, bandwidth $O(n)$, cost $O(n)$

{\bf 2.} ``...each thread has its own stack''

{\bf 3a.} footnote 6, p.23

{\bf 3b.} ``...would cause the bus to be locked for too long''

{\bf 4.} false sharing; cache blocks; $8 \times 128 (= 1024)$

{\bf 5a.}  Change line 102 to 

\begin{Verbatim}[fontsize=\relsize{-2}]
{  notdone[mv] = 0; done[mv] = 1;  }
\end{Verbatim}

{\bf 5b.} (i)

\end{document}

