| 1 |
\documentclass[a4paper,twoside]{report} |
| 2 |
|
| 3 |
\usepackage[numbers]{natbib} |
| 4 |
\citestyle{newapa} |
| 5 |
\usepackage[utf8]{inputenc} |
| 6 |
\usepackage{fancyhdr} |
| 7 |
\usepackage{color} |
| 8 |
\usepackage{graphicx} |
| 9 |
\usepackage{listings} |
| 10 |
\usepackage{makeidx} |
| 11 |
\usepackage{comment} |
| 12 |
|
| 13 |
%%%%% Formatting %%%%% |
| 14 |
|
| 15 |
% Use the metatext environment around text that should not appear in |
| 16 |
% the final document |
| 17 |
%\newenvironment{metatext}% |
| 18 |
%{\color{blue}}% |
| 19 |
%{} |
| 20 |
\excludecomment{metatext} |
| 21 |
|
| 22 |
% Use the rationale environment around arguments for design decisions |
| 23 |
\newenvironment{rationale}% |
| 24 |
{\par\begin{quote}\textbf{Rationale:}}% |
| 25 |
{\par\end{quote}} |
| 26 |
|
| 27 |
|
| 28 |
% Use the head environment around method heads |
| 29 |
\lstnewenvironment{head}[1]% |
| 30 |
{\lstset{frame=topline,emph={#1},emphstyle=\color{blue}\textbf}}% |
| 31 |
{} |
| 32 |
|
| 33 |
|
| 34 |
% Use the parameters environment after heads |
| 35 |
\newenvironment{parameters}% |
| 36 |
{\begin{tabular}{@{\hspace{2em}}lp{0.6\textwidth}}}% |
| 37 |
{\end{tabular}\par\vspace{1mm}\par\hrule\par\vspace{5mm}} |
| 38 |
|
| 39 |
|
| 40 |
% Use the code environment around method code examples |
| 41 |
\lstnewenvironment{code}[1]% |
| 42 |
{\lstset{frame=single,caption={#1}}}% |
| 43 |
{} |
| 44 |
|
| 45 |
\renewcommand{\lstlistingname}{Example} |
| 46 |
|
| 47 |
% Use the responsible command to indicate which author is responsible |
| 48 |
% for the present section |
| 49 |
\newcommand{\responsible}[1]% |
| 50 |
{{\color{red}[#1 is responsible for this section]}} |
| 51 |
|
| 52 |
|
| 53 |
\fancyhead{} |
| 54 |
\fancyhead[L]{\slshape\leftmark} |
| 55 |
|
| 56 |
\pagestyle{fancy} |
| 57 |
\makeindex |
| 58 |
|
| 59 |
%%%%% Actual content starts here %%%%% |
| 60 |
\begin{document} |
| 61 |
|
| 62 |
\lstset{language=C++,identifierstyle=\ttfamily} |
| 63 |
|
| 64 |
\title{MUSIC --- Multi-Simulation Coordinator\\[2ex] |
| 65 |
Users Manual\\} |
| 66 |
|
| 67 |
\author{Örjan Ekeberg and Mikael Djurfeldt} |
| 68 |
|
| 69 |
\maketitle |
| 70 |
|
| 71 |
\begin{abstract} |
| 72 |
MUSIC is an API allowing large scale neuron simulators using MPI |
| 73 |
internally to exchange data during runtime. MUSIC provides |
| 74 |
mechanisms to transfer massive amounts of event information and |
| 75 |
continuous values from one parallel application to another. Special |
| 76 |
care has been taken to ensure that existing simulators can be |
| 77 |
adapted to MUSIC. In particular, MUSIC handles data transfer |
| 78 |
between applications that use different time steps and different |
| 79 |
data allocation strategies. |
| 80 |
\end{abstract} |
| 81 |
|
| 82 |
|
| 83 |
\tableofcontents |
| 84 |
|
| 85 |
\listoffigures |
| 86 |
|
| 87 |
\chapter{Introduction} |
| 88 |
|
| 89 |
This document constitutes the final specification for the |
| 90 |
multi-simulation coordinator MUSIC. |
| 91 |
|
| 92 |
\section{Scope} |
| 93 |
|
| 94 |
MUSIC is a standard for run-time exchange of data between parallel |
| 95 |
applications in a cluster environment. The standard is designed |
| 96 |
specifically for interconnecting large scale neuronal network |
| 97 |
simulators, either with each-other or with other tools. |
| 98 |
|
| 99 |
A typical usage example is illustrated in figure~\ref{fig:multisim}, |
| 100 |
where three applications ($A$, $B$, and $C$) are executing in parallel |
| 101 |
while exchanging data via MUSIC. We will refer to this as a |
| 102 |
\emph{multi-simulation}, since the participating applications |
| 103 |
typically are neuronal simulators, or tools to support such |
| 104 |
simulators. In this example, application $A$ produces runtime data |
| 105 |
which is then used by $B$ and $C$. In addition, $B$ and $C$ mutually |
| 106 |
send data to each other. The data sent between applications can be |
| 107 |
either event based, such as neuronal spikes, or graded continuous |
| 108 |
values, for example membrane voltages. |
| 109 |
|
| 110 |
\begin{figure} |
| 111 |
\begin{center} |
| 112 |
\includegraphics[width=0.5\textwidth]{figures/multisim} |
| 113 |
\caption[Typical multi-simulation]{\label{fig:multisim} |
| 114 |
Illustration of a typical multi-simulation using MUSIC. Three |
| 115 |
applications, $A$, $B$, and $C$, are exchanging data during |
| 116 |
runtime. |
| 117 |
} |
| 118 |
\end{center} |
| 119 |
\end{figure} |
| 120 |
|
| 121 |
The primary objective of MUSIC is to support multi-simulations where |
| 122 |
each participating application itself is a parallel simulator with the |
| 123 |
capacity to produce and/or consume massive amounts of data. This |
| 124 |
promotes \emph{inter-operability} by allowing models written for |
| 125 |
different simulators to be simulated together in a larger system. It |
| 126 |
also enables \emph{re-usability} of models or tools by providing a |
| 127 |
standard interface. The fact that data is spread out over a number of |
| 128 |
processors makes it non-trivial to coordinate the transfer of data so |
| 129 |
that it reaches the right destination at the right time. The task for |
| 130 |
MUSIC is to relieve the applications from handling this complexity. |
| 131 |
|
| 132 |
|
| 133 |
\section{Design Goals} |
| 134 |
|
| 135 |
\subsection{Portability} |
| 136 |
|
| 137 |
The MUSIC library and utilities have been designed to run |
| 138 |
smoothly on state-of-the-art high-performance hardware. For maximal |
| 139 |
portability, the software is written in C++, which is the de facto |
| 140 |
standard for current high-end hardware. MUSIC also provides a |
| 141 |
C-interface, making it possible for applications written in C or |
| 142 |
FORTRAN to participate in a MUSIC multi-simulation. |
| 143 |
|
| 144 |
Most, if not all, current efforts in large scale neuronal simulations |
| 145 |
are based on the MPI\index{MPI} standard. MUSIC is built on top of |
| 146 |
MPI, and uses it to run the different simulators. MUSIC provides |
| 147 |
means to allow each simulator to use MPI internally without |
| 148 |
interfering with the others. |
| 149 |
|
| 150 |
MUSIC has been developed using two reference platforms: Intel-based |
| 151 |
multi-core workstations and the IBM |
| 152 |
BlueGene/L\index{BlueGene/L}\index{IBM BlueGene} supercomputer. These |
| 153 |
platforms can be considered as two extremes, where the multi-core |
| 154 |
machine represents a small parallel environment while the BlueGene/L |
| 155 |
represents a large scale massively parallel supercomputer with special |
| 156 |
requirements. In particular, the compute nodes on the BlueGene/L do |
| 157 |
not support multiple threads or processes. |
| 158 |
|
| 159 |
|
| 160 |
\subsection{Simplicity} |
| 161 |
\label{sec:simplicity} |
| 162 |
|
| 163 |
For MUSIC to be useful, it must be possible to adapt existing |
| 164 |
simulators so that they can participate in a multi-simulation without |
| 165 |
too much effort. We rely on the simulator developers to make these |
| 166 |
adaptations. An important design goal has therefore been to adapt the |
| 167 |
design to the typical structure of current simulators. It should be |
| 168 |
possible to add MUSIC library support without invasive restructuring |
| 169 |
of the existing code. |
| 170 |
|
| 171 |
The primary requirements on an application using MUSIC is that it |
| 172 |
declares what data should be exported and imported and that it |
| 173 |
repeatedly calls a function at regular intervals during the simulation |
| 174 |
to allow MUSIC to make the actual data transfer. |
| 175 |
|
| 176 |
|
| 177 |
\subsection{Independence} |
| 178 |
|
| 179 |
The MUSIC interface ensures that each individual application does not |
| 180 |
need special adaptation to specific properties of other applications. |
| 181 |
The application only needs to adhere to the specification of the MUSIC |
| 182 |
interface in order to communicate with other applications performing |
| 183 |
complementary tasks. This makes the development of MUSIC-aware |
| 184 |
software independent of what other applications it will communicate |
| 185 |
with. |
| 186 |
|
| 187 |
We hope that this will facilitate the development of general purpose |
| 188 |
tools. For example, a researcher can develop a tool for calculating |
| 189 |
synthetic EEG from simulation data. Via MUSIC, this tool should then |
| 190 |
be useful for anybody using any neuronal simulator which supports the |
| 191 |
common MUSIC interface. |
| 192 |
|
| 193 |
|
| 194 |
\subsection{Performance} |
| 195 |
|
| 196 |
The MUSIC API has been designed to allow for data transport of high |
| 197 |
bandwidth and low latency within the cluster. One means of ensuring |
| 198 |
the best use of the hardware while maintaining portability is to use |
| 199 |
the facilities of MPI for communication. MPI encapsulates software |
| 200 |
optimizations for specific hardware. By basing the interface on MPI we |
| 201 |
can benefit from such optimizations. |
| 202 |
|
| 203 |
|
| 204 |
\subsection{Extensibility} |
| 205 |
|
| 206 |
Where possible, MUSIC allows for extensions by the application |
| 207 |
programmer. Some classes in the MUSIC API (such as the index and data |
| 208 |
maps) can be subclassed in order to provide facilities not available |
| 209 |
directly in the API. |
| 210 |
|
| 211 |
|
| 212 |
\section{Terminology} |
| 213 |
|
| 214 |
\begin{description} |
| 215 |
\item[application] We use the term |
| 216 |
\emph{application}\index{application} to denote a simulator or other |
| 217 |
program interfaced to MUSIC. Each application is a parallel |
| 218 |
program, normally running on several processors. |
| 219 |
|
| 220 |
\item[multi-simulation] We use the term |
| 221 |
\emph{multi-simulation}\index{multi-simulation} to refer to the |
| 222 |
whole parallel execution of multiple applications coordinated by |
| 223 |
MUSIC. |
| 224 |
|
| 225 |
\item[port] Each application declares its ability to produce and |
| 226 |
consume data by publishing \emph{ports}\index{port}. Ports are |
| 227 |
named by the application and provided with information about the |
| 228 |
datatype (continuous data, spike events, messages) and mapping onto |
| 229 |
different processors. Ports are either |
| 230 |
\lstinline|InputPort|s\index{input port} or |
| 231 |
\lstinline|OutputPort|s\index{output port}. |
| 232 |
|
| 233 |
\item[connection] During the setup phase, MUSIC connects pairs of |
| 234 |
ports together to form \emph{connections}\index{connection}. During |
| 235 |
the runtime phase, data is transferred over the connection from the |
| 236 |
producer of the data to the consumer. While an |
| 237 |
\lstinline|InputPort| can have only one connection, an |
| 238 |
\lstinline|OutputPort| can be connected to multiple |
| 239 |
\lstinline|InputPort|s. |
| 240 |
|
| 241 |
\item[data map] A data map\index{data map} denotes the information on |
| 242 |
where data actually resides within the application. This is |
| 243 |
typically stored internally in the port data structure. Data to be |
| 244 |
transferred over a connection can be regarded as a large array |
| 245 |
distributed over multiple processors. The data map tells on |
| 246 |
what processor each data element resides and how it should be |
| 247 |
accessed. |
| 248 |
|
| 249 |
\item[ticks] During the runtime phase, all processes in each |
| 250 |
application must make a \emph{tick}\index{tick} call at regular |
| 251 |
intervals in simulated time. At these tick points, MUSIC is allowed |
| 252 |
to use MPI to transfer data between processors. |
| 253 |
\end{description} |
| 254 |
|
| 255 |
|
| 256 |
\section{Relation to Existing Software} |
| 257 |
|
| 258 |
MUSIC is not the only software project aiming to support |
| 259 |
inter-operability between neural simulators. In this section we will |
| 260 |
briefly describe some related projects and specifically focus on how |
| 261 |
they relate to MUSIC. |
| 262 |
|
| 263 |
\paragraph{PyNN}\index{PyNN} |
| 264 |
|
| 265 |
PyNN is a Python package for simulator-independent specification of |
| 266 |
neuronal network models. It provides a low-level procedural API and a |
| 267 |
high-level object-oriented API. Neuronal network models which are |
| 268 |
specified using these API:s can be simulated on simulators supporting |
| 269 |
PyNN, such as Neuron\index{Neuron} and NEST\index{NEST}. |
| 270 |
|
| 271 |
PyNN could be extended to support multi-simulations using the MUSIC |
| 272 |
library. Such an extension would provide means for controlling the |
| 273 |
interaction between the simulator and the MUSIC library and would, for |
| 274 |
example, support publishing of named ports. |
| 275 |
|
| 276 |
It is possible, in principle, to write Python code to directly handle |
| 277 |
communication between applications in a cluster, but such a solution |
| 278 |
would be inefficient compared to using MUSIC, and might, in the end, |
| 279 |
have to address the same problems which MUSIC provides a solution to. |
| 280 |
|
| 281 |
\paragraph{Neurospaces}\index{Neurospaces} |
| 282 |
|
| 283 |
The Neurospaces project promotes inter-operability and re-usability |
| 284 |
through the development of independent software components, some of |
| 285 |
which, together, will provide one of two alternative cores of the |
| 286 |
Genesis 3 simulator. One of the components, the Neurospaces Model |
| 287 |
Container abstracts model description from the solver. Another |
| 288 |
component, the Discrete Event System can handle distribution and |
| 289 |
queuing of spikes. Components adhere to the CBI simulator |
| 290 |
architecture. |
| 291 |
|
| 292 |
It is possible to develop a MUSIC adapter consistent with the CBI |
| 293 |
simulator architecture. This would allow the Neurospaces framework, |
| 294 |
and Genesis 3, to interface to independently running applications in a |
| 295 |
cluster environment. |
| 296 |
|
| 297 |
\begin{metatext} |
| 298 |
\paragraph{Neosim}\index{Neosim} |
| 299 |
|
| 300 |
\paragraph{MOOSE}\index{MOOSE} |
| 301 |
\end{metatext} |
| 302 |
|
| 303 |
\chapter{Execution Model} |
| 304 |
|
| 305 |
\section{Phases of Execution} |
| 306 |
|
| 307 |
A multi-simulation, i.e. a set of interconnected parallel |
| 308 |
applications, is executed in three distinct phases: |
| 309 |
\begin{description} |
| 310 |
\item[\textbf{Launch}]\index{launch phase} is the phase where all the |
| 311 |
applications are started on the processors. During this phase, |
| 312 |
MUSIC is responsible for distributing and launching the application |
| 313 |
binaries on the set of MPI processes allocated to the MUSIC job. |
| 314 |
Since MPI can be initialized first when the applications have been |
| 315 |
launched, most of this work needs to be performed outside of MPI. |
| 316 |
In particular, the tasks of accessing the command line argument of |
| 317 |
the MUSIC launch utility and of determining the ranks of processes |
| 318 |
before MPI initialization therefore has to be handled separately for |
| 319 |
different MPI implementations. |
| 320 |
|
| 321 |
Technically, the launch phase begins when \texttt{mpirun} launches |
| 322 |
the MUSIC binary and ends when the Setup object constructor |
| 323 |
returns. (See further description below.) |
| 324 |
|
| 325 |
\item[\textbf{Setup}]\index{setup phase} is the phase when all |
| 326 |
applications can publish what ports they are prepared to handle |
| 327 |
along with the time step they will use and where data will be |
| 328 |
present (where in memory and/or on what processor). During the |
| 329 |
setup phase, applications can read configuration parameters |
| 330 |
communicated via the common configuration file. At the end of the |
| 331 |
setup phase, MUSIC will establish all connections. |
| 332 |
|
| 333 |
The setup phase begins when the Setup object has been created and |
| 334 |
ends when the runtime object constructor returns. |
| 335 |
|
| 336 |
\item[\textbf{Runtime}]\index{runtime phase} is the phase when |
| 337 |
simulation data is actually transferred between applications. Via |
| 338 |
\texttt{tick} calls the simulated time of applications is |
| 339 |
kept in order. |
| 340 |
|
| 341 |
The runtime phase begins when the runtime object has been created |
| 342 |
and ends when its finalize method is called. |
| 343 |
\end{description} |
| 344 |
|
| 345 |
From the application programmers point of view, these phases are |
| 346 |
clearly separated through the use of two main components of the |
| 347 |
MUSIC interface: the \emph{Setup} and the \emph{Runtime} object. The |
| 348 |
launch phase is not visible for the application since it handles the |
| 349 |
situation before the application starts. |
| 350 |
|
| 351 |
When the application initializes MUSIC at the beginning of execution |
| 352 |
it receives a specific \emph{Setup object}. This object gives access |
| 353 |
to the functionality relevant during the setup phase via its methods. |
| 354 |
When done with the setup, the application program makes the transition |
| 355 |
to the runtime phase by passing the Setup object as an argument to the |
| 356 |
\emph{runtime object} constructor which destroys the Setup object. |
| 357 |
The runtime object provides methods relevant during the runtime phase |
| 358 |
of execution. |
| 359 |
|
| 360 |
\section{Spatial Distribution of Data} |
| 361 |
\label{sec:spatialdist} |
| 362 |
|
| 363 |
Communication between applications is handled by ports. Ports are |
| 364 |
named sources (output ports) or sinks (input ports) of data flows. |
| 365 |
The data to be communicated may be differently organized in process |
| 366 |
memory on the receiver side compared to the sender side. The |
| 367 |
applications may run on different numbers of processes, and, the data |
| 368 |
may be differently distributed among the sender processes and the |
| 369 |
receiver processes, as is shown in Figure~\ref{fig:datamapping}. How |
| 370 |
does MUSIC know which data to send where? |
| 371 |
|
| 372 |
In MUSIC, there are two views of the data to be communicated over a |
| 373 |
connection. Data elements are enumerated differently according to |
| 374 |
these views. MUSIC uses \emph{shared global indices}\index{shared |
| 375 |
index}\index{global index} to enumerate the entire set of data to be |
| 376 |
sent over the connection while \emph{local indices}\index{local index} |
| 377 |
enumerate the subset of data which is stored in the memory of a |
| 378 |
particular MPI process. Data does not need to be ordered in the same |
| 379 |
way according to the two views. For example, data stored in an array |
| 380 |
may be associated with an arbitrary subset of global indices in an |
| 381 |
arbitrary order. |
| 382 |
|
| 383 |
The MUSIC library is informed about the relationship between global |
| 384 |
and local indices and how data is stored in memory during the setup |
| 385 |
phase. Two abstractions are used to carry this information: |
| 386 |
|
| 387 |
The \lstinline|IndexMap| maps local indices to global indices. That |
| 388 |
is, the \lstinline|IndexMap| tells which parts of a distributed data |
| 389 |
array are handled by the local process and how the data elements are |
| 390 |
locally ordered. |
| 391 |
|
| 392 |
The \lstinline|DataMap| encapsulates how a port accesses its data. |
| 393 |
The \lstinline|DataMap| contains an \lstinline|IndexMap|. While an |
| 394 |
index map is a mapping between two kinds of indices, the data map also |
| 395 |
contains information about where in memory data resides, how it is |
| 396 |
structured, and, the type of the data elements. The type is used for |
| 397 |
marshalling when running on a heterogeneous cluster. |
| 398 |
|
| 399 |
During setup every process of the application individually provides |
| 400 |
the port with a \lstinline|DataMap| (or an \lstinline|IndexMap| in |
| 401 |
the case of event ports). |
| 402 |
|
| 403 |
\begin{figure} |
| 404 |
\begin{center} |
| 405 |
\includegraphics[width=0.7\textwidth]{figures/datamapping} |
| 406 |
\caption[Mapping of data]{\label{fig:datamapping} Data transfer |
| 407 |
over a connection from an application running in four processes |
| 408 |
to an application running in three processes. The light gray |
| 409 |
areas in the sender and receiver represents the MUSIC port. |
| 410 |
Dashed lines divide the application into distinct processes. } |
| 411 |
\end{center} |
| 412 |
\end{figure} |
| 413 |
|
| 414 |
\begin{rationale} |
| 415 |
While connections are often used to handle the transfer of spikes |
| 416 |
from one group of neurons to another, they should not be regarded as |
| 417 |
an implementation of synaptic projections\index{projections}. |
| 418 |
Connections will only handle a direct one-to-one transport from one |
| 419 |
application to another. Re-mapping to actual receiving neurons, |
| 420 |
e.g. to implement an all-to-all projection, must be handled by one |
| 421 |
of the applications. Thus, it may be better to regard the ports as |
| 422 |
\emph{proxy-objects}\index{proxy objects}, providing indirect access |
| 423 |
to neurons simulated by the other application. |
| 424 |
\end{rationale} |
| 425 |
|
| 426 |
|
| 427 |
\section{Timing Considerations} |
| 428 |
\label{sec:timing} |
| 429 |
|
| 430 |
Different applications may use different time steps and it is the |
| 431 |
responsibility of MUSIC to ensure that data is delivered at the |
| 432 |
appropriate time. In order to minimize handshaking, both parts of a |
| 433 |
connection pair locally calculate when the actual data transfer over |
| 434 |
MPI takes place. To ensure that these calculations produce |
| 435 |
predictable results, simulation time is internally represented using |
| 436 |
integers with a global micro-timestep\index{micro-timestep} common for |
| 437 |
all applications. |
| 438 |
|
| 439 |
Simulation time\index{simulation time} is local for each application |
| 440 |
and MUSIC does not enforce unnecessary synchronization between these |
| 441 |
local clocks. Thus, an application producing data may be running |
| 442 |
ahead of another application which consumes the same data. MUSIC |
| 443 |
internally builds a schedule which ensures that data arrives at the |
| 444 |
appropriate local time in the receiving application. Scheduling |
| 445 |
becomes more complex when data is not only transferred in a |
| 446 |
feed-forward manner, i.e. when the connection graph contains loops. |
| 447 |
In this case MUSIC has to rely on the existence of sufficient delays |
| 448 |
in the simulated model, typically corresponding to axonal |
| 449 |
delays\index{axonal delay}. |
| 450 |
|
| 451 |
\begin{figure} |
| 452 |
\begin{center} |
| 453 |
\begin{minipage}{0.45\textwidth} |
| 454 |
\includegraphics[width=\textwidth]{figures/ticklogic} |
| 455 |
\caption[Timing of data transfer, slowdown]{\label{fig:timingshorter} |
| 456 |
Transfer of data when sender has a shorter |
| 457 |
tick interval than the receiver.} |
| 458 |
\end{minipage} |
| 459 |
\hfill |
| 460 |
\begin{minipage}{0.45\textwidth} |
| 461 |
\includegraphics[width=\textwidth]{figures/ticklogic2} |
| 462 |
\caption[Timing of data transfer, speedup]{\label{fig:timinglonger} |
| 463 |
Transfer of data when sender has a longer |
| 464 |
tick interval than the receiver.} |
| 465 |
\end{minipage} |
| 466 |
\end{center} |
| 467 |
\end{figure} |
| 468 |
|
| 469 |
Figures~\ref{fig:timingshorter} and \ref{fig:timinglonger} illustrate |
| 470 |
how MUSIC handles time when transferring continuous data over a |
| 471 |
connection. In figure~\ref{fig:timingshorter}, the sender application |
| 472 |
uses a shorter tick interval than the receiver. The sender side uses |
| 473 |
values sampled at the tick points to interpolate a value corresponding |
| 474 |
to the point in time when the receiver makes its tick call. |
| 475 |
|
| 476 |
The dark middle area (labelled ``MPI'') is where the actual data |
| 477 |
transfer takes place. MUSIC makes use of the fact that the receiving |
| 478 |
application can run with its simulation clock set independently of the |
| 479 |
sender. The arrows going ``backwards in time'' in this area reflect |
| 480 |
the fact that the receivers clock is lagging. This makes it possible |
| 481 |
for data to arrive in time despite the fact that it was available |
| 482 |
later (e.g. at tick \(s_2\)) than when it was arriving (at \(r_1\)), |
| 483 |
when talking about simulated time. |
| 484 |
|
| 485 |
Figure~\ref{fig:timinglonger} illustrates what happens when the |
| 486 |
receiver of continuous data is calling tick faster then the sender. |
| 487 |
The sender will then buffer up values from the preceding and current |
| 488 |
ticks and transfer this at a suitable tick call. The receiver will |
| 489 |
portion these values out by interpolating at the appropriate ticks. |
| 490 |
|
| 491 |
The strategy of having the receiver application running with a delayed |
| 492 |
local clock only works when the connection graph forms a directed |
| 493 |
acyclic graph (DAG)\index{DAG}\index{acyclic graph}\index{loops}. |
| 494 |
When loops occur it is necessary to allow for data arriving late, at |
| 495 |
least somewhere along each loop. MUSIC handles this via |
| 496 |
\emph{acceptable latency}\index{acceptable latency}\index{latency} |
| 497 |
which is a property of event input ports. The receiving application |
| 498 |
declares how late, according to simulation time, data may arrive, thus |
| 499 |
giving MUSIC room for resolving the scheduling problem. In the case |
| 500 |
of continuous data, the application specifies a |
| 501 |
\emph{delay}\index{delay} which fulfills the same purpose. |
| 502 |
|
| 503 |
In figures \ref{fig:timingshorter} and \ref{fig:timinglonger}, the |
| 504 |
sending application must be running ahead of the receiver in order to |
| 505 |
maintain the illusion that communication is instantaneous. |
| 506 |
Figure~\ref{fig:timeline} illustrates the timing relation between |
| 507 |
sender and receiver along a real time axis (wallclock time) when the |
| 508 |
receiver accepts a delay of incoming data. This allows the receiver |
| 509 |
(B) to run ahead of the sender (A), thus creating the slack necessary |
| 510 |
to make schedules for communication loops. |
| 511 |
|
| 512 |
\begin{figure} |
| 513 |
\begin{center} |
| 514 |
\includegraphics[width=0.7\textwidth]{figures/timeline} |
| 515 |
\caption[Timing of ticks]{\label{fig:timeline} |
| 516 |
This figure illustrates how MUSIC can allow one application (B) |
| 517 |
to execute ahead of another (A) when transferring continuous |
| 518 |
data. The receiver (B) has specified a delay on the input port |
| 519 |
which means that the value to be delivered at each tick (gray |
| 520 |
areas) corresponds to a simulated time in A (blue arrows) which |
| 521 |
has already happened. |
| 522 |
|
| 523 |
Note that the tick times when MUSIC actually transfers data will |
| 524 |
be aligned on the real time axis, since blocking communication |
| 525 |
is used. In practice, one of the applications will have to wait |
| 526 |
for the other to reach the same point in its execution. |
| 527 |
} |
| 528 |
\end{center} |
| 529 |
\end{figure} |
| 530 |
|
| 531 |
|
| 532 |
\section{Message Ports}\index{message port} |
| 533 |
|
| 534 |
In addition to the port types which handle continuous and spike event |
| 535 |
data, MUSIC provides \emph{message ports}. Message ports allow for |
| 536 |
transmission of arbitrary messages of, for example, control |
| 537 |
information between applications. A multi-simulation may, for |
| 538 |
example, be controlled by a script running in a Python process on one |
| 539 |
of the cluster nodes. The script may use a message port to alter a |
| 540 |
parameter or turn on a stimulus in an application at a certain point |
| 541 |
in time. |
| 542 |
|
| 543 |
Messages sent from any process on the sender side of the connection |
| 544 |
are routed to all processes on the receiver side which have announced |
| 545 |
there willingness to receive messages. Contrary to ports for |
| 546 |
continuous data, any marshalling is the responsibility of the sender |
| 547 |
and receiver application. |
| 548 |
|
| 549 |
To achieve independence between MUSIC applications, it is recommended |
| 550 |
that messages are text strings with the syntax of the interpreter |
| 551 |
language of the receiving application, and that these text strings |
| 552 |
originate from a user-specified configuration file read by the sending |
| 553 |
application. |
| 554 |
|
| 555 |
|
| 556 |
\section{Application Responsibilities} |
| 557 |
|
| 558 |
One goal of MUSIC has been to limit the responsibilities imposed on |
| 559 |
each application (c.f. section \ref{sec:simplicity}). Here we present |
| 560 |
a step-by-step list of what an application must do in order to |
| 561 |
participate in a multi-simulation. |
| 562 |
|
| 563 |
\begin{enumerate} |
| 564 |
\item \textbf{Initiate MUSIC}\index{initiate MUSIC} |
| 565 |
|
| 566 |
This is done by calling the \lstinline!Setup! function. |
| 567 |
\item \textbf{Create ports} |
| 568 |
|
| 569 |
Data to be imported and exported is identified by creating named |
| 570 |
ports. |
| 571 |
\item \textbf{Map ports}\index{map ports} |
| 572 |
|
| 573 |
MUSIC is informed about where the actual data is located. This |
| 574 |
includes information about which processor owns each data element. |
| 575 |
For continuous data it also includes information about where in |
| 576 |
memory it is stored, while for event data it specifies how to |
| 577 |
receive events. |
| 578 |
\item \textbf{Initiate the runtime phase} |
| 579 |
|
| 580 |
At this stage, MUSIC can build the plan for communication between |
| 581 |
different processes. |
| 582 |
\item \textbf{Advance simulation time}\index{tick}\index{advance time} |
| 583 |
\index{time} |
| 584 |
|
| 585 |
The application must call \lstinline!tick! at regular intervals |
| 586 |
to give MUSIC the opportunity to transfer data. |
| 587 |
\item \textbf{Finalize MUSIC}\index{finalize}\index{terminate} |
| 588 |
|
| 589 |
By calling \lstinline|finalize|, all MUSIC communication is terminated. |
| 590 |
\end{enumerate} |
| 591 |
|
| 592 |
|
| 593 |
\chapter{Starting a Multi-Simulation} |
| 594 |
|
| 595 |
\section{Overview} |
| 596 |
|
| 597 |
Parallel programs based on MPI are normally started by running a |
| 598 |
special program called \texttt{mpirun}\index{mpirun} (for MPI-1) or |
| 599 |
\texttt{mpiexec}\index{mpiexec} (for MPI-2). To start multiple |
| 600 |
applications and enable them to communicate with each other, MUSIC |
| 601 |
utilizes a special launcher program called \texttt{music}\index{music |
| 602 |
(launcher)} which, in turn, starts the different applications. |
| 603 |
Information about which applications should be started, and the |
| 604 |
communication pattern between them is described in a common |
| 605 |
\emph{configuration file}\index{configuration file}. |
| 606 |
|
| 607 |
\begin{rationale} |
| 608 |
The reason for not controlling configuration via the MUSIC API is |
| 609 |
that individual applications should remain ignorant about the |
| 610 |
structure of the full multi-simulation. Thus, the API provides |
| 611 |
methods for asking about the parts of the configuration relevant for |
| 612 |
that application, i.e. its ports, but does not expose the complete |
| 613 |
communication graph. |
| 614 |
\end{rationale} |
| 615 |
|
| 616 |
|
| 617 |
\section{The Configuration File} |
| 618 |
|
| 619 |
The main purpose of the configuration file is to control what |
| 620 |
applications to start, and to connect output ports to input ports. |
| 621 |
The configuration file specifies the number of MPI processes allocated to |
| 622 |
each application. |
| 623 |
|
| 624 |
The configuration file consists of a sequence of blocks, each starting |
| 625 |
with a non-indented bracket: |
| 626 |
|
| 627 |
\begin{quote} |
| 628 |
[\emph{application\_label}] |
| 629 |
\end{quote} |
| 630 |
|
| 631 |
\noindent Each block consists of a sequence of configuration variable |
| 632 |
definitions applying to one application. The application label is |
| 633 |
used to refer to ports of the application. A variable definition |
| 634 |
takes the form of an assignment: |
| 635 |
|
| 636 |
\begin{quote} |
| 637 |
\emph{varname} = \emph{value} |
| 638 |
\end{quote} |
| 639 |
|
| 640 |
The following variable names have special meaning to MUSIC: |
| 641 |
\begin{description} |
| 642 |
\item[binary] Pathname to application binary |
| 643 |
\item[args] Command line given to the binary |
| 644 |
\item[np] The number of MPI processes to allocate for the application |
| 645 |
\item[timebase] The length of a MUSIC micro-step, that is, the |
| 646 |
resolution of {MUSIC}:s internal clocks). (Default value is 1 |
| 647 |
ns.) |
| 648 |
\end{description} |
| 649 |
\begin{rationale} |
| 650 |
The possibility to specify the MUSIC timebase is provided since the |
| 651 |
timebase is a compromise between resolution and maximal simulation |
| 652 |
time. With 64-bit clocks, a timebase of 1 ns gives a maximal |
| 653 |
simulation time of 585 years which should be sufficient for most |
| 654 |
applications. |
| 655 |
\end{rationale} |
| 656 |
|
| 657 |
Arbitrarily named parameters may also be included in the configuration |
| 658 |
file and these parameters can be accessed from the applications. |
| 659 |
|
| 660 |
A connection between an output and input port is specified using the |
| 661 |
following syntax: |
| 662 |
\begin{quote} |
| 663 |
\emph{application\_label.port\_name} \lstinline|->| \emph{application\_label.port\_name} |
| 664 |
\end{quote} |
| 665 |
\noindent The direction of the arrow (\lstinline|->|, \lstinline|<-|) indicates the |
| 666 |
direction of data transport. An output port can be connected to |
| 667 |
multiple input ports while an input port can be connected to, at most, |
| 668 |
one output port. |
| 669 |
|
| 670 |
Optionally, the width of the connections between applications can be |
| 671 |
specified: |
| 672 |
\begin{quote} |
| 673 |
\emph{application\_label.port\_name} \lstinline|->| |
| 674 |
\emph{application\_label.port\_name} [\emph{width}] |
| 675 |
\end{quote} |
| 676 |
The application label can be omitted if it refers to the application |
| 677 |
being specified by the surrounding block. |
| 678 |
An example of a simple configuration file can be seen in |
| 679 |
section~\ref{sec:conffile}. Appendix~\ref{sec:specsyntax} specifies |
| 680 |
the formal syntax of configuration files. |
| 681 |
|
| 682 |
\begin{rationale} |
| 683 |
Information from the configuration file needs to be available both |
| 684 |
in order to launch the application binaries and during the setup |
| 685 |
phase. Since launching must be done prior to MPI initialization, it |
| 686 |
is not possible to distribute configuration information via MPI |
| 687 |
itself. In the reference implementation of MUSIC, environment |
| 688 |
variables are used to distribute this information to the |
| 689 |
applications. |
| 690 |
|
| 691 |
This information transfer is hidden within MUSIC, so a different |
| 692 |
implementation of MUSIC may use another technique. In particular, |
| 693 |
if the applications are launched from a scripting program, such as |
| 694 |
PyNN\index{PyNN}, that program must also take care of transferring |
| 695 |
the relevant configuration information to the applications. |
| 696 |
\end{rationale} |
| 697 |
|
| 698 |
|
| 699 |
\chapter{Application Program Interface} |
| 700 |
|
| 701 |
\section{Conventions} |
| 702 |
|
| 703 |
This chapter describes the API to the MUSIC library. The API is |
| 704 |
object oriented and all communication with the library is performed |
| 705 |
via instance methods of different classes of objects. Appendix |
| 706 |
\ref{app:cint} presents an alternative C interface. The most common |
| 707 |
way of passing objects as arguments in MUSIC is via pointers. The |
| 708 |
only exception is the Setup constructor. The convention regarding |
| 709 |
memory management is that the caller should make sure that objects |
| 710 |
exist in memory during the entire execution of the method, and is also |
| 711 |
responsible for the deallocation of objects afterwards. |
| 712 |
|
| 713 |
|
| 714 |
\section{Error handling} |
| 715 |
|
| 716 |
MUSIC attempts to fall back on the error handling mechanisms of MPI. |
| 717 |
A MUSIC exception thus results in a call to the MPI error handler. |
| 718 |
A particular implementation of the MUSIC library does not guarantee |
| 719 |
that it handles all kinds of errors that may occur during MUSIC calls. |
| 720 |
Each error handled by MUSIC generates an exception, and MUSIC installs |
| 721 |
suitable error codes, classes and strings so that the MPI error |
| 722 |
handler is able to generate suitable error messages. |
| 723 |
|
| 724 |
MUSIC follows the style of error handling in the MPI standard, which |
| 725 |
is described in sections 7.2 and 7.3 in the MPI 1.1 |
| 726 |
report\cite{mpi1.1} and in section 2.8 of the MPI 2.0 |
| 727 |
report\cite{mpi2.0}. The default error handler of MPI is |
| 728 |
\lstinline|MPI_ERRORS_ARE_FATAL| which means that any error handled by |
| 729 |
MUSIC will result in the program being aborted. Using the error |
| 730 |
handling of MPI requires features only described in the MPI 2.0 |
| 731 |
report. For MPI implementations which lack this support, MUSIC uses |
| 732 |
its own error handler which has the same behavior as |
| 733 |
\lstinline|MPI_ERRORS_ARE_FATAL|. |
| 734 |
|
| 735 |
\begin{rationale} |
| 736 |
MUSIC adheres to the error handling strategy of MPI since the |
| 737 |
application is already using MPI and should not need to implement a |
| 738 |
second error handling strategy when converted to use MUSIC. |
| 739 |
\end{rationale} |
| 740 |
|
| 741 |
\section{Setup} |
| 742 |
|
| 743 |
\subsection{The setup constructor} |
| 744 |
|
| 745 |
Each application initializes the MUSIC library through a call to the |
| 746 |
Setup constructor\index{setup}. This constructor, in turn, calls |
| 747 |
\lstinline|MPI::Init|\index{MPI::Init}\index{init} to initialize |
| 748 |
MPI\index{initialize MPI}. The Setup constructor creates the Setup |
| 749 |
object through which the application can retrieve configuration |
| 750 |
information, get an application wide communicator, and setup ports. |
| 751 |
|
| 752 |
\begin{head}{Setup} |
| 753 |
Setup::Setup (int& argc, char**& argv) |
| 754 |
\end{head} |
| 755 |
\begin{parameters} |
| 756 |
\lstinline|argc| &% |
| 757 |
reference to the \lstinline|argc| argument of \lstinline|main| \\ |
| 758 |
\lstinline|argv| &% |
| 759 |
reference to the \lstinline|argv| argument of \lstinline|main| \\ |
| 760 |
\end{parameters} |
| 761 |
|
| 762 |
This constructor must be called at most once; subsequent calls are |
| 763 |
erroneous. It accepts the \lstinline|argc| and \lstinline|argv| that are |
| 764 |
provided by the arguments to \lstinline|main|. |
| 765 |
\index{argc}\index{argv} |
| 766 |
|
| 767 |
\begin{code}{Initializing MUSIC} |
| 768 |
int main (int argc, char *argv[]) |
| 769 |
{ |
| 770 |
MUSIC::Setup* setup = new MUSIC::Setup (argc, argv); |
| 771 |
|
| 772 |
/* parse arguments */ |
| 773 |
/* rest of program */ |
| 774 |
} |
| 775 |
\end{code} |
| 776 |
|
| 777 |
\begin{rationale} |
| 778 |
The idea behind creating a specific setup object is to ensure that |
| 779 |
the application does not accidentally call functions relevant only |
| 780 |
for the setup phase at other times. |
| 781 |
\end{rationale} |
| 782 |
|
| 783 |
|
| 784 |
\subsection{Communicators} |
| 785 |
|
| 786 |
During a multi-simulation the MUSIC library will create a unique |
| 787 |
intra-communi\-cator over the group of processes assigned to each |
| 788 |
application. This application wide communicator takes the role of the |
| 789 |
global communicator \lstinline|MPI::COMM_WORLD| and is retrieved from |
| 790 |
the setup object through a call to the \lstinline|communicator| |
| 791 |
method.\index{communicator} |
| 792 |
|
| 793 |
\begin{head}{communicator} |
| 794 |
MPI::Intracomm Setup::communicator () |
| 795 |
\end{head} |
| 796 |
\begin{parameters} |
| 797 |
\emph{return value} & the application wide communicator \\ |
| 798 |
\end{parameters} |
| 799 |
|
| 800 |
The application is supposed to use the application wide communicator |
| 801 |
in place of |
| 802 |
\lstinline|MPI::COMM_WORLD|\index{MPI::COMM\_WORLD}\index{COMM\_WORLD}. If |
| 803 |
the application binary has been launched using \lstinline|mpirun| |
| 804 |
instead of the \lstinline|music| utility, \lstinline|communicator ()| |
| 805 |
will return \lstinline|MPI::COMM_WORLD| as the application wide |
| 806 |
communicator. |
| 807 |
|
| 808 |
\pagebreak |
| 809 |
\index{rank}\index{Get\_rank} |
| 810 |
\begin{code}{Accessing the application-wide communicator} |
| 811 |
/* communicator with global scope */ |
| 812 |
extern MPI_Comm comm; |
| 813 |
|
| 814 |
... |
| 815 |
{ |
| 816 |
... |
| 817 |
comm = setup->communicator (); |
| 818 |
int rank = comm.Get_rank (); |
| 819 |
... |
| 820 |
} |
| 821 |
\end{code} |
| 822 |
|
| 823 |
\begin{rationale} |
| 824 |
An alternative to provide the \lstinline|communicator| function |
| 825 |
would have been to redefine \lstinline|MPI::COMM_WORLD|. This would |
| 826 |
ensure that an application does not accidentally use the global |
| 827 |
communicator. However, it may not always be possible to dynamically |
| 828 |
redefine this variable in all MPI implementations, so for the sake |
| 829 |
of portability, we have chosen a more straightforward technique. |
| 830 |
\end{rationale} |
| 831 |
|
| 832 |
|
| 833 |
\subsection{Port creation} |
| 834 |
|
| 835 |
Ports\index{ports} are named sources (output ports) or sinks (input |
| 836 |
ports) of data flows. Output and input ports are distinct classes. |
| 837 |
Ports are further subdivided into distinct classes depending on |
| 838 |
whether they handle continuous data, event data or messages. |
| 839 |
|
| 840 |
\index{publish output}\index{publish input} |
| 841 |
\begin{head}{publishContOutput,publishContInput, |
| 842 |
,publishEventOutput,publishEventInput, |
| 843 |
,publishMessageOutput,publishMessageInput} |
| 844 |
ContOutputPort* |
| 845 |
Setup::publishContOutput (string id) |
| 846 |
|
| 847 |
ContInputPort* |
| 848 |
Setup::publishContInput (string id) |
| 849 |
|
| 850 |
EventOutputPort* |
| 851 |
Setup::publishEventOutput (string id) |
| 852 |
|
| 853 |
EventInputPort* |
| 854 |
Setup::publishEventInput (string id) |
| 855 |
|
| 856 |
MessageOutputPort* |
| 857 |
Setup::publishMessageOutput (string id) |
| 858 |
|
| 859 |
MessageInputPort* |
| 860 |
Setup::publishMessageInput (string id) |
| 861 |
\end{head} |
| 862 |
\begin{parameters} |
| 863 |
\lstinline|id| & port name \\ |
| 864 |
\emph{return value} & an unmapped port \\ |
| 865 |
\end{parameters} |
| 866 |
|
| 867 |
Ports have two stages in life: the \emph{unmapped} stage and the |
| 868 |
\emph{mapped} stage. A port is unmapped when created. The MUSIC |
| 869 |
configuration file specifies connections between ports. It is |
| 870 |
possible to ask an unmapped port if it is connected, if it has a width |
| 871 |
specified and, if so, what width it has. A port becomes mapped when |
| 872 |
its method \lstinline|map| is called. |
| 873 |
|
| 874 |
\begin{code}{Creating an unmapped port} |
| 875 |
ContOutputPort* out = |
| 876 |
setup->publishContOutput ("out"); |
| 877 |
\end{code} |
| 878 |
|
| 879 |
\subsection{General port methods} |
| 880 |
|
| 881 |
The port API includes methods to ask a port if it is connected, if it |
| 882 |
has a width specified, and, if so, what that width is. |
| 883 |
|
| 884 |
\subsubsection{Port connectivity} |
| 885 |
|
| 886 |
The method \lstinline|isConnected| is used to check if the user has |
| 887 |
specified a connection of this port to another port in the |
| 888 |
configuration file. |
| 889 |
|
| 890 |
\index{isConnected}\index{connected port} |
| 891 |
\begin{head}{isConnected} |
| 892 |
bool Port::isConnected () |
| 893 |
\end{head} |
| 894 |
\begin{parameters} |
| 895 |
\emph{return value} & \lstinline|true| only if connected\\ |
| 896 |
\end{parameters} |
| 897 |
|
| 898 |
This method is typically used in cases where the use of some of the |
| 899 |
ports of the application is optional. In such a case, it is not |
| 900 |
sensible to allocate any application resources to support the data |
| 901 |
flow in question. One example is if one wants to support output of |
| 902 |
membrane potentials from a certain population of cells, but don't want |
| 903 |
to waste resources if no one is listening. |
| 904 |
|
| 905 |
\begin{code}{Optional handling of ports} |
| 906 |
ContOutputPort* out = |
| 907 |
setup->publishContOutput ("Vm"); |
| 908 |
/* map port only if anyone is listening */ |
| 909 |
if (out->isConnected ()) |
| 910 |
/* allocate application resources and map port */ |
| 911 |
\end{code} |
| 912 |
|
| 913 |
\subsubsection{Port width} |
| 914 |
\label{sec:width} |
| 915 |
|
| 916 |
The width of a port\index{port width}, that is the number of data |
| 917 |
elements transferred in parallel from a cont port or the largest |
| 918 |
possible id of an event port $+$ 1, can be specified in the |
| 919 |
configuration file. This should be thought of as a request for a |
| 920 |
given width. Applications can use the method \lstinline|hasWidth| to |
| 921 |
determine if a width has been specified and retrieve it using |
| 922 |
\lstinline|width|. Message ports do not have width. |
| 923 |
|
| 924 |
\index{hasWidth} |
| 925 |
\begin{head}{hasWidth} |
| 926 |
bool Port::hasWidth () |
| 927 |
\end{head} |
| 928 |
\begin{parameters} |
| 929 |
\emph{return value} & \lstinline|true| only if port width has been |
| 930 |
specified \\ |
| 931 |
\end{parameters} |
| 932 |
|
| 933 |
\index{width} |
| 934 |
\begin{head}{width} |
| 935 |
int Port::width () |
| 936 |
\end{head} |
| 937 |
\begin{parameters} |
| 938 |
\emph{return value} & port width \\ |
| 939 |
\end{parameters} |
| 940 |
|
| 941 |
\begin{rationale} |
| 942 |
Applications can use the above methods to adapt their port width. A |
| 943 |
typical usage would be a general purpose post-processing tool which |
| 944 |
receives information from an ongoing simulation. Such a tool can |
| 945 |
publish a number of optional input ports and then use |
| 946 |
\lstinline|isConnected| and \lstinline|width| to adapt its internal |
| 947 |
processing depending on what kind of data source it is actually |
| 948 |
connected to. See example \ref{code:adaptivewidth}. |
| 949 |
\end{rationale} |
| 950 |
|
| 951 |
|
| 952 |
\begin{code}{Publishing port of adaptive width\label{code:adaptivewidth}} |
| 953 |
{ |
| 954 |
... |
| 955 |
/* Publishing a port of adaptive width */ |
| 956 |
double* stateVars; |
| 957 |
MUSIC::ContInputPort* in = |
| 958 |
setup->publishContInput ("in"); |
| 959 |
if (!in->hasWidth ()) |
| 960 |
/* report error */ |
| 961 |
else |
| 962 |
{ |
| 963 |
int size = in->width (); |
| 964 |
/* for clarity we assume that nElements |
| 965 |
is a multiple of size */ |
| 966 |
int nLocal = nElements / size; |
| 967 |
/* example continues as in next example */ |
| 968 |
... |
| 969 |
|
| 970 |
} |
| 971 |
} |
| 972 |
\end{code} |
| 973 |
|
| 974 |
|
| 975 |
\subsection{Mapping cont ports} |
| 976 |
\index{cont ports} |
| 977 |
|
| 978 |
A port is informed about what data exists locally and how to access it |
| 979 |
by mapping it. Cont ports transfer data from or to memory during |
| 980 |
\lstinline|tick| calls and need to know the layout of data in memory. |
| 981 |
In addition, the marshalling (conversion between different bit level |
| 982 |
representations) performed on heterogeneous clusters requires |
| 983 |
information about the data type being transferred. This information |
| 984 |
is captured by the data map argument \lstinline|dMap|. The |
| 985 |
\lstinline|DataMap| type is described in section \ref{sec:datamap} |
| 986 |
below. |
| 987 |
|
| 988 |
\clearpage |
| 989 |
\index{map}\index{mapping cont ports} |
| 990 |
\begin{head}{map} |
| 991 |
void ContOutputPort::map (DataMap* dMap, |
| 992 |
int maxBuffered) |
| 993 |
|
| 994 |
void ContInputPort::map (DataMap* dMap, |
| 995 |
double delay, |
| 996 |
int maxBuffered, |
| 997 |
bool interpolate) |
| 998 |
\end{head} |
| 999 |
\begin{parameters} |
| 1000 |
\lstinline|dMap| & the data map associated with the port \\ |
| 1001 |
\lstinline|delay| & delay of data arrival in simulation time (s) \\ |
| 1002 |
\lstinline|maxBuffered| & maximal amount of data buffered (ticks) |
| 1003 |
\\ |
| 1004 |
\lstinline|interpolate| & enable interpolation (boolean) \\ |
| 1005 |
\end{parameters} |
| 1006 |
|
| 1007 |
The optional argument \lstinline|delay| informs MUSIC of when, |
| 1008 |
according to simulation time, to sample data on the sender side. If |
| 1009 |
enabled, linear interpolation is used to obtain an approximation of |
| 1010 |
the state at this time. The default delay is zero. Delayed continuous |
| 1011 |
data may be used in connectionist networks when modeling brain |
| 1012 |
pathways. A delay is \emph{required} at some point when communicating |
| 1013 |
continuous data in a loop (c.f. section \ref{sec:timing}). |
| 1014 |
|
| 1015 |
Buffering data in output and input ports gives more efficient |
| 1016 |
communication since data can be sent fewer times in larger packets. |
| 1017 |
By default MUSIC buffers some reasonable amount of data. In certain |
| 1018 |
situations it is necessary to be careful about memory usage. Using |
| 1019 |
the optional argument \lstinline|maxBuffered| the application can |
| 1020 |
give MUSIC a bound on how much data to buffer. MUSIC decides how much |
| 1021 |
data to buffer based on the lowest \lstinline|maxBuffered| parameter |
| 1022 |
given when mapping each of a set of connected ports and on latency |
| 1023 |
considerations when applications are connected in loops. A |
| 1024 |
\lstinline|maxBuffered| value of \(N\) ticks means: don't buffer more |
| 1025 |
data than is sufficient for communicating at every \(N\)\,th tick. |
| 1026 |
|
| 1027 |
When the optional argument \lstinline|interpolate| is |
| 1028 |
\lstinline|true|, MUSIC uses linear interpolation to determine the |
| 1029 |
values delivered on the receiver side. This is the default behavior. |
| 1030 |
By passing \lstinline|false| this interpolation can be switched off in |
| 1031 |
which case MUSIC selects the sample on the sender side which is |
| 1032 |
closest according to simulation time. |
| 1033 |
|
| 1034 |
\clearpage |
| 1035 |
\begin{code}{Mapping ports to internal data\label{code:mapping}} |
| 1036 |
{ |
| 1037 |
... |
| 1038 |
int size = comm.Get_size (); |
| 1039 |
int rank = comm.Get_rank (); |
| 1040 |
/* for clarity we assume that nElements |
| 1041 |
is a multiple of size */ |
| 1042 |
int nLocal = nElements / size; |
| 1043 |
double* stateVars = new double[nLocal]; |
| 1044 |
MUSIC::ContInputPort* out = |
| 1045 |
setup->publishContOutput ("out"); |
| 1046 |
MUSIC::ArrayData dMap (stateVars, MPI::DOUBLE, |
| 1047 |
rank * nLocal, nLocal); |
| 1048 |
out->map (&dMap); |
| 1049 |
... |
| 1050 |
} |
| 1051 |
\end{code} |
| 1052 |
|
| 1053 |
|
| 1054 |
\subsection{Mapping event ports} |
| 1055 |
\index{event ports} |
| 1056 |
|
| 1057 |
\index{map}\index{mapping event ports} |
| 1058 |
\begin{head}{map} |
| 1059 |
void EventOutputPort::map (IndexMap* indices, |
| 1060 |
Index::Type type, |
| 1061 |
int maxBuffered) |
| 1062 |
|
| 1063 |
void EventInputPort::map (IndexMap* indices, |
| 1064 |
EventHandler* handleEvent, |
| 1065 |
double accLatency, |
| 1066 |
int maxBuffered) |
| 1067 |
\end{head} |
| 1068 |
\begin{parameters} |
| 1069 |
\lstinline|indices| & the index map associated with the port \\ |
| 1070 |
\lstinline|type| & the indexing type used (local or global) \\ |
| 1071 |
\lstinline|handleEvent| & a user-defined event handler \\ |
| 1072 |
\lstinline|accLatency| & acceptable latency for incoming data (s) \\ |
| 1073 |
\lstinline|maxBuffered| & maximal amount of data buffered (ticks) \\ |
| 1074 |
\end{parameters} |
| 1075 |
|
| 1076 |
Since event ports don't access data the same way as cont ports, they |
| 1077 |
do not require a full \lstinline|DataMap|. Instead, an |
| 1078 |
\lstinline|IndexMap| is used to describe how indices in the |
| 1079 |
application should be mapped to the shared global indices common for |
| 1080 |
sender and receiver. The applications has the choice of using local |
| 1081 |
indices or bypassing the index transformation by directly using the |
| 1082 |
shared global indices when labelling events. This is controlled by |
| 1083 |
the \lstinline|type| parameter which can be set to |
| 1084 |
\lstinline|MUSIC::Index::LOCAL| or \lstinline|MUSIC::Index::GLOBAL|. |
| 1085 |
|
| 1086 |
Events are communicated to the application through an \emph{event |
| 1087 |
handler}\index{event handler}. The event handler is called by MUSIC |
| 1088 |
when the application calls \lstinline|tick|. It is called once for |
| 1089 |
every event delivered. |
| 1090 |
|
| 1091 |
Some spiking neural network models include axonal delays. The MUSIC |
| 1092 |
framework assumes that handling and delivery of delayed spikes occurs |
| 1093 |
on the receiver side. In such a case, the receiver may allow MUSIC to |
| 1094 |
deliver a spike event later than its time stamp according to local |
| 1095 |
time. The maximal acceptable latency is specified through the |
| 1096 |
\lstinline|accLatency|\index{accLatency} argument. |
| 1097 |
|
| 1098 |
The optional argument \lstinline|maxBuffered|\index{maxBuffered} |
| 1099 |
has a similar meaning as for cont ports above but the actual amount |
| 1100 |
of data buffered is, in this case, not deterministic since it is |
| 1101 |
dependent on spike rate. |
| 1102 |
|
| 1103 |
|
| 1104 |
\subsubsection{Sending events} |
| 1105 |
\index{sending events} |
| 1106 |
|
| 1107 |
The sender registers events for transmission by calling the method |
| 1108 |
\lstinline|insertEvent|. |
| 1109 |
|
| 1110 |
\index{insertEvent} |
| 1111 |
\begin{head}{insertEvent} |
| 1112 |
void EventOutputPort::insertEvent (double t, |
| 1113 |
LocalIndex id) |
| 1114 |
void EventOutputPort::insertEvent (double t, |
| 1115 |
GlobalIndex id) |
| 1116 |
\end{head} |
| 1117 |
\begin{parameters} |
| 1118 |
\lstinline|t| & trigger time of the event (s) \\ |
| 1119 |
\lstinline|id| & the local or global index of the event \\ |
| 1120 |
\end{parameters} |
| 1121 |
|
| 1122 |
MUSIC guarantees that this event will be delivered through a call to |
| 1123 |
the user-specified \lstinline|EventHandler| on the receiver side no |
| 1124 |
later that the acceptable latency relative to receiver local time. |
| 1125 |
The time \lstinline|t| must be between the simulation time of the last |
| 1126 |
tick and that of the next. |
| 1127 |
|
| 1128 |
The parameter \lstinline|id| should be converted from \lstinline|int| |
| 1129 |
to \lstinline|LocalIndex| or \lstinline|GlobalIndex| to indicate what |
| 1130 |
kind of indices are used in the application. |
| 1131 |
|
| 1132 |
|
| 1133 |
\subsubsection{Receiving events} |
| 1134 |
\index{receiving events} |
| 1135 |
|
| 1136 |
\index{EventHandler} |
| 1137 |
\begin{head}{EventHandlerLocalIndex,EventHandlerGlobalIndex,operator} |
| 1138 |
class EventHandlerLocalIndex { |
| 1139 |
public: |
| 1140 |
virtual void operator () (double t, |
| 1141 |
LocalIndex id) = 0; |
| 1142 |
}; |
| 1143 |
|
| 1144 |
class EventHandlerLocalIndex { |
| 1145 |
public: |
| 1146 |
virtual void operator () (double t, |
| 1147 |
GlobalIndex id) = 0; |
| 1148 |
}; |
| 1149 |
\end{head} |
| 1150 |
\begin{parameters} |
| 1151 |
\lstinline|t| & trigger time of the event (s) \\ |
| 1152 |
\lstinline|id| & local or global index if the event \\ |
| 1153 |
\end{parameters} |
| 1154 |
|
| 1155 |
Event handlers are called by event input ports to deliver events. The |
| 1156 |
application is supposed to customize either |
| 1157 |
\lstinline|LocalEventHandler| or \lstinline|GlobalEventHandler| by |
| 1158 |
subclassing one of them (depending on the indexing |
| 1159 |
scheme the application uses). |
| 1160 |
|
| 1161 |
|
| 1162 |
\clearpage |
| 1163 |
\subsection{Mapping message ports} |
| 1164 |
\index{message ports} |
| 1165 |
|
| 1166 |
Message ports behave similarly to event ports in that messages are |
| 1167 |
sent and delivered using similar mechanisms, but while events are |
| 1168 |
routed between processes based on event indices, messages are routed to all |
| 1169 |
processes on the receiver side which have provided a |
| 1170 |
\lstinline|MessageHandler| to \lstinline|map|. All arguments to |
| 1171 |
\lstinline|map| for message ports are optional. |
| 1172 |
|
| 1173 |
\index{map}\index{mapping message ports} |
| 1174 |
\begin{head}{map} |
| 1175 |
void MessageOutputPort::map (int maxBuffered) |
| 1176 |
|
| 1177 |
void MessageInputPort::map (MessageHandler* handler, |
| 1178 |
double accLatency, |
| 1179 |
int maxBuffered) |
| 1180 |
\end{head} |
| 1181 |
\begin{parameters} |
| 1182 |
\lstinline|handler| & a user-defined message handler \\ |
| 1183 |
\lstinline|accLatency| & acceptable latency for incoming data (s) \\ |
| 1184 |
\lstinline|maxBuffered| & maximal amount of data buffered (ticks) \\ |
| 1185 |
\end{parameters} |
| 1186 |
|
| 1187 |
|
| 1188 |
\subsubsection{Sending messages} |
| 1189 |
\index{sending messages} |
| 1190 |
|
| 1191 |
The sender registers a message for transmission by calling the method\\ |
| 1192 |
\lstinline|insertMessage|. |
| 1193 |
|
| 1194 |
\index{insertMessage} |
| 1195 |
\begin{head}{insertMessage} |
| 1196 |
void MessageOutputPort::insertMessage (double t, |
| 1197 |
void* msg, |
| 1198 |
size_t size) |
| 1199 |
\end{head} |
| 1200 |
\begin{parameters} |
| 1201 |
\lstinline|t| & time stamp (s) \\ |
| 1202 |
\lstinline|msg| & pointer to message \\ |
| 1203 |
\lstinline|size| & size of message in bytes \\ |
| 1204 |
\end{parameters} |
| 1205 |
|
| 1206 |
MUSIC will deliver this message through a call to the user-specified \\ |
| 1207 |
\lstinline|MessageHandler| on the receiver side no later than |
| 1208 |
\lstinline|accLatency| with regard to the time stamp. |
| 1209 |
|
| 1210 |
\begin{code}{Sending a message} |
| 1211 |
{ |
| 1212 |
... |
| 1213 |
char m[] = "string to send"; |
| 1214 |
port->insertMessage (runtime->time (), m, sizeof (m)); |
| 1215 |
... |
| 1216 |
} |
| 1217 |
\end{code} |
| 1218 |
|
| 1219 |
\pagebreak |
| 1220 |
\subsubsection{Receiving messages} |
| 1221 |
\index{receiving messages} |
| 1222 |
|
| 1223 |
\begin{head}{MessageHandler,operator} |
| 1224 |
class MessageHandler { |
| 1225 |
public: |
| 1226 |
virtual void operator () (double t, |
| 1227 |
void* msg, |
| 1228 |
size_t size) = 0; |
| 1229 |
}; |
| 1230 |
\end{head} |
| 1231 |
\begin{parameters} |
| 1232 |
\lstinline|t| & time stamp supplied by sender (s) \\ |
| 1233 |
\lstinline|msg| & pointer to message subclass instance \\ |
| 1234 |
\lstinline|size| & size of message instance in bytes \\ |
| 1235 |
\end{parameters} |
| 1236 |
|
| 1237 |
Message handlers are called by message input ports to deliver |
| 1238 |
messages. The application is supposed to customize |
| 1239 |
\lstinline|MessageHandler| by subclassing. It is recommended that |
| 1240 |
messages are text strings with the syntax of the interpreter language |
| 1241 |
of the receiving application, and that these text strings originate |
| 1242 |
from a user-specified configuration file read by the sending |
| 1243 |
application. |
| 1244 |
|
| 1245 |
The message given to the \lstinline|MessageHandler| is deallocated by |
| 1246 |
the MUSIC library. |
| 1247 |
|
| 1248 |
|
| 1249 |
\subsection{Index maps} |
| 1250 |
\index{index maps} |
| 1251 |
|
| 1252 |
An \lstinline|IndexMap| is a mapping from the local data element |
| 1253 |
indices to shared global indices. An index map instance thus holds |
| 1254 |
information of which subset of the shared global indices belong to the |
| 1255 |
local MPI process and of their local order. MUSIC implements two |
| 1256 |
subclasses of \lstinline|IndexMap|: \lstinline|PermutationIndex| and |
| 1257 |
\lstinline|LinearIndex|. The most general form is |
| 1258 |
\lstinline|PermutationIndex| which allows for an arbitrary mapping. |
| 1259 |
|
| 1260 |
\index{PermutationIndex} |
| 1261 |
\begin{head}{PermutationIndex} |
| 1262 |
PermutationIndex::PermutationIndex (int* indices, |
| 1263 |
int size) |
| 1264 |
\end{head} |
| 1265 |
\begin{parameters} |
| 1266 |
\lstinline|indices| & vector of shared indices \\ |
| 1267 |
\lstinline|size| & number of shared indices \\ |
| 1268 |
\end{parameters} |
| 1269 |
|
| 1270 |
\index{LinearIndex} |
| 1271 |
\begin{head}{LinearIndex} |
| 1272 |
LinearIndex::LinearIndex (int baseIndex, int size) |
| 1273 |
\end{head} |
| 1274 |
\begin{parameters} |
| 1275 |
\lstinline|baseIndex| & shared index corresponding to local index zero \\ |
| 1276 |
\lstinline|size| & number of contiguous indices in this process \\ |
| 1277 |
\end{parameters} |
| 1278 |
|
| 1279 |
When a cont output port is mapped it becomes associated with a set of |
| 1280 |
state variables (or other data) in the memory of the sender. When the |
| 1281 |
receiver calls \lstinline|runtime::tick|, an estimate of the values |
| 1282 |
of these variables are stored in a set of variables associated with an |
| 1283 |
input port on the receiver side. Similarly, an event output port is |
| 1284 |
mapped to a set of event id:s. |
| 1285 |
|
| 1286 |
While the number of variables or id:s on the receiver side is always |
| 1287 |
the same as on the sender side, the data can be distributed in |
| 1288 |
different ways between MPI processes on the sender side compared to |
| 1289 |
the receiver side. In fact, sender and receiver may consist of |
| 1290 |
different numbers of processes. |
| 1291 |
|
| 1292 |
Index maps are used in each MPI process to tell MUSIC how data is |
| 1293 |
distributed and ordered by enumerating the shared indices |
| 1294 |
represented by the process in local order. |
| 1295 |
|
| 1296 |
\subsection{Data maps} |
| 1297 |
\label{sec:datamap} |
| 1298 |
\index{data maps} |
| 1299 |
|
| 1300 |
A \lstinline|DataMap| encapsulates how a port accesses its data. |
| 1301 |
While an index map is a mapping between two kinds of indices, the data |
| 1302 |
map also contains information about where in memory data resides, how |
| 1303 |
it is structured, and, the type of the data elements. |
| 1304 |
\lstinline|ArrayData| is a subclass of \lstinline|DataMap| which |
| 1305 |
describes arrays of data elements. See example \ref{code:mapping}. |
| 1306 |
|
| 1307 |
\index{ArrayData} |
| 1308 |
\begin{head}{ArrayData} |
| 1309 |
ArrayData::ArrayData (void* buffer, MPI_Datatype type, |
| 1310 |
IndexMap* map) |
| 1311 |
\end{head} |
| 1312 |
\begin{parameters} |
| 1313 |
\lstinline|buffer| & data memory location \\ |
| 1314 |
\lstinline|type| & data type \\ |
| 1315 |
\lstinline|map| & index map \\ |
| 1316 |
\end{parameters} |
| 1317 |
|
| 1318 |
Since data organized in arrays is common, MUSIC provides a convenience |
| 1319 |
form of the array data map constructor which also creates a linear |
| 1320 |
index map: |
| 1321 |
|
| 1322 |
\begin{head}{ArrayData} |
| 1323 |
ArrayData::ArrayData (void* buffer, |
| 1324 |
MPI_Datatype type, |
| 1325 |
int baseIndex, |
| 1326 |
int size) |
| 1327 |
\end{head} |
| 1328 |
\begin{parameters} |
| 1329 |
\lstinline|buffer| & data memory location \\ |
| 1330 |
\lstinline|type| & data type \\ |
| 1331 |
\lstinline|baseIndex| & shared index of first local element \\ |
| 1332 |
\lstinline|size| & number of contiguous indices in this process \\ |
| 1333 |
\end{parameters} |
| 1334 |
|
| 1335 |
|
| 1336 |
\subsection{Configuration variables} |
| 1337 |
\index{configuration variables} |
| 1338 |
|
| 1339 |
The values of all variables defined in the configuration file can be |
| 1340 |
queried using the method \lstinline|config|. |
| 1341 |
|
| 1342 |
\index{config} |
| 1343 |
\begin{head}{config} |
| 1344 |
bool Setup::config (string name, string* result) |
| 1345 |
|
| 1346 |
bool Setup::config (string name, int* result) |
| 1347 |
|
| 1348 |
bool Setup::config (string name, double* result) |
| 1349 |
\end{head} |
| 1350 |
\begin{parameters} |
| 1351 |
\lstinline|name| & variable name \\ |
| 1352 |
\lstinline|result| & pointer to location where result should go \\ |
| 1353 |
\emph{return value} & true if value of correct type was found \\ |
| 1354 |
\end{parameters} |
| 1355 |
|
| 1356 |
Querying for a value of type \lstinline|int| or \lstinline|double| |
| 1357 |
expects a value of the correct type, if defined in the configuration |
| 1358 |
file. If the variable is defined, but its value can't be translated |
| 1359 |
into the correct type this causes an error condition. |
| 1360 |
|
| 1361 |
\begin{code}{Querying configuration variables} |
| 1362 |
/* Retrieving the parameter gKCa |
| 1363 |
from configuration file */ |
| 1364 |
double gKCa; |
| 1365 |
if (!config ("gKCa", &gKCa)) |
| 1366 |
gKCa = 29.5e-9; // default value |
| 1367 |
\end{code} |
| 1368 |
|
| 1369 |
\section{Runtime} |
| 1370 |
|
| 1371 |
\subsection{The runtime constructor} |
| 1372 |
|
| 1373 |
\begin{head}{runtime} |
| 1374 |
Runtime::Runtime (Setup* s, double h) |
| 1375 |
\end{head} |
| 1376 |
\begin{parameters} |
| 1377 |
\lstinline|s| & pointer to the Setup object \\ |
| 1378 |
\lstinline|h| & simulated time increment at each tick (s) \\ |
| 1379 |
\end{parameters} |
| 1380 |
|
| 1381 |
Creation of the runtime object marks the transition from the setup to |
| 1382 |
the runtime phase. The runtime object constructor destroys the Setup |
| 1383 |
object, effectively making it impossible to create new ports. All |
| 1384 |
data structures which have been associated with ports during mapping |
| 1385 |
must be initialized to some suitable start value at the time of the |
| 1386 |
call to the runtime constructor. These values are used during early |
| 1387 |
data transfers of data sampled at negative values of simulation time |
| 1388 |
and, thus, not available. |
| 1389 |
|
| 1390 |
\begin{code}{Runtime} |
| 1391 |
... |
| 1392 |
MUSIC::Runtime runtime = MUSIC::Runtime (setup, stepSize); |
| 1393 |
... |
| 1394 |
\end{code} |
| 1395 |
|
| 1396 |
\begin{rationale} |
| 1397 |
The step size is given as a real number (in seconds) since this |
| 1398 |
makes most sense from the applications point of view. Internally, |
| 1399 |
this number is converted to an integer (using the time micro step |
| 1400 |
time base). This is made to ensure that all processes use exactly |
| 1401 |
the same numbers even when the multi-simulation is running on mixed |
| 1402 |
architectures. Both sides of a connection must agree on when data |
| 1403 |
is transferred over the MPI connector to minimize the |
| 1404 |
need for handshaking during the runtime phase. |
| 1405 |
\end{rationale} |
| 1406 |
|
| 1407 |
\begin{rationale} |
| 1408 |
In order to create a deterministic schedule for buffering and data |
| 1409 |
transfer, we require that \lstinline|tick| increments simulated time |
| 1410 |
by a fixed amount each time. We realize that some applications may |
| 1411 |
use a variable time step\index{variable time step} for their |
| 1412 |
numerical integrations, which may then make it harder to execute |
| 1413 |
these tick calls at the right time. However, allowing variable tick |
| 1414 |
steps would have made it impossible to use a pre-computed |
| 1415 |
deterministic schedule and enforced repeated handshaking throughout |
| 1416 |
the runtime phase, resulting in a substantial performance |
| 1417 |
degradation. |
| 1418 |
|
| 1419 |
Note that the tick step does not need to be equal to the internally |
| 1420 |
used integration step\index{integration step}. We believe that most |
| 1421 |
large scale parallel simulators already have some means for fixed |
| 1422 |
interval operations, e.g. to handle logging to files or graphics, |
| 1423 |
which may be utilized also for the tick calls. |
| 1424 |
\end{rationale} |
| 1425 |
|
| 1426 |
|
| 1427 |
\subsection{The tick} |
| 1428 |
\index{tick} |
| 1429 |
|
| 1430 |
\begin{head}{tick} |
| 1431 |
void Runtime::tick () |
| 1432 |
\end{head} |
| 1433 |
\begin{parameters} |
| 1434 |
\end{parameters} |
| 1435 |
|
| 1436 |
The tick function must be called at regular intervals in simulation |
| 1437 |
time. The application chooses the interval as a parameter to the |
| 1438 |
\lstinline|Runtime| constructor, normally based on the time step used |
| 1439 |
in the application. The \lstinline|tick| function is typically called |
| 1440 |
in the main simulation loop of each application. Different |
| 1441 |
applications may use different tick intervals and MUSIC will ensure |
| 1442 |
that time is incremented consistently throughout the multi-simulation. |
| 1443 |
|
| 1444 |
Before \lstinline|tick| is called, the application must ensure that |
| 1445 |
all data mapped for output is valid. At the \lstinline|tick| call, |
| 1446 |
time is incremented and data mapped for input is updated to reflect |
| 1447 |
the new time. Further, installed event handlers will be called |
| 1448 |
\emph{during} the \lstinline|tick| call to deliver events. |
| 1449 |
|
| 1450 |
The MUSIC library may, or may not, exchange data with other |
| 1451 |
applications at the tick call. The application must ensure that |
| 1452 |
exported data values are valid when \lstinline|tick| is called. It |
| 1453 |
must also expect that imported values may change and that event and |
| 1454 |
message handlers are called. |
| 1455 |
|
| 1456 |
\begin{rationale} |
| 1457 |
The idea behind the \lstinline|tick| call is to hide the complexity |
| 1458 |
of data buffering and MPI transfer from the application. For |
| 1459 |
efficient data transfer, MUSIC will try to buffer data both at the |
| 1460 |
sending and receiving port in order to send data in large chunks. |
| 1461 |
Internally, MUSIC will use a pre-computed schedule to keep track of |
| 1462 |
at what ticks the actual data transfer should take place and when |
| 1463 |
data should instead be buffered for later transfer. |
| 1464 |
\end{rationale} |
| 1465 |
|
| 1466 |
|
| 1467 |
\subsection{Simulation time} |
| 1468 |
\index{simulation time} |
| 1469 |
|
| 1470 |
The method \lstinline|time| returns local time in seconds. |
| 1471 |
|
| 1472 |
\index{time} |
| 1473 |
\begin{head}{time} |
| 1474 |
double Runtime::time () |
| 1475 |
\end{head} |
| 1476 |
\begin{parameters} |
| 1477 |
\emph{return value} & local time (s) \\ |
| 1478 |
\end{parameters} |
| 1479 |
|
| 1480 |
\lstinline|time| returns the local time. Time starts at 0\,s and is |
| 1481 |
incremented at every \lstinline|tick| call. While it is possible, and |
| 1482 |
recommended, to let MUSIC keep track of time for the application, this |
| 1483 |
is not required. |
| 1484 |
|
| 1485 |
\begin{rationale} |
| 1486 |
To schedule data transfers, MUSIC needs to keep track of the |
| 1487 |
simulation time of all applications via its internal integer |
| 1488 |
representation. If the application independently manages its own |
| 1489 |
clock, typically by incrementing a floating point variable, there is |
| 1490 |
a risk for drift between the two time representations. The |
| 1491 |
\lstinline|time| function makes it possible for the application to |
| 1492 |
keep its clock in perfect synchronization with time in the other |
| 1493 |
applications. |
| 1494 |
\end{rationale} |
| 1495 |
|
| 1496 |
|
| 1497 |
\subsection{Finalization} |
| 1498 |
|
| 1499 |
An application supporting MUSIC should replace its call to |
| 1500 |
\lstinline|MPI::Finalize| with a call to \lstinline|MUSIC::finalize|. |
| 1501 |
|
| 1502 |
\index{finalize} |
| 1503 |
\begin{head}{finalize} |
| 1504 |
void Runtime::finalize () |
| 1505 |
\end{head} |
| 1506 |
\begin{parameters} |
| 1507 |
\end{parameters} |
| 1508 |
|
| 1509 |
\lstinline|MUSIC::finalize| makes sure all internally buffered data is |
| 1510 |
sent and finally calls \lstinline|MPI::Finalize|. Note that this |
| 1511 |
means that communication via MPI will not be possible afterwards. |
| 1512 |
|
| 1513 |
|
| 1514 |
\chapter{Adapting Existing Applications} |
| 1515 |
|
| 1516 |
In this chapter we will highlight the steps necessary to adapt an |
| 1517 |
existing neural simulator to MUSIC. We will assume that the simulator |
| 1518 |
is already using MPI to simulate large networks of interconnected |
| 1519 |
neurons. |
| 1520 |
|
| 1521 |
The two main tasks that need to be handled are: firstly, to create and |
| 1522 |
map ports for data to be imported and exported, and, secondly, to |
| 1523 |
ensure that the \lstinline|tick| function is called at regular |
| 1524 |
intervals. |
| 1525 |
|
| 1526 |
|
| 1527 |
\section{Creating and Mapping Ports} |
| 1528 |
|
| 1529 |
The application needs to inform MUSIC about what data to import and |
| 1530 |
export, and where this data resides. A simulator will typically use |
| 1531 |
some sort of script files where the user specifies the model and other |
| 1532 |
aspects of the simulation. If possible, it is desirable to extend the |
| 1533 |
scripting language of the simulator so that the user can specify what |
| 1534 |
model variables to communicate, and what names to use for ports. |
| 1535 |
|
| 1536 |
Assuming that we have introduced such constructs into the scripting |
| 1537 |
language, we must decide on a suitable point in the initialization |
| 1538 |
process where ports should be created and mapped. Since continuous |
| 1539 |
data is read from, or written to, application memory space, the |
| 1540 |
program must have allocated its runtime data structures in order to |
| 1541 |
perform the mapping. |
| 1542 |
|
| 1543 |
Communication of spikes will use event ports. Function calls are used |
| 1544 |
to send and receive individual spike events. Sending of spikes is |
| 1545 |
relatively straightforward, since the only thing needed is to add a |
| 1546 |
call to the method \lstinline|insertEvent| at the location where |
| 1547 |
spikes are normally detected in the program. Receiving spikes |
| 1548 |
requires more administration, since the spikes can be received earlier |
| 1549 |
than when they should reach their destination compartment. It is |
| 1550 |
therefore necessary to save incoming spikes in some sort of sorted |
| 1551 |
buffer (typically a priority queue). |
| 1552 |
|
| 1553 |
\begin{figure} |
| 1554 |
\begin{center} |
| 1555 |
\begin{minipage}[t]{0.45\textwidth} |
| 1556 |
\includegraphics[width=\textwidth]{figures/remapping} |
| 1557 |
\caption[Processing of incoming data]{\label{fig:remapping1} |
| 1558 |
The sender application presents the data to the output port in |
| 1559 |
the same order as it is stored internally. The receiving |
| 1560 |
application will see the transferred data in the same order |
| 1561 |
and will explicitly have to implement a proper reordering to |
| 1562 |
implement a typical synaptic projection. |
| 1563 |
} |
| 1564 |
\end{minipage} |
| 1565 |
\hfill |
| 1566 |
\begin{minipage}[t]{0.45\textwidth} |
| 1567 |
\includegraphics[width=\textwidth]{figures/remapping2} |
| 1568 |
\caption[Remapping of data within MUSIC]{\label{fig:remapping2} |
| 1569 |
If there is a one-to-one correspondence between sending and |
| 1570 |
receiving neurons, the receiving application can specify an |
| 1571 |
appropriate index map to instruct MUSIC to send the data |
| 1572 |
directly to the right destination. |
| 1573 |
} |
| 1574 |
\end{minipage} |
| 1575 |
\end{center} |
| 1576 |
\end{figure} |
| 1577 |
|
| 1578 |
In addition, MUSIC will always present the spikes as they appear in |
| 1579 |
the sending group of neurons. In most situations, the receiving |
| 1580 |
application will want to implement a remapping to the target |
| 1581 |
compartments, as illustrated in figure~\ref{fig:remapping1}. One spike |
| 1582 |
may thus end up at multiple postsynaptic compartments, spread out over |
| 1583 |
the processors of the receiving application. |
| 1584 |
|
| 1585 |
In some situations it may be desirable for the receiving application |
| 1586 |
to avoid this remapping. The application can then utilize the different |
| 1587 |
forms of mappings available in MUSIC to create a general permutation |
| 1588 |
so that MUSIC will send spikes directly to the processor where they |
| 1589 |
should be handled. This situation is illustrated in |
| 1590 |
figure~\ref{fig:remapping2} |
| 1591 |
|
| 1592 |
|
| 1593 |
\section{Advancing Simulation Time} |
| 1594 |
|
| 1595 |
The application must call the \lstinline|tick| function repeatedly |
| 1596 |
throughout the simulation. The application will have to ensure that |
| 1597 |
these calls are made at regular intervals, as specified to the runtime |
| 1598 |
constructor. Note that this refers to \emph{simulated time}; there is |
| 1599 |
no need to consider how much computation time (``wall clock time'') is |
| 1600 |
used between tick calls. |
| 1601 |
|
| 1602 |
If the application makes use of variable time steps internally, it may |
| 1603 |
be necessary to use some sort of checkpoints at fixed intervals where |
| 1604 |
tick can be called. It is not necessary to call tick at every |
| 1605 |
integration time step, but the calls should not be too infrequent. |
| 1606 |
|
| 1607 |
The tick calls are the only times during runtime when MUSIC will use |
| 1608 |
MPI. MUSIC will then use its own communicators, not to interfere with |
| 1609 |
the MPI operations of the application. Still, we recommend that the |
| 1610 |
application does not intersperse the tick calls with ongoing MPI |
| 1611 |
operations. |
| 1612 |
|
| 1613 |
When sending continuous values the application must ensure that data |
| 1614 |
arrays mapped for output are filled with values relevant for the time |
| 1615 |
of the \emph{next} tick. After the \lstinline|tick| call, data arrays |
| 1616 |
mapped for input will be filled with imported data belonging to the |
| 1617 |
same point in time. Note that \lstinline|Runtime::time| is updated |
| 1618 |
\emph{during} the \lstinline|tick| call to reflect the current |
| 1619 |
simulation time. |
| 1620 |
|
| 1621 |
|
| 1622 |
\section{Initialization and Finalization} |
| 1623 |
|
| 1624 |
\subsection{Initiate MUSIC}\index{initiate MUSIC} |
| 1625 |
|
| 1626 |
The idea here is to replace the call to \lstinline|MPI::Init| with a |
| 1627 |
call to the \lstinline|MUSIC:Setup| constructor. The Setup |
| 1628 |
constructor calls \lstinline|MPI::Init| for the application. |
| 1629 |
|
| 1630 |
The application will have to replace all uses of the global |
| 1631 |
communicator \lstinline|MPI::COMM_WORLD| with the communicator |
| 1632 |
supplied by MUSIC. The global communicator will be global over all |
| 1633 |
applications and it is necessary to limit the MPI operations to the |
| 1634 |
group of MPI processes belonging to the application. |
| 1635 |
|
| 1636 |
There should be no need to link an application differently when it is |
| 1637 |
used together with other applications in a MUSIC setting compared to |
| 1638 |
when it is used in a stand-alone setting. In order to support |
| 1639 |
``standard'' operation for the application, |
| 1640 |
\lstinline|Setup::communicator ()|, therefore, will return |
| 1641 |
\lstinline|MPI::COMM_WORLD| if the job is started directly with |
| 1642 |
\lstinline|mpirun| instead of with the MUSIC launcher. |
| 1643 |
|
| 1644 |
|
| 1645 |
|
| 1646 |
\subsection{Initiate the runtime phase} |
| 1647 |
|
| 1648 |
Creating the runtime object will implicitly call the \lstinline|Setup| |
| 1649 |
object destructor to ensure that the application will no longer be |
| 1650 |
able to change the communication pattern. At this stage, MUSIC can |
| 1651 |
build the plan for communication between different processes. |
| 1652 |
|
| 1653 |
\subsection{Finalize MUSIC}\index{finalize}\index{terminate} |
| 1654 |
|
| 1655 |
The application should also replace its call to |
| 1656 |
\lstinline|MPI::Finalize|, normally used to shut down communication, |
| 1657 |
by a call to \lstinline|MUSIC::finalize|. This will internally call |
| 1658 |
\lstinline|MPI::Finalize| after having flushed all pending data from |
| 1659 |
internal buffers. |
| 1660 |
|
| 1661 |
\bibliographystyle{unsrtnat} |
| 1662 |
\bibliography{music-rfc} |
| 1663 |
|
| 1664 |
\appendix |
| 1665 |
|
| 1666 |
\chapter{A Complete Example} |
| 1667 |
|
| 1668 |
This chapter shows a minimal but still complete example. It consists |
| 1669 |
of two applications, \texttt{waveproducer} and \texttt{waveconsumer}, |
| 1670 |
and a configuration file used to launch and connect them. |
| 1671 |
|
| 1672 |
|
| 1673 |
\section{Configuration File} |
| 1674 |
\label{sec:conffile} |
| 1675 |
|
| 1676 |
The configuration file starts the waveproducer application on four |
| 1677 |
processors and waveconsumer on three. |
| 1678 |
|
| 1679 |
\lstinputlisting[language=Clean,frame=single]{wavetest.music} |
| 1680 |
|
| 1681 |
|
| 1682 |
\section{Data Generating Application} |
| 1683 |
|
| 1684 |
\lstinputlisting{waveproducer.cc} |
| 1685 |
|
| 1686 |
|
| 1687 |
\section{Data Consuming Application} |
| 1688 |
|
| 1689 |
\lstinputlisting{waveconsumer.cc} |
| 1690 |
|
| 1691 |
|
| 1692 |
\chapter{C Interface} |
| 1693 |
\label{app:cint} |
| 1694 |
|
| 1695 |
Most elements of the C interface can be constructed from their C++ |
| 1696 |
counterparts using a few translation rules: |
| 1697 |
|
| 1698 |
\begin{enumerate} |
| 1699 |
\item All identifiers have the prefix \lstinline|MUSIC_|. |
| 1700 |
\item Constructors translate to \lstinline|create| followed by the |
| 1701 |
class name. |
| 1702 |
\item Destructors translate to \lstinline|destroy| followed by the |
| 1703 |
class name. |
| 1704 |
\item Methods translate to class name followed by method name. |
| 1705 |
\item References translate to pointers. |
| 1706 |
\item Strings translate to \lstinline|char *|. |
| 1707 |
\item Optional C++ arguments are required in C. |
| 1708 |
\end{enumerate} |
| 1709 |
|
| 1710 |
Entries which do not strictly follow these rules are preceded with an |
| 1711 |
extra comment in the following listing. |
| 1712 |
|
| 1713 |
\lstinputlisting{music-c-int.h} |
| 1714 |
|
| 1715 |
\chapter{Specification File Syntax} |
| 1716 |
\label{sec:specsyntax} |
| 1717 |
|
| 1718 |
\newcommand{\nt}[1]{$<$#1$>$} |
| 1719 |
|
| 1720 |
\begin{tabular}{lcl} |
| 1721 |
\nt{simulation spec} & ::= & \{ \nt{application block} \} \\ |
| 1722 |
\nt{application block} & ::= & \nt{newline} '[' \nt{application id} ']' \{ \nt{declaration} |
| 1723 |
\} \\ |
| 1724 |
\nt{application id} & ::= & \nt{symbol} \\ |
| 1725 |
\nt{declaration} & ::= & \nt{variable def} $|$ \nt{connection} \\ |
| 1726 |
\nt{variable def} & ::= & \nt{variable} '=' \nt{value} \\ |
| 1727 |
\nt{variable} & ::= & \nt{symbol} \\ |
| 1728 |
\nt{value} & ::= & \nt{integer} $|$ \nt{float} $|$ \nt{string} \\ |
| 1729 |
\nt{connection} & ::= & \nt{port id} \nt{direction} \nt{port id} [ \nt{width} ] \\ |
| 1730 |
\nt{port id} & ::= & \nt{application id} '.' \nt{port} $|$ |
| 1731 |
\nt{port} \\ |
| 1732 |
\nt{port} & ::= & \nt{symbol} \\ |
| 1733 |
\nt{direction} & ::= & $->$ $|$ $<-$ \\ |
| 1734 |
\nt{width} & ::= & '[' \nt{integer} ']' \\ |
| 1735 |
\end{tabular} |
| 1736 |
|
| 1737 |
\printindex |
| 1738 |
|
| 1739 |
\end{document} |
| 1740 |
|
| 1741 |
|
| 1742 |
%%% Local Variables: |
| 1743 |
%%% mode: latex |
| 1744 |
%%% TeX-master: t |
| 1745 |
%%% eval: (flyspell-mode 1) |
| 1746 |
%%% eval: (ispell-change-dictionary "american") |
| 1747 |
%%% eval: (flyspell-buffer) |
| 1748 |
%%% End: |