% $Id: aboutcryptool.tex 3714 2016-04-08 18:34:16Z esslinger $
% ............................................................................
%                 TEXT OF THE 2nd PAGE (Overview)
%
% ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

\clearpage\phantomsection

\addcontentsline{toc}{chapter}{Overview about the Content of the CrypTool Book}
\chapter*{Overview about the Content of the CrypTool Book}

\parskip 4pt
%\vskip +12 pt
The rapid spread of the Internet has led to intensified research in the
technologies involved, especially within the area of cryptography where a good
deal of new knowledge has arisen.

In this {\em book accompanying the CrypTool programs} \index{CrypTool}
you will find predominantly mathematically oriented information on using
cryptographic procedures. Also included are many sample code pieces written in the
computer algebra system {\bf SageMath}\index{SageMath} (see appendix~\ref{s:appendix-using-sage}).
The main chapters have been written by various {\bf authors}
(see appendix~\ref{s:appendix-authors}) %\hyperlink{appendix-authors}{authors}
and are therefore independent from one another. At the end of most chapters
you will find references and web links.
The sections have been enriched with many {\em footnotes}. Within the footnotes
you can see where the described functions can be called in the different CrypTool
versions.

The \hyperlink{Kapitel_1}{first chapter} explains the principles of symmetric
and asymmetric {\bf encryption} and definitions for their resistibility.

Because of didactic reasons the \hyperlink{Kapitel_PaperandPencil}
{second chapter} gives an exhaustive overview
about {\bf paper and pencil encryption methods}.

Big parts of this book are dedicated to the fascinating topic of
{\bf prime numbers} (chap. \ref{Label_Kapitel_Primes}).
%\hyperlink{Kapitel_2}{{\bf prime numbers}}.
Using numerous examples, {\bf modular arithmetic} and
{\bf elementary number theory} (chap. \ref{Chapter_ElementaryNT})
are introduced. The features of the {\bf RSA procedure} are a key aspect.

By reading chapter \ref{Chapter_ModernCryptography}
you'll gain an insight into the mathematical ideas and concepts behind
{\bf modern cryptography}.

Chapter \ref{Chapter_Hashes-and-Digital-Signatures} gives
an overview about the status of attacks against modern {\bf hash algorithms}
and is then shortly devoted to {\bf digital signatures},
which are an essential component of e-business applications.

Chapter \ref{Chapter_EllipticCurves} describes {\bf elliptic curves}:
They could be used as an alternative to RSA and in addition are extremely
well suited for implementation on smartcards.

Chapter \ref{Chapter_BitCiphers} introduces {\bf Boolean algebra}.
Boolean algebra is the foundation for most modern, symmetric encryption algorithms
as these operate on bit streams and bit groups. Principal construction
methods are described and implemented in SageMath.

Chapter \ref{Chapter_HomomorphicCiphers} describes {\bf homomorphic crypto
functions}: They are a modern research topic which got especial attention
in the course of cloud computing.

The \hyperlink{Chapter_Crypto2020}{last chapter} {\bf Crypto2020}
discusses threats for currently used cryptographic methods and introduces
alternative research approaches to achieve long-term security
of cryptographic schemes.

Whereas the CrypTool \textit{e-learning programs}\index{e-learning} motivate
and teach you how to use cryptography in practice, the \textit{book} provides
those interested in the subject with a deeper understanding of the mathematical
algorithms used -- trying to do it in an instructive way.

Within the {\bf appendices}
\ref{s:appendix-menu-overview-CT1},
\ref{s:appendix-template-overview-CT2},
\ref{s:appendix-function-overview-JCT}, and
\ref{s:appendix-function-overview-CTO}
you can gain a fast overview about the functions delivered by the different
CrypTool variants\index{CrypTool 1}\index{CrypTool 2}\index{JCrypTool} via:
\begin{itemize}
  \item the function list and
        the \hyperlink{appendix-menu-overview-CT1}
                      {menu tree of CrypTool 1 (CT1)},
  \item the function list and
        the \hyperlink{appendix-template-overview-CT2}
                      {templates in CrypTool 2 (CT2)},
  \item the \hyperlink{appendix-function-overview-JCT}
                      {function list of JCrypTool (JCT)}, and
  \item the \hyperlink{appendix-function-overview-CTO}
                      {function list of CrypTool-Online (CTO)}.
\end{itemize}

% Bernhard Esslinger, Matthias B\"uger, Bartol Filipovic, Henrik Koy,
% Roger Oyono and J\"org Cornelius Schneider
The authors would like to take this opportunity to thank their colleagues
in the particular companies and at the universities of Bochum, Darmstadt,
Frankfurt, Gie\ss en, Karlsruhe and Siegen.

\enlargethispage{12pt}
As with the e-learning program CrypTool\index{CrypTool}, the quality of the
book is enhanced by your suggestions and ideas for improvement.
We look forward to your feedback.

% Local Variables:
% TeX-master: "../script-en.tex"
% End:


\documentclass[12pt]{article}

\usepackage[margin=1in]{geometry}
\usepackage{mathptmx}
\usepackage[colorlinks, citecolor=black, linkcolor=black, %
filecolor=black, urlcolor=blue]{hyperref}
\usepackage{natbib}
\usepackage{doi}
\usepackage{amsmath}

\title{TMR: A parallel mesh generation and adaptation tool}
\author{Graeme J. Kennedy}
\date{}

\begin{document}

\maketitle

\section{Introduction}

TMR is a tool for creating meshes for 2D, mapped 2D, and 3D geometries which can then be refined using a forest of quadtrees in 2D or octrees in 3D.
The quadrilateral or hexahedral meshes created by TMR can be either second- or third-order.
TMR is designed to facilitate the creation of a hierarchical series of meshes for multigrid methods.
The refinement algorithms within TMR can be used with solution or design-based refinement or adjoint-based refinement techniques.
The interface to the underlying geometry kernel within TMR is an abstract layer that provides both geometry and topology information available from CAD.
This abstract interface has been implemented using OpenCascade so that STEP files can be loaded.

The meshing capabilities in TMR are build around two steps:
%
\begin{enumerate}
\item The creation of moderate size quadrilateral and hexahedral meshes in serial using a combination of the blossom-quad algorithm for 2D meshes and swept-mesh methods for 3D meshes.
\item Adaptive quadtreee and octree meshing and partitioning in parallel based on the input connectivity from the moderate size 2D and 3D meshes.
\end{enumerate}
%
These capabilities can be used to analyze and optimize large-scale problems efficiently on high-performance computing resources.

This document describes the algorithms and methods used in TMR and its interface.
It is divided between a high-level description of the algorithms and a detailed description of the interface in TMR.

\section{Algorithms}

The following sections describe the algorithms that are implemented with TMR at a high-level.
More detailed descriptions can be found within the comments in the code.

\subsection{Serial meshing capabilities}

The 2D and mapped 2D meshing capabilities in TMR are built around the blossom-quad algorithm~\citep{Remacle:2012:blossom-quad}.
This algorithm generally produces good quality quadrilateral meshes with some restrictions on the input geometry and the mesh size.
The maximum mesh size is approximately 1/2 the minimum geometric feature size or edge length, or 1/4 the minimum hole size.
This requirement arises because there is a minimum of 2 elements per edge or 4 elements around a hole.
Sharp corners with small acute angles limit local mesh quality and lead to the introduction of local kite elements.

Blossom-quad first builds a triangular surface mesh which is then converted to a quadrilateral mesh through an optimal weighted matching using the blossom algorithm.
TMR uses a generalization of Rebay's algorithm for efficient unstructured triangular mesh generation~\citep{Rebay:1993:unstructured-triangle}.
This algorithm generates a triangular surface mesh using a frontal method that updates a Delaunay triangularization based on the Bowyer--Watson algorithm~\citep{Shewchuk:2012:Delaunay-notes}.
Once the triangular mesh is generated, it is smoothed using a Laplacian technique.
The recombination of the triangular mesh into a quad mesh is then performed using the weighted matching algorithm.
The weights between adjacent triangles are computed based on a combined quad quality, which is a function of the maximum interior angle in the quadrilateral.
The weights are a nonlinear function of this quality metric, where angles close to $180^{\circ}$ are most heavily penalized.
Adjacent triangular elements along the boundary are also linked with imaginary quads with a large weight.

The matching algorithm selects which quads to combine in order to create the mesh with the best overall quality based on the weights.
The quad mesh is then post-processed to remove poor quality quadrilateral elements with specific topologies.
Finally, the resulting quad mesh is smoothed using a quad-specific algorithm by~\citet{Giuliani:1982:quad-smoothing}.
The smoothing algorithm minimizes a combination of the squeeze and distortion in the mesh.

\subsection{Mapped Quadtree and octree meshing}

Quadtree and octree meshing techniques provide an intermediate step between fully structured meshes and unstructured meshes.
There are several ways that an quadtree or octree can be stored.
The most natural way is to store the data in a tree structure where the leaves of the tree represent elements in the mesh.
However, this type of data structure method requires extra overhead and memory needed to traverse through the depth of the tree.

In TMR, the leaves of the quadtree or octree are stored in an array data structure directly, without referencing the nodes within the tree hierarchy.
This approach is based on the work of~\citet{BursteddeWilcoxGhattas11} and \citet{IsaacBursteddeWilcoxEtAl15}.
Within this data structure, the leaves represent either elements or nodes within the mesh.
To mesh realistic geometries, the method employs a semi-structured approach in which a global unstructured quadrilateral or hexahedral super-mesh defines the connections between quadtree or octrees.
Each quadtree or octree is then parametrically mapped to the geometry using an abstract geometry layer described below.

Each quadrant or octant within a local quadtree is uniquely identified based on its local $x$-$y$-$z$ coordinates and its refinement level.
The coordinates correspond to the lower left hand corner of the quadrant or octant and the level is used to determine the length of the side of an element.
This length can be used to determine the local coordinates of neighboring elements.
The tree can be traversed by creating parent or child quadrants.

To enable local changes in the mesh refinement, adjacent quadrants may have different levels, producing elements with different side-lengths.
Dependent or hanging nodes must be added when the mesh refinement level changes between adjacent quadrants.
To ensure finite-element compatibility between adjacent elements, dependent nodes must be constrained along an edge.
To ensure compatibility, TMR imposes that the relative difference in levels between two adjacent quadrants cannot exceed one.
This is referred to as 2:1 balancing.
After a refinement step, the global mesh must be balanced so that both intra- and inter-quadtree quadrants are 2:1 balanced.
Inter-quadtree operations are performed by mapping the quadrants from their locally-aligned coordinate system to the coordinate system of an adjacent quadtree along common shared edges or corners.

In addition to the element mesh, the semi-structured method must also create and uniquely order the nodes.
A local Morton encoding on each tree to facilitate these operations.
The order of the quadrilaterals within the global quadtree mesh is based on the unstructured global mesh.
The ownership of shared corners, edges, and faces is determined in advance to avoid duplicating node numbers.
During the node ordering process, hanging nodes are labeled and their corresponding independent neighbors are determined so that they can be eliminated using compatibility constraints during finite-element analysis.

\subsection{Interface to CAD}

The interface to CAD geometry is provided through an intermediate interface in TMR.
An implementation of this interface is provided for OpenCascade which enables models to be loaded directly from OpenCascade or intermediate tools.
For instance, OpenCascade can load geometry that has been exported in a STEP format.

TMR has internal definitions for both geometry and topological entities.
The geometric entities include nodes, curves, and surfaces, while the topological entities include vertex, edge, edge loop, face, and volume objects.
The topological entities describe the logical relationships between their underlying geometric representations.
Each vertex is associated with a node, each edge with a curve, and each face with surface.
Each edge contains a first and second vertex denoting the start and end point of the underlying curve.
An edge loop contains a series of edges that are connected together to form a closed loop on a surface.
Each face is bounded by a series of edge loops that define the extent of the face and any holes or cutouts that form the surface.
The volume object contains a series of faces that bound the volume to create a watertight surface.

The orientation of geometry objects within the model are of critical importance.
Incorrect orientation information can produce a model with an incompatible topology that does not reflect the underlying geometry.
Each edge has a natural orientation defined by its first and second vertices.
However, within an edge loop, the orientation of a particular edge may be reversed relative to its natural orientation.
Therefore, the edge loop object stores both the list of edges that form the loop and their orientations relative to the natural edge orientation.

Faces in TMR are defined in their natural orientation.
This means that the parametric areas computed are positive such that the parametric system is right-handed.
The orientation of an edge loop on a face is always defined such that the material lies to the left of an edge within an edge loop when walking the loop in its positive orientation (taking into account the relative orientation in the edge loop object).
The natural orientation may vary from the orientation used within the CAD package and so TMR stores a flag to indicate whether the orientation of the surface is flipped.
The surfaces that create a volume have an orientation, defined with an outward normal direction.
The volume object contains a list of surfaces and their orientations relative to the natural surface orientation stored in TMR that indicates whether the surface is outward facing.

The meshes within TMR are generated and stored on a component-level basis.
Meshing proceeds through the hierarchy of topological entities from vertices, edges, faces to volumes.
Each component stores its own portion of the mesh using its natural orientation.
However, when the mesh is extracted, the orientation is converted to the CAD-based orientation by flipping the orientation when it does not align.

\section{TMR Interface and Methods}

There are two interfaces to TMR: the C++ interface and the Python-level interface.
TMR is implemented in C++, so the interface through C++ contains all publicly accessible class member functions.
The Python-level interface wraps the most important classes and functions, but does not provide an interface to all lower-level operations.

There are three primary types of classes within TMR:
\begin{enumerate}
\item Geometry and topology-level classes which interface with the underlying geometry kernell
\item Serial mesh-level classes which are used to create moderate-size quadrilateral and hexahedral meshes based on the input geometry; and
\item Quadtree and Octree-level classes which are used to create, modify, refine and extract information from the quad/octrees.
\end{enumerate}
%
The methods and data stored in each of these types of classes will be described below.

Almost all classes in TMR inherit from \texttt{TMREntity}.
Those that do not are low-level data structures that are used within higher-level operations.
The \texttt{TMREntity} base class defines a reference counting scheme for all objects allocated on the heap.
Once an object is allocated, you must call \texttt{obj->incref()} and if it goes out of scope you must call \texttt{obj->decref()}.
These calls are handled automatically by the Python interface.

\subsection{Geometry-level classes}

The primary geometry-level classes used within TMR consist of entity-level classes and container-level classes. The abstract interface classes to the underlying geometry consist of:
\begin{itemize}
\item \texttt{TMRVertex}: Evaluate a node location
\item \texttt{TMREdge}: Evaluate a node location on a curve with a single parametric argument $t$. Provides access to the first and second vertices that begin/end the edge. Given a parametric location $t$ and a face, return the $(u,v)$ location on the face.
\item \texttt{TMRFace}: Evaluate a node location given a parametric location $(u,v)$. Access the edge loops that bound the face.
\end{itemize}

The other objects define collections of geometric entities:
%
\begin{itemize}
\item \texttt{TMREdgeLoop}: Contains an oriented set of edges that enclose a surface. Provides the edge list and their relative orientations in the loop.
\item \texttt{TMRVolume}: Contains an oriented collection of surfaces that enclose a volume. Provides a list of surfaces and their relative orientations in the volume.
\item \texttt{TMRModel}: Contains an ordered collection of vertices, edges, faces, and volumes that define a model geometry.
\end{itemize}

The \texttt{TMRModel} class is often created by a call to \texttt{TMR\_LoadModelFromSTEPFile( const char* )}.
This function loads the model data from the STEP file and creates the OpenCascade versions of the geometric entities and containers that define the model.
This call attempts to remove any extraneous geometry defined in the STEP file but not contained within the model.
This function creates and initializes the internal topology of the model, which can then be used in subsequent meshing operations.

A direct connection between the geometry and octree or quadtree levels is provided through the \texttt{TMRTopology} class that defines the topology for mapped-quadrilateral and hexahedral geometries.
This class can be created directly, but it is most common to create this using the mesh-level classes described below.

The class \texttt{TMRPoint}, which does not inherit from \texttt{TMREntity} contains the $x$, $y$, $z$ location of a point.

\subsection{Mesh generation-level classes}

\texttt{TMRMesh} provides the primary interface to the meshing functionality in TMR and is used to create quadrilateral and hexahedral meshes.
The actual meshing operations are performed on the root processor with rank 0, but all connectivity and location information is broadcast to all processors.
The primary functions in \texttt{TMRMesh} are:
\begin{itemize}
\item \texttt{void mesh(double)}: Mesh the model with the provided spacing and default meshing options
\item \texttt{void mesh(TMRMeshOptions, double)}: Mesh the model with the provided spacing and the provided meshing options
\item \texttt{int getMeshPoints(TMRPoint**)}: Retrieve a global array of the mesh locations
\item \texttt{int getMeshConnectivity}: Retrieve the global connectivity from the mesh
\item \texttt{TMRModel *createModelFromMesh()}: Create a geometry model based on the mesh
\item \texttt{void writeToVTK(const char*, int)}: Write the mesh to a VTK file
\item \texttt{void writeToBDF(const char*, int)}: Write the mesh to a BDF file
\end{itemize}

\texttt{TMRMeshOptions} class defines a number of options that modify the meshing algorithm. These include the following:
\begin{itemize}
\item \texttt{int triangularize\_print\_level}: Print level to provide more
  verbosity during the triangularization algorithm.
\item \texttt{int write\_mesh\_quality\_histogram}: Write out a histogram of the mesh quality in the final smoothed quadrilateral mesh.
\item \texttt{TMRFaceMeshType mesh\_type\_default}: Default mesh type either structured or unstructured. In the case that it is set to structured, the algorithm firsts checks if it is possible to use a mapped mesh, and reverts to an unstructured algorithm otherwise.
\item \texttt{int num\_smoothing\_steps}: Number of smoothing steps to apply during both the Laplacian and quad smoothing algorithms
\item \texttt{TriangleSmoothingType tri\_smoothing\_type}: Smooth the triangular mesh using either a Laplacian smoother or a spring-based analogy
\item \texttt{double frontal\_quality\_factor}: Use the mesh quality indicator to determine when to accept new triangles in the frontal algorithm.
\end{itemize}

The mesh itself is created by meshing the vertices, edges, faces, and volumes within the mesh.
These meshes are stored in the following classes
%
\begin{itemize}
\item \texttt{TMREdgeMesh}: Stores the node numbers along an edge
\item \texttt{TMRFaceMesh}: Stores the structured/unstructured surface mesh
\item \texttt{TMRVolumeMesh}: Stores the hexahedral volume mesh
\end{itemize}

TMR only supports swept volume mesh generation.
This requires the specification of additional information to indicate what surfaces should be linked and what direction should be swept.
This information is provided by indicating source and target geometry entities.
When a source/target pair is set, the mesh connectivity is copied from the source to the target.
A swept volume can only be created if:
\begin{enumerate}
\item The \texttt{TMRVolume} object contains a source/target \texttt{TMRFace} object pair that share the same number of edge loops and each source/target edge pair has the same number of nodes; and
\item All other \texttt{TMRFace} objects are structured with the same number of nodes along the swept direction.
\end{enumerate}
%
To ensure these conditions apply, it is often necessary to set source/target pairs for faces and edges.

The \texttt{TMREdgeMesh} object is created by first computing the number of nodes along its length, and then globally ordering the nodes. The number of nodes is determined based on the following criteria:
\begin{itemize}
\item If the first and second vertices are different, then at least 3 nodes are created along the edge.
\item If the first and second vertices are the same and the edge is not degenerate, then it forms a loop back on itself and at least 5 nodes are created (double counting the first and last node number).
\item If the edge is a target edge, the number of nodes is taken from the source edge.
\item Otherwise, the number of nodes is selected as an odd number that most closely matches the spacing requested along the edge.
\end{itemize}
Note that an odd number of nodes are required so that an even number of elements are created along the edge which is needed to ensure the proper functioning of the blossom-quad algorithm.

\subsection{Quad/octree-level classes}

The quadtree and octree level classes are used to create, refine and manipulate the semi-structured mesh in parallel.
The quadrants or octants are stored in a distributed manner across processors.
The following section describes the functions for the forest of octree operations.
Analogous functionality is defined for the forest of quadtree object as well.
The first step in creating a \texttt{TMROctForest} object is typically creating a \texttt{TMRTopology} object which defines a model with mapped 2D and 3D geometry that consists entirely of non-degenerate quadrilateral surfaces with four non-degenerate edges and hexahedral volumes with 6 enclosing surfaces.
This type of object can be created using the constructor \texttt{TMRTopology( MPI\_Comm, TMRModel* )}.
The \texttt{TMRTopology} object defines additional functionality that is generally required only for lower-level operations.

Once the topology object has been created, the \texttt{TMROctForest} object can be initialized. It has the following functions:
%
\begin{itemize}
\item \texttt{TMROctForest( MPI\_Comm )}: Create the forest of octree object without initializing anything
\item \texttt{void setTopology( TMRTopology* )}: Set the \texttt{TMRTopology} object for the underlying
\item \texttt{void repartition()}: Repartition the mesh across processors. This redistributes the elements so that there are an equal, or nearly equal, number of elements on each processor.
\item \texttt{void createTrees( int refine\_level )}: Create all the octrees in the mesh with the given level of refinement. Be careful, the number of elements in the mesh scales with $8^{\text{level}}$.
\item \texttt{void createRandomTrees()}: Create a set of trees with random levels of refinement. This can be useful for testing purposes
\item \texttt{TMROctForest *duplicate()}: Duplicate a forest by copying connectivity, topology and elements (but not duplicating nodes)
\item \texttt{TMROctForest *coarsen()}: Create a new forest object by coarsening all the elements within the mesh by one level, if possible. Does not create new nodes.
\item \texttt{void refine( const int refinement[] )}: Refine the elements in the node by the specified number of levels. If a negative number is supplied, coarsen the element.
\item \texttt{void balance( int balance\_corner=0 )}: Balance all the elements in the mesh to achieve a 2:1 balance
\item \texttt{void createNodes()}: Create all the nodes within the mesh
\item \texttt{TMROctantArray* getOctsWithAttribute( const char *attr )}: Get an array of octants with the desired attribute
\item \texttt{int* getNodesWithAttribute( const char *attr, int *len )}: Get an array of the nodes numbers with the desired attribute
\item \texttt{void createMeshConn( int **conn, int *nelems )}: Create and return the distributed mesh connectivity using a global ordering
\item \texttt{void createDepNodeConn()}: Create the dependent (hanging) node connectivity
\item \texttt{int getDepNodeConn( const int **ptr, const int **conn, const double **weights )}: Retrieve the dependent node connectivity from the octree object
\item \texttt{void createInterpolation( TMROctForest *coarse, TACSBVecInterp *interp )}: Create an interpolation object between two octrees that share a common topology.
\end{itemize}

\subsubsection{Typical usage}

The typical usage for a \texttt{TMROctForest} object would consist of the following:
\begin{enumerate}
\item Create the object and call \texttt{setTopology()} to set the super-mesh
\item Create an initial element mesh by calling \texttt{createTrees()}
\item Create a refined mesh by duplicating and refining the octree forest by calling \texttt{duplicate()} followed by \texttt{refine()}. Note that the length of the integer array passed to \texttt{refine} must be equal to the number of elements in the original mesh.
\item Balance the mesh and create nodes by calling \texttt{balance()} then \texttt{createNodes()}
\item Create a sequence of coarser lower-order meshes by repeated calling \texttt{duplicate()} and \texttt{coarsen()}.
\item Create interpolants between meshes for multigrid methods by calling \texttt{createInterpolation()}
\end{enumerate}

\subsection{Python-level}

An interface to TMR through Python has been created using cython.
The Python-level wrapper contains all of the objects described above without the preciding \texttt{TMR}.
To use the TMR-Python interface requires calls such as
\begin{verbatim}
from mpi4py import MPI
from tmr import TMR

# Set the communicator
comm = MPI.COMM_WORLD

# Load the model from the STEP file
geo = TMR.LoadModel('geometry.stp')

# Get the volumes
vols = geo.getVolumes()

# Get the edges/faces from the geometry
faces = geo.getFaces()
edges = geo.getEdges()

# Set the source/target relationships
faces[4].setSource(vols[0], faces[5])
edges[8].setSource(edges[5])

# Create the geometry
mesh = TMR.Mesh(comm, geo)

# Mesh the part
opts = TMR.MeshOptions()
opts.num_smoothing_steps = 0

# Mesh the geometry with the given target size
htarget = 4.0
mesh.mesh(htarget, opts=opts)
\end{verbatim}

\subsection{Error estimation algorithms}

There are two mesh refinement strategies that are implemented in TMR: the first is based on the strain energy norm, while the second is an adjoint-based refinement technique.
The strain energy based refinement method is designed to reduce the solution error in the natural strain energy norm.
This call takes the form:
%
\begin{verbatim}
double TMR_StrainEnergyErrorEst( TMRQuadForest *forest,
                                 TACSAssembler *tacs,
                                 TMRQuadForest *forest_refined,
                                 TACSAssembler *tacs_refined,
                                 double *error );
\end{verbatim}
%
The forest can be refined based on the requested target error and the solution set in TACS.

The adjoint-based refinement method requires a \texttt{TACSAssembler} object for both the current level of refinement and a uniformly refined version of the model.
The adjoint-based mesh refinement call takes the form
\begin{verbatim}
double TMR_AdjointErrorEst( TMRQuadForest *forest,
                            TACSAssembler *tacs,
                            TMRQuadForest *forest_refined,
                            TACSAssembler *tacs_refined,
                            TACSBVec *adjoint,
                            double *error,
                            double *adj_corr );
\end{verbatim}
The adjoint vector is supplied in \texttt{adjvec}.

\bibliographystyle{abbrvnat}
\bibliography{refs}

\end{document}


\section{Conclusion}
\label{sec:conclusion}
In this paper we have demonstrated how to find \emph{dynamic} witnesses
to \emph{static} type errors.
%
Dynamic witnesses provide the user with more information than static
error messages, and enable the use of standard debugging techniques
to explore \emph{how} the program ``goes wrong''.
%
Our witness search produces general witnesses, precluding the
possiblity of a valid typing for the program.
%
We have shown a novel interactive visualization of the execution of
functional programs, which can be used to \emph{show} a novice how a
witness makes their program crash.
%
Our evaluation shows that our search is effective at finding witnesses
with a 87\% success rate, and that our jump-compressed traces
effectively hide boring details of the execution, with 90\% of the
benchmarks containing less than 10 jumps.

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


%\documentclass[12pt]{article}
\documentclass[12pt,landscape]{article}

\include{preamble}

\newcommand{\instr}{\small Your answer will consist of a lowercase string (e.g. \texttt{aebgd}) where the order of the letters does not matter. \normalsize}

\title{Math 368 / 650 Fall \the\year{} \\ Midterm Examination One}
\author{Professor Adam Kapelner}

\date{Thursday, October 7, \the\year{}}

\begin{document}
\maketitle

%\noindent Full Name \line(1,0){410}

\thispagestyle{empty}

\section*{Code of Academic Integrity}

\footnotesize
Since the college is an academic community, its fundamental purpose is the pursuit of knowledge. Essential to the success of this educational mission is a commitment to the principles of academic integrity. Every member of the college community is responsible for upholding the highest standards of honesty at all times. Students, as members of the community, are also responsible for adhering to the principles and spirit of the following Code of Academic Integrity.

Activities that have the effect or intention of interfering with education, pursuit of knowledge, or fair evaluation of a student's performance are prohibited. Examples of such activities include but are not limited to the following definitions:

\paragraph{Cheating} Using or attempting to use unauthorized assistance, material, or study aids in examinations or other academic work or preventing, or attempting to prevent, another from using authorized assistance, material, or study aids. Example: using an unauthorized cheat sheet in a quiz or exam, altering a graded exam and resubmitting it for a better grade, etc.
\\

\noindent By taking this exam, you acknowledge and agree to uphold this Code of Academic Integrity. \\

%\begin{center}
%\line(1,0){250} ~~~ \line(1,0){100}\\
%~~~~~~~~~~~~~~~~~~~~~signature~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ date
%\end{center}

\normalsize

\section*{Instructions}
This exam is 70 minutes (variable time per question) and closed-book. You are allowed \textbf{one} page (front and back) of a \qu{cheat sheet}, blank scrap paper and a graphing calculator. Please read the questions carefully. Within each problem, I recommend considering the questions that are easy first and then circling back to evaluate the harder ones. No food is allowed, only drinks. %If the question reads \qu{compute,} this means the solution will be a number otherwise you can leave the answer in \textit{any} widely accepted mathematical notation which could be resolved to an exact or approximate number with the use of a computer. I advise you to skip problems marked \qu{[Extra Credit]} until you have finished the other questions on the exam, then loop back and plug in all the holes. I also advise you to use pencil. The exam is 100 points total plus extra credit. Partial credit will be granted for incomplete answers on most of the questions. \fbox{Box} in your final answers. Good luck!

\pagebreak

\problem\timedsection{10} These are questions about indicator functions. Let $a,b \in \reals$ and $b > a$. And let $X$ be a discrete rv.

\vspace{-0.2cm}\benum\truefalsesubquestionwithpoints{18}

\begin{enumerate}[(a)]
\item $\sum_{x \in \reals} \indic{x \in \braces{a}} = a$
\item $\sum_{x \in \reals} \indic{x \in \braces{a}} = 1$
\item $\sum_{x \in \reals} a\indic{x \in \braces{a}} = a$
\item $\sum_{x \in \reals} a\indic{x \in \braces{a}} = 1$
\item $\prod_{x \in \reals} a\indic{x \in \braces{a}} = a$
\item $\prod_{x \in \reals} a\indic{x \in \braces{a}} = 1$

\item $\int_{\reals} a\indic{x \in [a,b]} = a$
\item $\int_{\reals} a\indic{x \in [a,b]} = b$
\item $\int_{\reals} a\indic{x \in [a,b]} = b-a$
\item $\int_0^1 \indic{x \in [a,b]} = b-a$

\item $p(x) = p^{old}(x)\indic{x \in \support{X}}$
\item $\sum_{x \in \reals} p^{old}(x) = 1$
\item $\sum_{x \in \support{X}} p^{old}(x) = 1$

\item $\sum_{x \in \naturals} p(x) = 1$
\item $\sum_{x \in \integers} p(x) = 1$

\item $\int_{\reals} p^{old}(x) = 1$
\item $\int_{\support{X}} p^{old}(x) = 1$

\item $\sum_{x \in \support{X}} p^{old}(x)^2 = 1$

\end{enumerate}
\eenum\instr\pagebreak

%%%%%%%%%%%%%%%%%%
\problem\timedsection{11} Let $X \sim U(\braces{1,2,3})$ and $Y \sim U(\braces{-1,-2,-3})$ and $T = X + Y$.

\vspace{-0.2cm}\benum\truefalsesubquestionwithpoints{19}

\begin{enumerate}[(a)]
\item $\sum_{x \in \reals} p_{X,Y}(x,y) = 1$
\item $p_{X,Y}$ has at most 9 $x,y$ input pairs that produce nonzero values
\item $p_X^{old}(x) = 1/3$
\item $p_Y^{old}(y) = 1/3$
\item $p_T^{old}(t) = 1/9$ if $X,Y$ are independent.
\item $p_T^{old}(2) = 1/9$ if $X,Y$ are independent.
\item $p_T(t) = p_{X,Y}(x,y) \star p_{X,Y}(x,y)$
\item $p_T(t) = \sum_{x \in \reals} \sum_{y \in \reals} p_{X,Y}(x,y)$
\item The expectation of $T$ is 0 if $X,Y$ are independent.
\item The expectation of $T$ is 0 regardless of the dependence relationship of $X, Y$.
\item $\support{T} = \braces{-2, -1, 0, 1, 2}$ if $X,Y$ are independent.
\item $\support{T} = \braces{-2, -1, 0, 1, 2}$ regardless of the dependence relationship of $X, Y$.
\item $T$ could be a degenerate rv.
\item You can compute $p_T(t)$ for all $t \in \reals$ if $X,Y$ are independent given the information provided.
\item You can compute $p_T(t)$ for all $t \in \reals$ if $X,Y$ are dependent given the information provided.
\item $\cov{X}{Y} = 0$ if $X,Y$ are independent.
\item $\cov{X}{T} = 0$ if $X,Y$ are independent.
\item $\cov{Y}{T} = \expe{YT} - \expe{Y}\expe{T}$ if $X,Y$ are independent.
\item $\cov{X}{Y} = \cov{Y}{X}$ if $X,Y$ are dependent.
\end{enumerate}
\eenum\instr\pagebreak

%%%%%%%%%%%%%%%%%%
\problem\timedsection{10} Let $X \sim \geometric{p_x}$ independent of $Y \sim \geometric{p_y}$ and $T = X + Y$.

\vspace{-0.2cm}\benum\truefalsesubquestionwithpoints{15}

\begin{enumerate}[(a)]
\item The PMF of $T$ can be derived using one of the discrete convolution formulas
\item $\support{X} = \support{T}$
\item If $p_x > p_y$ it is likely that $X > Y$
\item $T \sim \geometric{p_x+p_y}$
\item $T \sim \negbin{2}{p_x+p_y}$
\item If $p_x = p_y = 1$, $T$ is a degenerate rv
\item If $p_x = p_y = 0$, $T$ is a degenerate rv
\item If $p_x = p_y = \half$ then $T \sim \negbin{2}{\half}$
\item If $p_x = p_y = \half$ then $\prob{X = Y} > 0$
\item If $p_x = p_y = \half$ then $\prob{X = Y} = \frac{3}{4}$
\item If $p_x = p_y = \half$ then $\prob{X = Y} = \oneover{3}$
\item If $p_x = p_y = \half$ then $\prob{X = Y} = \half$
\item If $p_x = p_y = \half$ then $\prob{X = Y} = \oneover{4}$
\item If $p_x = p_y = \half$ then $\prob{X = Y} = \oneover{8}$
\item If $p_x = p_y = \half$ then $\prob{X = Y} = \oneover{16}$
\end{enumerate}
\eenum\instr\pagebreak

%%%%%%%%%%%%%%%%%%
\problem\timedsection{10} Let $X \sim \geometric{p}$ independent of $Y \sim \geometric{p}$ and $T = X + Y$.

\vspace{-0.2cm}\benum\truefalsesubquestionwithpoints{13}

\begin{enumerate}[(a)]
%\item $\prob{T = 6} = 7(1-p)^7 p^2$
%\item $\prob{T = 6} = 7(1-p)^6 p^2$
%\item $\prob{T = 6} = 6(1-p)^7 p^2$
%\item $\prob{T = 6} = 6(1-p)^6 p^2$
\item $p_{X\,|\,T}(x,t) = p_{X,T}(x,t)$
\item $p_{X\,|\,T}(x,t) = p_{X,Y}(x,t) / p_T(t)$
\item $p_{X\,|\,T}(x,t) = p_{X,Y}(x,t-x) / p_T(t)$
\item $p_{X\,|\,T}(x,t) = \displaystyle \frac{(1-p)^x (1-p)^{t-x}}{(t+1) (1-p)^t}$
\item $p_{X\,|\,T}(x,t) = \displaystyle \frac{(1-p)^x (1-p)^{t-x}}{(t+1) (1-p)^t p^2}$
\item $p_{X\,|\,T}(x,t) = \displaystyle \frac{(1-p)^x (1-p)^{t-x}}{t (1-p)^{t+1}}$
\item $p_{X\,|\,T}(x,t) = \displaystyle \frac{(1-p)^x (1-p)^{t-x}}{t (1-p)^{t+1} p^2}$
\item $p_{X\,|\,T}(x,t)$ is a geometric rv
\item $p_{X\,|\,T}(x,t)$ is a negative binomial rv
\item $p_{X\,|\,T}(x,t)$ is a binomial rv
\item $p_{X\,|\,T}(x,t)$ is a poisson rv
\item $p_{X\,|\,T}(x,t)$ is a uniform discrete rv
\item $p_{X\,|\,T}(x,t)$ is a degenerate rv
\end{enumerate}
\eenum\instr\pagebreak

%%%%%%%%%%%%%%%%%%
\problem\timedsection{7} Let $\X = \bracks{\Xoneton}^\top \sim p(\x)$ and $\expe{\X} = \zerovec_n$.

\vspace{-0.2cm}\benum\truefalsesubquestionwithpoints{10}

\begin{enumerate}[(a)]
\item If $\A$ be an $m \times n$ matrix of constants, then $\expe{\A\X} = \zerovec_m$
\item $\var{\X}$ is an $n \times n$ matrix with entries $\expe{X_i X_j}$ at row $i$ and column $j$
\item $\var{\X}$ can be written as a quadratic form
\item $\var{\X}$ can be written as the expectation of an inner product
\item $\var{\X}$ can be written as the expectation of an outer product
\item If $\Xoneton \inddist$ then $\var{\X} = \I_n$
\item There exists a $p(\x)$ where $\var{\X}$ is \emph{not} symmetric
\item There exists a $p(\x)$ where $\var{\onevec^\top \X} > \sum_{i=1}^n \var{X_i}$
\item There exists a $p(\x)$ where $\var{\onevec^\top \X} = \sum_{i=1}^n \var{X_i}$
\item There exists a $p(\x)$ where $\var{\onevec^\top \X} < \sum_{i=1}^n \var{X_i}$
\end{enumerate}
\eenum\instr\pagebreak

%%%%%%%%%%%%%%%%%%
\problem\timedsection{10} Let $X_1 \sim \binomial{n_1}{p_1}$ independent of $X_2 \sim \binomial{n_2}{p_2}$ and consider the difference $D = X_1 - X_2 \sim p_D(d)$. Let $Y = -X_2$.

\vspace{-0.2cm}\benum\truefalsesubquestionwithpoints{10}

\begin{enumerate}[(a)]
\item If $n_1$ was large and $p_1 \approx 0$, then the PMF of $X_1$ can be approximated with low error by $\poisson{n_1 p_1}$
\item $X_1 \sim \displaystyle \binom{n_1}{x} p_1^x (1-p_1)^{n_1 - x} \indic{x \in \braces{0, 1, \ldots, n_1}}$
\item $X_2 \sim \displaystyle \binom{n_2}{x} p_2^x (1-p_2)^{n_2 - x} \indic{x \in \braces{0, 1, \ldots, n_2}}$
\item $Y \sim \displaystyle \binom{n_2}{-y} p_2^{-y} (1-p_2)^{n_2 + y} \indic{y \in \braces{0, 1, \ldots, n_2}}$
\item $p_D(d) = \displaystyle\sum_{x \in \reals} p_{X_1}(x) p_{X_2}(d - x)$
\item $p_D(d) = \displaystyle\sum_{x \in \support{X_1}} p_{X_1}^{old}(x) p_{X_2}^{old}(d - x) \indic{d-x \in \braces{0, 1, \ldots, n_2}}$
\item $p_D(d) = \displaystyle\sum_{x = 0}^{n_1} \binom{n_1}{x} p_1^x (1-p_1)^{n_1 - x} \binom{n_2}{x-d} p_2^{x-d} (1-p_2)^{n_2 + d - x} \indic{x-d \in \braces{0, 1, \ldots, n_2}}$
\item $p_D(d) = \displaystyle\sum_{x = d}^{n_1} \binom{n_1}{x} p_1^x (1-p_1)^{n_1 - x} \binom{n_2}{x-d} p_2^{x-d} (1-p_2)^{n_2 + d - x}$
\item $D$ is a binomial rv
\item $D$ is a poisson rv
\end{enumerate}
\eenum\instr\pagebreak

%%%%%%%%%%%%%%%%%%
\problem\timedsection{12} A large factory produces marbles with the following color distribution:

\begin{table}[h]
\centering
\begin{tabular}{l|lllll}
Color 			& Blue & Red & Green & Yellow & Orange \\ \hline
Percentage	     & 20    & 20   & 30      & 5        & 25
\end{tabular}
\end{table}

\noindent You sample 100 marbles randomly from the assembly line. Let $X_b, X_r, X_g, X_y, X_o$ denote the rv's modeling the counts of Blue, Red, Green, Yellow and Orange marbles respectively in your sample and let $\X$ denote the column vector of those rv's stacked.

\vspace{-0.2cm}\benum\truefalsesubquestionwithpoints{15}

\begin{enumerate}[(a)]
\item $X_b \sim \binomial{100}{0.2}$ and $X_r \sim \binomial{100}{0.2}$
\item $X_b + X_r \sim \binomial{200}{0.2}$
\item $\expe{X_b + X_r} = 40$.
\item $\x \in \reals$
\item $\x^\top \onevec = 100$ for all $\x \in \support{\X}$
\item $|\corr{X_b}{X_r}| = |\cov{X_b}{X_r}|$
\item $|\corr{X_b}{X_r}| > |\corr{X_y}{X_g}|$
\item $p_{X_b\,|\,X_r}(x, y)$ is undefined for $y > 100$
\item Generally speaking, the more blue marbles in the sample, the less yellow marbles in the sample.
\item If it is known that there are 8 blue marbles in the sample, then the number of yellow marbles is expected to be lower as compared to if you have no information about the number of blue marbles in the sample.\\

For the remaining questions, assume that we are told there are 8 blue marbles in the sample.
\item The number of yellow marbles will be a drawn from a $\binomial{92}{0.05}$ rv.
\item The number of yellow marbles will be a drawn from a $\binomial{92}{0.0625}$ rv.
\item The number of yellow marbles will be a drawn from a $\binomial{75}{0.05}$ rv.
\item The number of yellow marbles will be a drawn from a $\binomial{75}{0.0625}$ rv.
\item $\bracks{X_r\, X_g\, X_y\, X_o}^\top \sim \multinomial{4}{92}{\bv{p}}$ where the vector $\bv{p}$ can be computed using information provided in this problem.
\end{enumerate}
\eenum\instr\pagebreak

\end{document}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\problem\timedsection{5} These are conceptual questions ...

\vspace{-0.2cm}\benum\truefalsesubquestionwithpoints{14}

\begin{enumerate}[(a)]
\item
\end{enumerate}
\eenum\instr\pagebreak


\section{Optimization Overview}

Most intermediate representations are organised as \textit{control flow graphs (CFG)} over \textit{basic blocks}.

\subsection{Basic Blocks}

A basic block is a single entry, single exit, straight line code segment. More formally, it is a maximal sequence of instructions with no labels (except at the first instruction) and no jumps (except at the last instruction).

In the following figure, (a) is a basic block. (b) is not a basic block because it has multiple exits; (c) is not a basic block because it has multiple entries; (d) is not a basic block because it does not represent a straight line code.

\begin{figure}[htp]
\centering
\includegraphics[height=6cm]{images/1.png}
\caption{Examples and Counterexamples for basic block}
\end{figure}

Consider the following example of a single basic block:

\begin{enumerate}
    \item L:
    \item \(t := 2 * x\)
    \item \(w := t + x\)
    \item if w \(>\) 3 goto L'
\end{enumerate}

\begin{itemize}
    \item Is it ok to change (3) to \(w := 3 * x\) ?
    It is ok. If addition of two numbers is more expensive as compared to multiplication of a number with a constant, the above change can be considered an optimization.
    \item Is it ok to change (4) to if x \(>\) 1 goto L' ? It is not ok. Because here x is a finite bounded integer and due to overflow, it is possible to have \(3 * x > 3\) and not x \(>\) 1.
    \item Is it ok to remove (2) ? Depends on whether variable t is used later in the code or not.
\end{itemize}

\subsection{Control Flow Graph}

A control flow graph is a directed graph with
\begin{itemize}
    \item basic blocks as nodes
    \item edge from block A to block B if the execution can pass from the last instruction in A to the first instruction in B, for example
    \begin{itemize}
        \item the last instruction in A is: jump Lb
        \item the last instruction in A is: if id1 = id2 then goto Lb
        \item execution can fall-through from block A to block B
    \end{itemize}
\end{itemize}

Consider the following example of a CFG:

\begin{figure}[htp]
\centering
\includegraphics[height=6cm]{images/CFG Example.png}
\caption{CFG Example}
\end{figure}

The body of a method (or procedure) can be represented as a control-flow graph. There is one initial node (entry node). All "return" nodes are terminal.

\subsection{Optimization}
The optimizations are performed on the control flow graph of the intermediate representation of the code to improve program's resource utilization:

\begin{itemize}
    \item Execution Time
    \item Code Size
    \item Memory Usage
    \item Frequency of Disk I/O operations (or network operations)
    \item Power Consumption (Not same as energy)
\end{itemize}

It is important to remember that optimization should not alter the meaning of the program. It should not alter what the program computes.

For example, the following optimization changes the meaning of the program and thus, it is not a valid optimization.

w := 3 * x
if w \(>\) 3 goto L

cannot be converted to: if x \(>\) 1 goto L

\subsection{Typical Granularity of Optimization}

\begin{enumerate}
    \item \textbf{Local Optimizations}
    \begin{itemize}
        \item applied to a basic block in isolation
        \item easiest to implement
    \end{itemize}

    \item \textbf{Global Optimizations}
    \begin{itemize}
        \item applied to a CFG (method body) in isolation while crossing the boundaries of basic blocks
    \end{itemize}

    \item \textbf{Inter-Procedural Optimizations}
    \begin{itemize}
        \item applied across method (CFG) boundaries
        \item difficult to implement but usually most effective
    \end{itemize}
\end{enumerate}

\subsection{Economics of the Optimization}

Optimizations are more of an art rather than science. The current state of the art methods are based on the concept of "Maximum benefit for minimum cost" where cost can denote the development and integration costs of the optimization.

\begin{itemize}
    \item Some optimizations are hard to implement
    \item Some optimizations require large compilation time
    \item Some optimizations have low payoff (the benefits) and it is often difficult to quantify payoff.
\end{itemize}


%% FINAL PROJECT FOR ANALYTICAL MODELS
%% last modifed 05/08/06
\documentclass[times,12pt,fullpage]{article}

\usepackage{hyperref}
\usepackage{times}
\usepackage{amsmath,amssymb,amsfonts} % Typical maths resource packages

\topmargin 0.0in \oddsidemargin -0.2in \evensidemargin 0.8in
\textwidth 6.80in \textheight 8.6in
\parskip 7.6pt
\parindent 0.25in

\makeindex
\usepackage{fancyhdr}
\thispagestyle{fancy} \pagestyle{fancy} \fancyhf{}
\lhead{Multiprocessor Modeling Guide} \chead{} \rhead{Bennett
\thepage} \lfoot{} \cfoot{} \rfoot{}

\title{Modeling Guide for Multiprocessing Systems}
\author{Matthew Bennett \\
{\small School of Computing, University of Southern Mississippi} \\
{\small {\em matthew.bennett@usm.edu} \ Typeset in \LaTeX on \
\today{} } }
\date{ }

\begin{document}
\maketitle
\begin{abstract}\noindent A tremendous variety of techniques exist for the modeling and
subsequent simulation of multiprocessor systems. This paper presents
several of the approaches of Marsan et al. \cite{marsan}, in a
condensed format suitable to practical systems engineer or computer
scientist. Most of these techniques are based upon Generalized
Stochastic Petri Nets. The guide covers Bucci's Preemptive Time Nets
\cite{bucci} to fill in gaps where continuous-time models fail.
\end{abstract}

\section*{Preliminaries}
A working knowledge of multiprocessor architecture, statistical
distributions, and the modeling technique of General Stochastic
Petri Nets is required. For the latter, Murata \cite{murata}
provides a succinct and quick introduction. Markov chains are
mentioned, but the results presented do not require thorough
understanding of the device, since the work has already been
completed and proven by others.

Many of the graphs or numerical results in Marsan \cite{marsan}, and
\cite{murata} are similar enough to be asymptotically bound for some
constant. The purpose of this guide is to provide a straightforward
and efficient means of guiding the systems architect through the
modeling process and on into either simulation or analysis. The
reader may check those sources cited for more in-depth coverage of
very detailed models, since only the simplest models are presented
within.

A few taxonomic niceties will save the designer some time. The
modeling phase has been split into five categories (as in
\cite{marsan}). After the model is developed, the developer may move
on to modeling fault tolerance (\ref{fault tolerance}) or
verification (\ref{analysis}).

\section{Bus-Contention Free Architectures}
The most trivial multiprocessor system to model is one that
experiences no contention whatsoever. The canonical example in
academia (as in \cite{marsan}) is a crossbar-connected switch
between $n$ processor elements and $m$ memory elements. An analog of
crossbar switch is the Plain Old Telephone System (POTS) exchange.
These are rarely seen in practice, since the number of switches and
interconnections increases by a factor of $\Theta(mn)$, making the
interconnection network extremely expensive for even small numbers
of processors and memories.

Marsan \cite{marsan} mentions that most time spent in any
multiprocessing time is idle time due to contention for a common
resource such as a bus. It is therefore no surprise that modeling
contention-free systems is strait-forward in terms of waiting. The
analysis instead concentrates on statistical modeling of random
activity within the system. This is easily accomplished using
queueing networks, where processors are nodes without queues, and
memory modules are nodes with finite queues \cite{marsan}. For a
crossbar architecture, there is an edge from every processor element
to every memory element, since any processor may read any memory
element regardless of other processors. Some simplification occurs
when two or more processors try to access the same memory node in a
given time step: only one is served. Simulation can be performed
using the Monte Carlo method, with memory accesses being produced
using a random variable (``Markovian process'' is exponential) on
all producers (processors) and consumers (memories) in the net.

As more becomes known about the system under analysis, more can be
included in the modeling queueing network. Marsan \cite{marsan}
provides a useful ontology by asking if the devices are synchronous,
or asynchronous, and also whether memory accesses are uniform or
non-uniform between processors.

Marsan gives a number of case studies. The simplest one is
attributed to Bhandarkar \cite{bhan}, who assumes that memory
accesses are uniform across processors, with lost requests in the
case of memory contention. Bandarkar creates a vector of states that
the queueing network can take on, and then further simplifies the
amount of information at hand by creating super-states, or {\em
equivalence classes} of mutually indistinguishable states (since
processors and memories are assumed identical). He derives a formula
(Marsan fig 6.2) which can be used to algorithmically calculate
super-state transition probabilities in a Markov process, and Marsan
(p. 124, 136) gives further approximation formulas from others' work
which can be calculated in better time on a computer. These
approximations are not as important as they once were, because
computers are substantially more capable today than they were in
1986, at the time of publication. They are all valid, as they are
equivalent to the exact result obtained by Bandarkar \cite{bhan}. A
good approximation closed-form for the number of busy memory modules
$ \beta $ is given by Rau \cite{rau} , using binomial approximations
for all events (equation \ref{raus}). In this formula, $m$ counts
memories, and $p$ counts processors.
\begin{equation}\label{raus}
\frac{\sum_{i=0}^{\text{min}(m,p)-1} 2^i \binom {m-1}{i} \binom
{p-1}{i}}
{\sum_{i=0}^{\text{min}(m,p)-1}\frac{2^i}{i+1}\binom{m-1}{i}\binom{p-1}{i}}
\end{equation}
Delay models, in which memory contention requests are queued instead
of dropped, were also considered my multiple authors. Many of the
results were similar, with memory utilization expectedly being
better with the addition of queues to memory \cite{marsan} (136).
Rau's formula given above is an excellent minimum bound for back of
the envelope calculations for networks without bus contention.

\section{Shared Memory Systems}

Most real systems are not free of bus contention, because of the
nonlinear overhead cost of building complete connection networks.
When bus contention is introduced, the location of the bus with
respect to the memory elements and processors plays a vital role in
the performance and contention of the system as a whole. In this
section, we investigate the subset of systems for which a number of
processors each have a private local memory, connected by a local
bus, and must contend for access to a shared memory, which requires
control of one of one or more global buses. This multiprocessor
architecture is common to many multiprocessor, multi-core
workstations as well as supercomputers such as the classic Cray
series. Classical multi-threading problems, including deadlock
prevention and avoidance, starvation, and mutual exclusion must all
be taken into account for any shared memory systems. Marsan
\cite{marsan} lays out a number of simplifying assumptions for
modeling shared memory systems. Namely, they are: no delay when
capturing the bus (other than normal bus contention), CSMA/CA bus
discipline, and immediate release of the bus upon completion (as
with capture). Marsan uses the term ``active state'' to mean that a
processor is not currently accessing memory, ``waiting state'' to
mean that a processor is waiting for the bus or memory, and ``access
state'' to mean that the processor is currently in memory.

\subsection{Single-Bus Shared Memory Systems}
The architecture is defined by Marsan to be a single global bus
connecting a number of local buses to the shared memory resource.
Each local bus serves a single processor and its private memory.

He chooses three values to take into consideration: access times,
active times, and

\subsubsection{Exponential Distribution}
The Exponential Distribution represents . In a generalized
stochastic petri net, a single exponentially distributed random
event can be represented by a place connected to a timed transition,
where the firing rate of that transition takes on the parameter
$\lambda$ of the exponential distribution, and determines the
likelihood of that even firing depending on a continuous time
variable \cite{marsan}. An example of an Exponentially distributed
random variable is likelihood of a webserver receiving a packet at a
particular time.

\subsubsection{Erlang-k Distribution}
An Erlang-K distribution models k Exponentially distributed random
events which depend upon one another. They must occur in {\em
serial}. In the Petri Net representation, Erlang-K events should be
represented by a k-chain of exponential General Stochastic
Continuous-Timed Petri events \cite{marsan}. An example of an Erlang
distributed random variable is the number of packets to a web server
at a particular instant of time.

\subsubsection{Hyper-Exponential Distribution}
A hyper-exponentially distributed random variable counts the number
of simultaneous occurrences of an exponentially distributed random
event, such as processors trying to access the same piece of memory
simultaneously.

\subsubsection{Queueing disciplines}

Marsan \cite{marsan} defines three queueing disciplines for dealing
with memory access contention, and mutual exclusion assurance. Fixed
priority means that the processors have some preordained priority
for which can preempt one another for memory access. Process sharing
is like round-robin in that processors take their turn accessing
memory in the order they attempt to get in, but they are guaranteed
access because of some global device, like in time sharing. First
come first serve simply operated like a FIFO queue, but provides no
guarantee that a process will give up the bus to allow others in.

All of the combinations of these ideas can be analyzed, and have
been in several different papers. Again, see Marsan p. 157 for a
full bibliography of works. A simplified queuing network model or
Markov chain was successfully employed to deal with simple cases in
which access times and/or active times were equally exponentially
distributed, but Petri nets were used by Marsan to get results for
the more complex models where distribution was hyper-exponential,
Erlang, or more complicated.

In all cases, the numerical results of Marsan seem to indicate that
modeling with a generalized stochastic Petri net can produce
approximate simulation results fairly close to the analytical
results for simpler single-bus shared memory systems. The numerical
results show that the queueing discipline is not an important
consideration when modeling small systems. Since Petri nets are more
graphical and more intuitive than analytical methods, and because
the mathematics become complicated for very complex systems, the
recommended method for modeling anything complex is Generalized
Stochastic Petri nets as described in the 2nd half of Marsan
\cite{marsan} (Chapter 7 and the beginning of Chapter 8).

\subsection{Multi-Bus Shared Memory Systems}
Multi-bus Shared Memory systems can be modeled with Petri nets using
the same techniques as single-bus shared memory systems. Generally,
the number of buses are represented as tokens in a resource pool,
which is a place. Depending upon the architecture of the system, and
because of Marsan's simplifying assumptions for shared memory
systems, immediate transitions usually follow the global bus
resource pool (capturing and releasing being instantaneous, but
active, access times being exponential).

Marsan gives a full analytical treatment to many complicated
multi-bus systems, but that is unnecessary since most systems can be
easily intuitively modeled with Petri nets. Marsan et al. first
obtains upper and lower bounds limiting the gain or loss of
processing power, so any numerical results given by Petri net
modeling should fall within the domain on \cite{marsan} (p.
186-189). This is generally a good methodology, since most
bottlenecks in this configuration are assumed to stem from global
bus contention.

\section{Distributed Memory Systems}
Shared memory systems are not the only type of distributed system. A
true distributed system uses a paradigm more like message passing.
This architecture consists of one or more global buses connecting
local buses. Each local bus contains a processor and at least one
memory element. Unlike previous shared memory systems, there is no
memory connected to the global bus(es). Instead, the memory at each
local bus is used by any processor in the system, and both local and
global buses must be secured at each access step. An example of this
type of system is a computer network utilizing file sharing. Because
of the high dynamism of such networks, analysis of any but the
simplest distributed memory systems is impossible with queueing
nets. Marsan \cite{marsan} proposes tens of architectures that are
both single global bus and multiple global bus and also incorporate
distributed memory, but does not give any indication of extending
this methodology to generalized distributed systems.

To model any distributed memory systems, a Petri net should be
employed, and numerical results obtained. The reachability tree of
the Petri net can then be used to discover some analytical artifacts
of the system, such as whether it is live, as described in
\cite{murata}.

\section{Extended Petri Nets}

Bucci \cite{bucci} describes an extended version of Petri nets where
the continuous time model is replaced with discrete time events. A
global clock of some sort . A ``firing event'' occurs whenever the
random variable distribution coincides {\em as well as} the time has
come for that transition to fire. The idea of this extension is that
a Petri net can operate within a discrete time domain, following a
global clock, while keeping the ability to induce transitions from
state-to-state concurrently (ie using threads or a similar
mechanism). This dramatically increases the simulation uses of GSPN
models, but does not really add much to their descriptive power.
Bucci's method should be taken into account any time that a
simulation must occur, especially in a simulation with lots of
simultaneity.

\section{Fault Tolerance Modeling}\label{fault tolerance}
If systems include repairable components, a GSPN event (place /
timed transition) can represent the break and rapair of any
component in the system, just as

\section{Analysis and Verification}\label{analysis}
Generally, any sort of Petri Net model is good for modeling a
specific system, but can only provide numerical results. In order to
assure that those results are statistically significant, many runs
(at least 30) should be performed in simulation, and every variable
must be checked for consistency with a real system. One technique
which is liberally applied by many \cite{murata} \cite{marsan} is to
use a verifiable Markovian process or queueing network to provide
upper and lower analytical bounds. At this point, the system can
simply be built and run. Analysis can be extremely difficult, so
most of the time the Petri net approach will be more useful for the
budding system developer, without rigorous mathematical background.

\begin{thebibliography}{5}

\bibitem{marsan} Marsan, N. Balbo, G. Conte, G. "Stochastic Petri Nets." Performance Models of Multiprocessor Systems. Cambridge: MIT Press. 1986. pp. 72 - 98.

\bibitem{bucci}  Bucci, G. Correctness Verification and Performance Analysis Using Stochastic Preemptive Time Petri Nets. IEEE Transactions on Software Engineering. Vol 23, No 11. November 2005. pp. 913 - 937.

\bibitem{murata} Murata, T. Petri Nets: Properties, Analysis, and Applications. Invited Paper. Proceedings of the IEEE. Vol 77. No 4. April 1989. pp. 541 - 579.

\bibitem{bhan} Bhandarkar, D. Analysis of Memory Interference in
Multiprocessors. IEEE Transactions on Computers Vol 24. No 9.
September 1975. 897-908.

\bibitem{rau} Rau, B. Interleaved Memory Bandwidth in a Model of a Multiprocessor Computer System. IEEE Transactions on Computers Vol 28. No 9.
September 1979. 678 - 681.

\end{thebibliography}

\end{document}