handouts/pep-ho.tex
changeset 187 4d300409f2fe
parent 186 f211d9cb856e
child 188 937c995b047a
equal deleted inserted replaced
186:f211d9cb856e 187:4d300409f2fe
   212 adding just eight characters---in two places you have to add
   212 adding just eight characters---in two places you have to add
   213 \texttt{.par}. Try the same in C++ or Java!
   213 \texttt{.par}. Try the same in C++ or Java!
   214 
   214 
   215 \begin{figure}[p]
   215 \begin{figure}[p]
   216 \begin{boxedminipage}{\textwidth}
   216 \begin{boxedminipage}{\textwidth}
       
   217 
       
   218 A Scala programm for generating pretty pictures of the Mandelbrot Set 
       
   219 (\url{https://en.wikipedia.org/wiki/Mandelbrot_set}):
   217 \begin{center}    
   220 \begin{center}    
   218 \begin{tabular}{c}  
   221 \begin{tabular}{c}  
   219 \includegraphics[scale=0.15]{../pics/mand1.png}\\
   222 \includegraphics[scale=0.12]{../pics/mand1.png}
   220 \end{tabular}
   223 \end{tabular}
   221 
   224 \end{center}
   222 Wellknown Mandelbrot program for generating pretty pictures due to
   225 
   223 Benoit Mandelbrot. (\url{https://en.wikipedia.org/wiki/Mandelbrot_set})
   226 \begin{center}
   224 \bigskip
   227 \begin{tabular}{@{}p{0.45\textwidth}|p{0.45\textwidth}@{}}
   225 
   228   \bf sequential version: & \bf parallel version: (on 4 cores)\smallskip\\
   226 
   229 
   227 \begin{tabular}{@{}p{6cm}|p{6cm}@{}}
   230   {\hfill\includegraphics[scale=0.12]{../pics/mand4.png}\hfill} &
   228   \includegraphics[scale=0.15]{../pics/mand4.png} &
   231   {\hfill\includegraphics[scale=0.12]{../pics/mand3.png}\hfill} \\
   229   \includegraphics[scale=0.15]{../pics/mand3.png} \\
   232 
   230 \footnotesize
   233 {\footnotesize\begin{lstlisting}[xleftmargin=-1mm]
   231 {\begin{lstlisting}
       
   232 for (y <- (0 until H)) {
   234 for (y <- (0 until H)) {
   233   for (x <- (0 until W)) {
   235   for (x <- (0 until W)) {
   234     
   236     
   235     val c = start + 
   237     val c = start + 
   236       (x * d_x + y * d_y * i)
   238       (x * d_x + y * d_y * i)
   241 
   243 
   242     pixel(x, y, col)
   244     pixel(x, y, col)
   243   }
   245   }
   244   viewer.updateUI()
   246   viewer.updateUI()
   245 }   
   247 }   
   246 \end{lstlisting}}
   248 \end{lstlisting}}   
   247 & \\
   249 & 
       
   250 {\footnotesize\begin{lstlisting}[xleftmargin=0mm]
       
   251 for (y <- (0 until H).par) {
       
   252   for (x <- (0 until W).par) {
       
   253       
       
   254     val c = start + 
       
   255       (x * d_x + y * d_y * i)
       
   256     val iters = iterations(c, max) 
       
   257     val col = 
       
   258       if (iters == max) black 
       
   259       else colours(iters % 16)
       
   260   
       
   261     pixel(x, y, col)
       
   262   }
       
   263   viewer.updateUI()
       
   264 }   
       
   265 \end{lstlisting}}\\
       
   266 
       
   267 \centering\includegraphics[scale=0.5]{../pics/cpu2.png} &
       
   268 \centering\includegraphics[scale=0.5]{../pics/cpu1.png}\\ 
       
   269 
       
   270 
   248 \end{tabular}
   271 \end{tabular}
   249 \end{center}
   272 \end{center}
   250 \caption{Test \label{mand}}
   273 \caption{Test \label{mand}} 
   251 \end{boxedminipage}
   274 \end{boxedminipage}
   252 \end{figure}  
   275 \end{figure}  
   253 
   276 
   254 But remember that this easy parallelisation of code requires that we
   277 But remember that this easy parallelisation of code requires that we
   255 have no state in our programs\ldots{} that is no counters like
   278 have no state in our programs\ldots{} that is no counters like