\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=15mm,basicstyle=\footnotesize}

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

Directions: {\bf \Large Work only on this sheet} (on both sides, if
needed).  MAKE SURE TO COPY YOUR ANSWERS TO A SEPARATE SHEET FOR SENDING
ME AN ELECTRONIC COPY LATER.

{\bf Important note:}  Remember that in problems calling for R code, you
are allowed to use any built-in R function, e.g. {\bf choose()}, {\bf
sum()}, {\bf combn()} etc.  

{\bf IMPORTANT NOTE:}  All questions refer to CUDA/NVIDIA GPUs.

{\bf 1.} (15) Fill in the blank:  Having a lot of threads helps achieve
\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_ hiding.

{\bf 2.} (15) Suppose the variable {\bf n} is our problem size, and we
wish to check whether the total number of threads evenly divides this
quantity.  Write one line of code, to be run on the device, that sets
the {\bf bool} variable {\bf evenlydivides} (assumed previously
declared) to {\bf true} if this condition holds, {\bf false} otherwise.
Assume we only use the ``x dimension'' in grids and blocks.

{\bf 3.}  Consider the mutual-outlinks problem in Section 5.8, but
changed as follow:

\begin{itemize}

\item Line 14 is now

\begin{lstlisting}
i = me;
\end{lstlisting}

\item Line 19 is now blank.

\item Variables such as {\bf totth} will now be ignored.  (They would be
removed, but let's keep the specs simple here.)

\end{itemize}

Answer the questions below.  Assume the program won't ever be run with 
any partially-filled blocks; the total number of threads will be evenly
divisible by the number of blocks.

\begin{itemize}

\item [(a)] (20) One more line in the program would need to be changed.
State which one, and what the new version of the line would look line.
{\bf Note!  Put your answer on just ONE line in your submitted
electronic file.} Sample answer line:

\begin{lstlisting}
change line 45 to:  i = 168;
\end{lstlisting}

\item [(b)] (15) Which line, already a drain on execution speed, would
become even more of a drain, and why?

\end{itemize}

{\bf 4.} (20) Consider static versus dynamic scheduling of loop
operations.  Our CUDA examples, such as Line 14 in the mutual-outlink
example (original version, not changed as in Problem 3), have used
static scheduling.  Explain in one line why dynamic scheduling generally
would not be a good choice for our GPU programming.

{\bf 5.} (15) Consider the primes-finding code in Section 5.9, specifically
the function {\bf sieve()}.  This question concerns the issue of
possible bank conflicts between thread 0 and thread 1.   Fill in the
blank with a mathematical condition involving {\bf chunk}:  There will
be no bank conflicts as long as \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_.

\onecolumn

\newpage

{\bf Solutions:}

{\bf 1.}  latency

{\bf 2.}  

\begin{lstlisting}
evenlydivides = (n % (gridDim.x * blockDim.x) == 0);
\end{lstlisting}

{\bf 3.a}

\begin{lstlisting}
change line 50 to:  dim3 dimGrid(n/192,1);
\end{lstlisting} 

{\bf 3.b}  Line 20.  It would be executed more often, thus more of a
drain.

{\bf 4.}  It would be difficult to implement dynamic scheduling without
inducing a large degree of thread divergence.  Also, dynamic scheduling
requires atomic access to a work queue, which is slow on our GPUs.

{\bf 5.}  In Line 74 the two threads will be simultaneously accessing
items that are {\bf chunks} words apart in memory.  Those will be in
separate banks as long as {\bf chunk \% 32} is not 0.

\end{document}

