% Assignment 01 for CMPT 898.02
% Paralllel Programming for Scientific Computing

% author: Raymond J. Spiteri
%   date: Mon Jan 18 09:35:10 CST 2010
%  place: Saskatoon, SK

%     completed: 
% last modified: Fri 22 Jan 2010 15:10:34 CST

\documentclass[12pt]{article}

\usepackage{macros_local}
\usepackage{amsmath}
\usepackage{alltt}

\topmargin  = 0pt
\headheight = 0pt
\headsep    = 0pt

\voffset    = 0in
\hoffset    = 0in
\textheight = 230mm
\textwidth  = 164mm

\evensidemargin = 0pt
\oddsidemargin  = 0pt

%\pagestyle{empty}

\begin{document}

\begin{center}
%\textbf{\hspace{-13mm} Name: \hspace{75mm} Student Number:} \hspace*{25mm}\\
%\vspace*{5mm}
  University of Saskatchewan\\
  Department of Computer Science \\
  \vspace*{3mm}
  \textbf{Parallel Programming for Scientific Computing} \\
  (CMPT 851) \\
  Instructor: Dr. Raymond J. Spiteri \\
  \vspace*{3mm}
  ASSIGNMENT 01 \\
  \textbf{Due: 1:00 p.m. Tuesday, February 04, 2014} \\
\end{center}

\begin{enumerate}
\item \input{asn1q1}
\item \input{asn1q2}

\newpage
\item \input{asn1q3}
\item \input{asn1q4}

\end{enumerate}

\end{document}

\item \textbf{[25 marks]} 
%
  A scalar standard {\em Brownian motion} (or {\em Wiener process})
  over $[0, T]$ is a random variable $W(t)$ that depends continuously
  on $t \in [0, T]$ and satisfies
  \begin{enumerate}
  \item $W(0) = 0$ with probability 1;

  \item For $0 \le s < t \le T$, the random variable given by the
    increment $W(t)-W(s)$ is normally distributed with mean zero and
    variance $t-s$; i.e., $W(t)- W(s) \sim \sqrt{t - s}\,\mathcal{N}(0,
    1)$, where $\mathcal N(0, 1)$ denotes a normally distributed
    random variable with zero mean and unit variance;

  \item For $0 \le s < t < u < v \le T$ the increments $W(t) - W(s)$
    and $W(v) - W(u)$ are independent.
  \end{enumerate}
  For computational purposes it is useful to consider discretized
  Brownian motion, where $W(t)$ is specified at discrete $t$
  values. We thus set $\Dt = T/N$ for some positive integer $N$ and
  let $W_j$ denote $W(t_j)$ with $t_j = j\Dt$.

  Condition~(a) says $W_0 = 0$ with probability 1. Conditions (b) and
  (c) imply
  \begin{equation*}
    W_j = W_{j-1} + dW_j, \quad j=1,2,\ldots,N,
  \end{equation*}
  where each $dW_j \sim \sqrt{\Dt}\,\mathcal{N}(0,1)$.

  Let $T=1$ and $N=500$.

  Generate a plot of 5 different discrete Brownian paths $W(t)$ versus
  $t$.

  Generate a plot of 5 different discrete paths for the function
  $u(W(t))  =e^{t+\recip{2} W(t)}$.

  Write a parallel code in OpenMP that generates $M=50,000$ paths and
  computes the average values of $U_j=u(W(t_j))$ for each $j$. Plot
  the average values on the same graph used for the 5 paths of
  $u(W(t))$. What do you notice?

  List the execution times for your code for $p=1,2,4,8$, and 16
  processors.

\newpage
\item \textbf{[25 marks]} 
%
  The {\em lenticular} volume enclosed by the intersection of two
  spheres with radii $R$ and $R'$ is given by
  \begin{equation*}
    V = \frac{\pi}{6}\, h_1 (3 r^2 + h_1^2) + \frac{\pi}{6}\, h_2(3 r^2+h_2^2),
  \end{equation*}
  where 
  \begin{equation*}
    h_1 = R(1-\cos\theta),\quad h_2=\frac{R\sin\theta(1-\cos(\alpha-\theta))}{\sin(\alpha-\theta)},\quad r=R\sin\theta,
  \end{equation*}
  $\theta$ is the half-angle subtended by $V$ at the centre of the
  sphere with radius $R$, and $\alpha$ is the {\em contact angle},
  i.e., the angle between the tangents to the each of the spheres at
  any intersection point.

  The volume $V$ is made of up of $n$ particles with volume $\nu =
  \scinot{1.7277}{-29} \text{m}^{-3}$. We apply a scaling to the
  variables to write $V = (k_B T)^{-3/2} n \nu$, where $k_B =
  \scinot{1.3806503}{-23}$ is Boltzmann's constant and $T$ is the
  temperature. The scaled $R$ is the radius of the sphere for
  $n_0=456$ particles; i.e., $R=(3n_0\nu/(4\pi))^{1/3}/\sqrt{k_B T}$.

  We wish to determine the behaviour of $\theta$ as a function of the
  contact angle $\alpha$ for a fixed temperature $T=710$ K and a range
  of $n=0,1,\ldots, 80$. 

  Use pMatlab to calculate $\theta$ for the set $\alpha =$ {\tt
    0:pi/60:pi}. Plot $\theta$ for $\alpha = \frac{\pi}{4}$ as a
  function of $n$.
%
  You may assume $\theta \in [0,\pi]$.

\item \textbf{[25 marks]} 
%
In the following exercises, assume you have $p=8$ processors. Use
  only the commands {\tt MPI\_SEND} and {\tt MPI\_RECV} for message
  passing.  Each time a processor sends or receives a message, it
  should identify itself, the processor with which it is
  communicating, and the message being passed.
  \begin{enumerate}
  \item Write a program in which one processor initializes and sends
    the message {\tt Hello World!}~to each of the other
    processors.
  \item Write a program in which one processor receives the message
    {\tt Hello World!}~from each of the other processors. The message
    should be initialized in each sending processor.
  \item Write a program in which process {\tt i} sends the message
    {\tt Greetings!}~to process {\tt MOD(i+1,p)}. Should process {\tt
      i} send its message before it receives one, or should it first
    receive and then send? Does it matter? What happens when the
    program is run on one processor?
  \end{enumerate}


%%% Local Variables: 
%%% mode: latex
%%% TeX-master: "asn1"
%%% End: 
