~ubuntu-branches/ubuntu/raring/yorick/raring

« back to all changes in this revision

Viewing changes to mpy/mpy.1

  • Committer: Bazaar Package Importer
  • Author(s): Thibaut Paumard
  • Date: 2010-05-06 17:47:18 UTC
  • mfrom: (1.2.1 upstream) (6.1.1 sid)
  • Revision ID: james.westby@ubuntu.com-20100506174718-j26zbusz02k8hf6t
Tags: 2.1.06+dfsg-2
Deactivate check suite on MIPS due to bug #580524.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
.TH MPY 1 "2010 MARCH 21"
 
2
.UC 4
 
3
.SH NAME
 
4
mpy \- Message Passing Yorick
 
5
.SH SYNOPSIS
 
6
mpirun \-np mp_size
 
7
.B mpy
 
8
[ \-j
 
9
.I pfile1.i
 
10
[ \-j
 
11
.I pfile2.i
 
12
[ ... ]]]
 
13
[ \-i
 
14
.I file1.i
 
15
[ \-i
 
16
.I file2.i
 
17
[ ... ]]]
 
18
.br
 
19
mpirun \-np mp_size
 
20
.B mpy
 
21
\-batch
 
22
.I file.i
 
23
.br
 
24
.SH DESCRIPTION
 
25
.I Yorick
 
26
is an interpreted language like Basic or Lisp, but far faster. See 
 
27
.I yorick
 
28
(1) to learn more about it.
 
29
.br
 
30
.I Mpy
 
31
is a parallel version of
 
32
.I Yorick
 
33
based on the Message Passing Interface (MPI). The exact syntax for launching a parallel job depends on your MPI environment. It may be necessary to launch a special daemon before calling
 
34
.I mirun
 
35
or an equivalent command.
 
36
.SS Explanations
 
37
 
 
38
The mpy package interfaces yorick to the MPI parallel programming
 
39
library.  MPI stands for Message Passing Interface; the idea is to
 
40
connect multiple instances of yorick that communicate among themselves
 
41
via messages.  Mpy can either perform simple, highly parallel tasks as
 
42
pure interpreted programs, or it can start and steer arbitrarily
 
43
complex compiled packages which are free to use the compiled MPI API.
 
44
The interpreted API is not intended to be an MPI wrapper; instead it
 
45
is stripped to the bare minimum.
 
46
 
 
47
This is version 2 of mpy (released in 2010); it is incompatible with
 
48
version 1 of mpy (released in the mid 1990s), because version 1 had
 
49
numerous design flaws making it very difficult to write programs free
 
50
of race conditions, and impossible to scale to millions of processors.
 
51
However, you can run most version 1 mpy programs under version 2 by
 
52
doing mp_include,"mpy1.i" before you mp_include any file defining an
 
53
mpy1 parallel task (that is before any file containg a call to
 
54
mp_task.)
 
55
.SS Usage notes
 
56
The MPI environment is not really specified by the standard; existing
 
57
environments are very crude, and strongly favor non-interactive batch
 
58
jobs.  The number of processes is fixed before MPI begins; each
 
59
process has a rank, a number from 0 to one less than the number of
 
60
processes.  You use the rank as an address to send messages, and the
 
61
process receiving the message can probe to see which ranks have sent
 
62
messages to it, and of course receive those messages.
 
63
 
 
64
A major problem in writing a message passing program is handling
 
65
events or messages arriving in an unplanned order.  MPI guarantees
 
66
only that a sequence of messages send by rank A to rank B will arrive
 
67
in the order sent.  There is no guarantee about the order of arrival
 
68
of those messages relative to messages sent to B from a third rank C.
 
69
In particular, suppose A sends a message to B, then A sends a message
 
70
to C (or even exchanges several messages with C) which results in C
 
71
sending a message to B.  The message from C may arrive at B before the
 
72
message from A.  An MPI program which does not allow for this
 
73
possibility has a bug called a "race condition".  Race conditions may
 
74
be extremely subtle, especially when the number of processes is large.
 
75
 
 
76
The basic mpy interpreted interface consists of two variables:
 
77
  mp_size   = number of proccesses
 
78
  mp_rank   = rank of this process
 
79
and four functions:
 
80
  mp_send, to, msg;         // send msg to rank "to"
 
81
  msg = mp_recv(from);      // receive msg from rank "from"
 
82
  ranks = mp_probe(block);  // query senders of pending messages
 
83
  mp_exec, string;          // parse and execute string on every rank
 
84
 
 
85
You call mp_exec on rank 0 to start a parallel task.  When the main
 
86
program thus created finishes, all ranks other than rank 0 return to
 
87
an idle loop, waiting for the next mp_exec.  Rank 0 picks up the next
 
88
input line from stdin (that is, waits for input at its prompt in an
 
89
interactive session), or terminates all processes if no more input is
 
90
available in a batch session.
 
91
 
 
92
The mpy package modifies how yorick handles the #include parser
 
93
directive, and the include and require functions.  Namely, if a
 
94
parallel task is running (that is, a function started by mp_exec),
 
95
these all become collective operations.  That is, rank 0 reads the
 
96
entire file contents, and sends the contents to the other processes as
 
97
an MPI message (like mp_exec of the file contents).  Every process
 
98
other than rank 0 is only running during parallel tasks; outside a
 
99
parallel task when only rank 0 is running (and all other ranks are
 
100
waiting for the next mp_exec), the #include directive and the include
 
101
and require functions return to their usual serial operation,
 
102
affecting only rank 0.
 
103
 
 
104
When mpy starts, it is in parallel mode, so that all the files yorick
 
105
includes when it starts (the files in Y_SITE/i0) are included as
 
106
collective operations.  Without this feature, every yorick process
 
107
would attempt to open and read the startup include files, overloading
 
108
the file system before mpy ever gets started.  Passing the contents of
 
109
these files as MPI messages is the only way to ensure there is enough
 
110
bandwidth for every process to read the contents of a single file.
 
111
 
 
112
The last file included at startup is either the file specified in the
 
113
\-batch option, or the custom.i file.  To avoid problems with code in
 
114
custom.i which may not be safe for parallel execution, mpy does not
 
115
look for custom.i, but for custommp.i instead.  The instructions in
 
116
the \-batch file or in custommp.i are executed in serial mode on rank 0
 
117
only.  Similarly, mpy overrides the usual process_argv function, so
 
118
that \-i and other command line options are processed only on rank 0 in
 
119
serial mode.  The intent in all these cases is to make the \-batch or
 
120
custommp.i or \-i include files execute only on rank 0, as if you had
 
121
typed them there interactively.  You are free to call mp_exec from any
 
122
of these files to start parallel tasks, but the file itself is serial.
 
123
 
 
124
An additional command line option is added to the usual set:
 
125
  mpy \-j somefile.i
 
126
.br
 
127
includes somefile.i in parallel mode on all ranks (again, \-i other.i
 
128
includes other.i only on rank 0 in serial mode).  If there are
 
129
multiple \-j options, the parallel includes happen in command line
 
130
order.  If \-j and \-i options are mixed, however, all \-j includes
 
131
happen before any \-i includes.
 
132
 
 
133
As a side effect of the complexity of include functions in mpy, the
 
134
autoload feature is disabled; if your code actually triggers an
 
135
include by calling an autoloaded function, mpy will halt with an
 
136
error.  You must explicitly load any functions necessary for a
 
137
parallel tasks using require function calls themselves inside a
 
138
parallel task.
 
139
 
 
140
The mp_send function can send any numeric yorick array (types char,
 
141
short, int, long, float, double, or complex), or a scalar string
 
142
value.  The process of sending the message via MPI preserves only the
 
143
number of elements, so mp_recv produces only a scalar value or a 1D
 
144
array of values, no matter what dimensionality was passed to mp_send.
 
145
 
 
146
The mp_recv function requires you to specify the sender of the message
 
147
you mean to receive.  It blocks until a message actually arrives from
 
148
that sender, queuing up any messages from other senders that may
 
149
arrive beforehand.  The queued messages will be retrieved it the order
 
150
received when you call mp_recv for the matching sender.  The queuing
 
151
feature makes it dramatically easier to avoid the simplest types of
 
152
race condition when you are write interpreted parallel programs.
 
153
 
 
154
The mp_probe function returns the list of all the senders of queued
 
155
messages (or nil if the queue is empty).  Call mp_probe(0) to return
 
156
immediately, even if the queue is empty.  Call mp_probe(1) to block if
 
157
the queue is empty, returning only when at least one message is
 
158
available for mp_recv.  Call mp_probe(2) to block until a new message
 
159
arrives, even if some messages are currently available.
 
160
 
 
161
The mp_exec function uses a logarithmic fanout - rank 0 sends to F
 
162
processes, each of which sends to F more, and so on, until all
 
163
processes have the message.  Once a process completes all its send
 
164
operations, it parses and executes the contents of the message.  The
 
165
fanout algorithm reaches N processes in log to the base F of N steps.
 
166
The F processes rank 0 sends to are ranks 1, 2, 3, ..., F.  In
 
167
general, the process with rank r sends to ranks r*F+1, r*F+2, ...,
 
168
r*F+F (when these are less than N-1 for N processes).  This set is
 
169
called the "staff" of rank r.  Ranks with r>0 receive the message from
 
170
rank (r\-1)/F, which is called the "boss" of r.  The mp_exec call
 
171
interoperates with the mp_recv queue; in other words, messages from
 
172
a rank other than the boss during an mp_exec fanout will be queued for
 
173
later retrieval by mp_recv.  (Without this feature, any parallel task
 
174
which used a message pattern other than logarithmic fanout would be
 
175
susceptible to race conditions.)
 
176
 
 
177
The logarithmic fanout and its inward equivalent are so useful that
 
178
mpy provides a couple of higher level functions that use the same
 
179
fanout pattern as mp_exec:
 
180
  mp_handout, msg;
 
181
  total = mp_handin(value);
 
182
.br
 
183
To use mp_handout, rank 0 computes a msg, then all ranks call
 
184
mp_handout, which sends msg (an output on all ranks other than 0)
 
185
everywhere by the same fanout as mp_exec.  To use mp_handin, every
 
186
process computes value, then calls mp_handin, which returns the sum of
 
187
their own value and all their staff, so that on rank 0 mp_handin
 
188
returns the sum of the values from every process.
 
189
 
 
190
You can call mp_handin as a function with no arguments to act as a
 
191
synchronization; when rank 0 continues after such a call, you know
 
192
that every other rank has reached that point.  All parallel tasks
 
193
(anything started with mp_exec) must finish with a call to mp_handin,
 
194
or an equivalent guarantee that all processes have returned to an idle
 
195
state when the task finishes on rank 0.
 
196
 
 
197
You can retrieve or change the fanout parameter F using the mp_nfan
 
198
function.  The default value is 16, which should be reasonable even
 
199
for very large numbers of processes.
 
200
 
 
201
One special parallel task is called mp_connect, which you can use to
 
202
feed interpreted command lines to any single non-0 rank, while all
 
203
other ranks sit idle.  Rank 0 sits in a loop reading the keyboard and
 
204
sending the lines to the "connected" rank, which executes them, and
 
205
sends an acknowledgment back to rank 0.  You run the mp_disconnect
 
206
function to complete the parallel task and drop back to rank 0.
 
207
 
 
208
Finally, a note about error recovery.  In the event of an error during
 
209
a parallel task, mpy attempts to gracefully exit the mp_exec, so that
 
210
when rank 0 returns, all other ranks are known to be idle, ready for
 
211
the next mp_exec.  This procedure will hang forever if any one of the
 
212
processes is in an infinite loop, or otherwise in a state where it
 
213
will never call mp_send, mp_recv, or mp_probe, because MPI provides no
 
214
means to send a signal that interrupts all processes.  (This is one of
 
215
the ways in which the MPI environment is "crude".)  The rank 0 process
 
216
is left with the rank of the first process that reported a fault, plus
 
217
a count of the number of processes that faulted for a reason other
 
218
than being sent a message that another rank had faulted.  The first
 
219
faulting process can enter dbug mode via mp_connect; use mp_disconnect
 
220
or dbexit to drop back to serial mode on rank 0.
 
221
.SS Options
 
222
.TP 20
 
223
.RI \-j \0file.i
 
224
includes the Yorick source file
 
225
.I file.i
 
226
as mpy starts in parallel mode on all ranks.  This is equivalent to
 
227
the mp_include function after mpy has started.
 
228
.TP
 
229
.RI \-i \0file.i
 
230
includes the Yorick source file
 
231
.I file.i
 
232
as mpy starts, in serial mode.  This is equivalent to the #include
 
233
directive after mpy has started.
 
234
.TP
 
235
.RI \-batch \0file.i
 
236
includes the Yorick source file
 
237
.I file.i
 
238
as mpy starts, in serial mode.  Your customization file custommp.i, if any, is
 
239
.I not
 
240
read,
 
241
and mpy is placed in batch mode.  Use the help command on the batch
 
242
function (help, batch) to find out more about batch mode.  In batch
 
243
mode, all errors are fatal; normally, mpy will halt execution and
 
244
wait for more input after an error.
 
245
.PP
 
246
.SH AUTHOR
 
247
.PP
 
248
David H. Munro, Lawrence Livermore National Laboratory
 
249
.PP
 
250
.SH FILES
 
251
.PP
 
252
Mpy uses the same files as yorick, except that custom.i is replaced by
 
253
custommp.i (located in /etc/yorick/mpy/ on Debian based systems) and
 
254
the Y_SITE/i\-start/ directory is ignored.
 
255
.SH SEE ALSO
 
256
yorick(1)