
The Multiphase Shared Arrays (MSA) library provides a specialized
shared memory abstraction in \charmpp\ that provides automatic memory management.
Explicitly shared memory
provides the convenience of shared memory programming while exposing
the performance issues to programmers and the ``intelligent'' ARTS.

\newcommand{\accu}{\texttt{accumulate}\xspace }
\newcommand{\wo}{\texttt{write-once}\xspace }
\newcommand{\ro}{\texttt{read-only}\xspace }
\newcommand{\sync}{\texttt{sync}\xspace }
\newcommand{\pref}{\texttt{prefetch}\xspace }

Each MSA is accessed in one specific mode
during each phase of execution:
\ro mode, in which any thread can read
any element of the array;
\wo mode, in
which each element of the array is written to (possibly multiple
times) by at most one worker thread, and no reads are allowed
and \accu mode, in which any threads can add values to any array
element, and no reads or writes are permitted.
A \sync call is used to denote the end of a phase.

We permit multiple copies of a page of data on different
processors and provide automatic fetching and caching of remote data.
For example, initially an array might be put in
\wo mode while it is populated with data from a file.
This determines the cache
behavior and the
permitted operations on the array during this phase.
\wo means every thread can write to a different element of the array.
The user is responsible for ensuring that two threads do not write to
the same element; the system helps by detecting violations.
From the cache maintenance viewpoint, each
page of the data can be over-written on it's owning processor without
worrying about transferring ownership or maintaining coherence.
At the \sync, the data is simply merged.
Subsequently, the array may be \ro for a while, thereafter data
might be \accu'd into it, followed by it returning to \ro mode.  In
the \accu phase, each local copy of the page on each processor could
have its accumulations tracked independently without maintaining page
coherence, and the results combined at the end of the phase.
The \accu operations also include set-theoretic union
operations, i.e. appending items to a set of objects would also be a
valid \accu operation.
User-level or compiler-inserted explicit \pref calls can be used to
improve performance.

A software engineering benefit that accrues from the explicitly shared
memory programming paradigm is the (relative) ease and simplicity of
programming.  No complex, buggy data-distribution and messaging
calculations are required to access data.

To use MSA in a \charmpp\ program:
\begin{itemize}
\item build \charmpp\ for your architecture, e.g. \texttt{net-linux}.
\item \texttt{cd charm/net-linux/tmp/libs/ck-libs/multiphaseSharedArrays/; make}
\item \texttt{\#include ``msa/msa.h''} in your header file.
\item Compile using \texttt{charmc} with the option ``\texttt{-module
      msa}''
\end{itemize}

The API is as follows: See the example programs in
\texttt{charm/pgms/charm++/multiphaseSharedArrays}.
