Parallel Algorithm Pseudocode Conventions for Mesh Models – Continued
Read/Write Statements
We will assume the existence of two parallel I/O statements,
read
for input and
write
for output.
Suppose, for example, that we have a list of
n
values stored
sequentially in the input device.
These
n
values might be read into a one-
dimensional mesh M
P
by the following statement:
for
P
i
, 1
≤
i
≤
n
do in parallel
read
(
P
i
:
L
)
end in parallel
This
in parallel
statement simultaneously reads the
i
th value in the external
input device into the variable
P
i
:
L
in the local memory of processor
P
i
,
i
∈
{1, …,
n}.
Typically, when using
read
or
write
statements in a procedure or function,
a
dcl
statement is included which covers all variables participating in I/O, together
with
range
descriptions when interconnection models are considered (the range
variable is not required for PRAM models due to the shared nature of the
memory).
Also, the terms
external input
and
external output
will be utilized in
the opening syntax.
Algorithms for the Mesh Model
As we did for the PRAM model, we now will develop a complete algorithm for
searching on the two-dimensional mesh model.
Recall from our earlier discussions of this algorithm, that similar to the PRAM
algorithm for the same problem, the 2-d mesh algorithm for searching consisted
of three distinct phases, the first of which was broadcasting phase in which the
value of the search element
x
was broadcast as a distributed element to all the
participating processors.
Using the pseudocode that we have developed for the
interconnection network models, this algorithm would have the pseudocode
shown in Figure 1.
Parallel Algorithms IV -
1
Parallel Algorithms
IV
(18)
procedure
broadcast2Dmesh (P
1,1
:x, n)
model:
Two-dimensional mesh M
q,q
with
p = n = q
2
processors
input:
P
1,1
:x (element to be broadcast)
output:
P
1,1
:x (element is broadcast to each processor in M
q,q
)
for
i := 1
to
q-1
do
P
1, i+1
:x
⇐
P
1, i
: x
{propagate
x
to right across first row}
endfor
for
i := 1
to
q-1
do
for
P
i,
j
, 1
≤
j
≤
q
do in parallel
P
i+1, j
:x
⇐
P
i, j
: x
{propagate
x
down row by row}
end in parallel
endfor
end
broadcast2Dmesh