\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 blank with a term from our course:
Compared to OpenMP, code written in CUDA tends to have
smaller/finer \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_.

{\bf 2.} (20) Consider the CUDA example of transforming an adjacency
matrix in Sec.\ 5.12, which we will compare to the similar OMP example
in Sec.\ 4.13.  In the latter, consider line 54.  State which line
(specify the line number) in the CUDA version this corresponds to, or if
there is none, why none is needed.

{\bf 3.} (20) Consider the CUBLAS example, Sec.\ 5.17.1.1. Suppose we
simply want to compute the product of the top row of our matrix with the
specified vector.  Show how to change line 33 to accomplish this.

{\bf 4.} Consider the Mutual Outlinks example, Sec.\ 5.8.  There each
thread does a lot of work, but here we'll change it so that each thread
will handle exactly one row of the adjacency matrix.

Line 51 will replace the 192 by {\bf tperb} (``threads per block''),
taken from the command line.  

\begin{itemize}

\item [(a)] (20) What specific restriction must we impose on the user in
terms of the grid and block sizes?

\item [(b)] (15) State which two lines must be changed in the kernel, and
show what they should be changed to.

\item [(c)] (15) When I first compiled the (unchanged) program, I got an
error message, ``atomicAdd undefined'' (but no other errors).  What
likely error did I make?

\end{itemize}


\onecolumn

\newpage

{\bf Solutions:}

{\bf 1.} granularity

{\bf 2.} No corresponding line.  The second kernel call depends on
results from the first, and CUDA will notice that will require a wait.

{\bf 3.}

\begin{lstlisting}
cublasSgemv('n',1,n,1.0,dm,n,dm,n,0.0,drs,1);
\end{lstlisting}

{\bf 4.a} Must have {\bf n = nblk * tperb}, so don't have more or fewer
threads than matrix rows.

{\bf 4.b} Change line 14 to

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

Delete line 19.

{\bf 4.c} Forgot to include {\bf -arch=s\_11} in the compile line.  This
is needed because {\bf atomicAdd()} is a function usable only on models
1.1 and above.

\end{document}


