
\documentclass[11pt]{article}  

\setlength{\oddsidemargin}{0in}
\setlength{\evensidemargin}{0in}

\setlength{\topmargin}{0.0in}
\setlength{\headheight}{0in}
\setlength{\headsep}{0in}
\setlength{\textwidth}{6.5in}
\setlength{\textheight}{9.5in}
\setlength{\parindent}{0in}
\setlength{\parskip}{0.05in}

\usepackage{fancyvrb}
\usepackage{relsize}
\usepackage{hyperref}

\usepackage{listings}
\usepackage{amsmath}

\begin{document}

\lstset{xleftmargin=5mm,framexleftmargin=10mm,basicstyle=\footnotesize}

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

{\bf  Directions:}

Save your work frequently. {\bf Your OMSI app must fill your laptop screen at
ALL times.}  No other electronic devices allowed.  If you forgot your
laptop or did not go through the OMSI dry run and have problems with the
app, you must submit your work on the paper quiz sheet.

{\bf 1.} Name the three basic groups of wires in a basic system bus.

{\bf 2.} On p.21, it is mentioned that MPI accommmodates
heterogeneous systems, e.g.\ in which some of the nodes are
little-endian and some are big-endian.  In class we discussed another
type of heterogeneity accommmodated by MPI.  What was it?

{\bf 3.} In the MPI example, pp.18ff, how many pairs of sockets are
set up?  How many are actually used?  EXPLAIN.

{\bf 4.} Here is the code you used to test OpenMP on your machine:

\begin{verbatim}
#include <omp.h>
#include <stdio.h>
#include <stdlib.h>

int main (int argc, char *argv[]) {
   int nthreads, tid;
   #pragma omp parallel private(nthreads, tid)
   {
     tid = omp_get_thread_num();
     printf("Hello World from thread = %d\n", tid);
     if (tid == 0) {
       nthreads = omp_get_num_threads();
       printf("Number of threads = %d\n", nthreads);
     }
   }  
}
\end{verbatim}

Use an OpenMP pragma to replace the ``if,'' with the understanding that
we no longer care which threads prints out the number of threads; we
just need it so that that printing is done only once.

{\bf For full credit, your submission must be compilable and runnable.
Try it!  That is a major point of using OMSI.}

{\bf 5.} Consider the {\bf pthreads} example, pp.8ff.  Suppose we did
not want to have global variables, and wish to change the code
accordingly.  We start small, changing only {\bf nextbase}.  State what
changes would need to be made.

\newpage

{\bf Solutions:}

{\bf 1.} data, address, control

{\bf 2.} In MPI send/receive operations, the sender and receiver may
have different word sizes, say 64-bit and 32-bit.  An {\bf MPI\_int}
in one size will be converted to the other.

{\bf 3.} There is a manager and 3 workers, so C(4,2) = 6 socket pairs
will be set up if we have a separate manager and 3 workers.  But only 2
will be used, node 0 to node 1 and node 1 to node 2.

{\bf 4.}

\begin{verbatim}
#include <omp.h>
#include <stdio.h>
#include <stdlib.h>

int main (int argc, char *argv[]) {
   int nthreads, tid;
   #pragma omp parallel private(nthreads, tid)
   {
     tid = omp_get_thread_num();
     printf("Hello World from thread = %d\n", tid);
     #pragma omp single 
     {
       nthreads = omp_get_num_threads();
       printf("Number of threads = %d\n", nthreads);
     }
   }  
}
\end{verbatim}

{\bf 5.}  Remove {\bf nextbase} from line 24, and add it to line 64.
In line 80, replace {\bf i} by a {\bf struct} containing {\bf i} and
{\bf *nextbase}.  In line 39, replace {\bf int tn} by a pointer to the
{\bf struct}, and make similar changes within the body of {\bf
worker()}.
\end{document}

