324
72
Parallel Processing and Parallel Algorithms
3. Those processor P, for which x = Ey. juqo, Update index=(k ~ 1)(n/N)+j
In general, the parallel algorithm can be represented as follows to address the
speedup over the sequential version.
Procedure Parallel-Divide-and-Conquer(Input, Output)
Divide(Input, Input, Input, ...mput,)
for i= 1 tom do in parallel,
Parallel-Divide-and-Conquer(Input,, Output,
Input,, Output,
Inpat,, Output,)
endfor
Combine(Output,, Output, ...Output,, Output)
End Parallel-Divide-and-Conquer
Depth-First Search
Sequential graph algorithms often employ some form of graph traversal, which
is equivalent to tracing the edges of a spanning tree of the graph, Perhaps, from
the sequential complexity point of view, the most successful and commonly
used form of graph traversal is the Depth-First Search (DFS). The importance of
the depth-first search is that many efficient sequential algorithms on graphs use
DFS as the basic procedure. The graph G is represented by its adjacency list and
for each vertex v there is a list of all vertices adjacent to v. Depth-first search is
the process of searching a graph in such a way that the search moves forward
until it reaches a vertex whose neighbors have all been examined. At this point it
backtracks a minimum distance and continues in a new direction. In other
words, in a depth-first search, if v is the vertex being searched from (starting
vertex), (v.w) is the edge being examined and w is unvisited, w will be the next
vertex searched from (the new starting point). The DFS is called recursively.
However, if vis the starting vertex and (v,w) is the edge being examined and
w is already visited, v remains the vertex being searched from, and another ver-
tex adjacent to v which has not been visited, is chosen as the vertex to be ex-
amined. This indicates that in the DFS strategy the vertices are examined in or-
der of decreasing depth in the tree.
Although in a depth-first search it is not required the children of a vertex be
visited in any particular order, we follow the convention that the children of a
vertex are visited from left to right. The depth-first search algorithm assigns a
number to each vertex v which specifies the order in which the vertex is visited
during the graph traversal. This number is called the depth-first index of the
vertex. Formally, the DFS is described as follows.Chapter 7. Parallel Search Algorithms 325
Depth-First-Search (DFS)
Input: A directed connected graph G and a specified starting vertex v.
Output: The depth-first indices of the vertices of G starting with v = 1.
ie 7.2 shows a depth-first search of a tree performed in this manner such
that the vertices are numbered in the order they are visited, with the starting
vertex being A. The sequential DFS can be represented in terms of the following
recursive procedure. The algorithm is called a depth-first search because it initi-
ates as many recursive calls as possible before it ever returns from a call. The
recursion stops only when exploration of the graph is blocked and can go no
further. At this point the recursion stops so alternate possibilities at higher levels,
ccan be explored.
ABCDEFGH
BAA A AE AE
c FGF F
D HOH
E
G
@ ®
© @
Figure 7.2. A graph and its comesponding depth-first tree. (a) Graph G. (b) Adjacency of
graph G. (c) Depth-fist tre obtained from depth-first traversal. (4) Depth-first index tree
obtained from depth-first traversal.
Procedure Depth-First(A)
begin
mark every vertex “unvisited”
veestart vertex
‘1 vis the vertex being searched from */
Call Depth-First-Search(v)326
Parallel Processing and Parallel Algorithms
Procedure Depth-First-Search(v)
begin
mark v “visited”
for each vertex w adjacent to v do
if w is marked “unvisited”
then Call Depth-First-Search(w)
endfor
End Depth-First-Search
end
End Depth-First
We analyze the time complexity of DFS in a graph with n vertices and m
edges, with respect to two basic operations, visiting a vertex and examining a
vertex, to determine if it has been visited. The worst-case complexity for both
operations occurs when the graph is connected. If the graph is connected, we
can verify that every vertex is visited exactly once with a total of n vertex visits.
Each edge in the graph addresses exactly two vertex examinations, thus yielding
the number of vertices to be examined as 2m. Therefore, the total number of op-
erations by DFS in the worst-case is n + 2m, resulting in a complexity of O(n +
m).
In general, parallel processing is a major approach to enhance the efficiency
of search algorithms. We focus entirely on bounded parallelism, which corre-
sponds to the more realistic assumption that a given computing system has only
a fixed number of processors functioning in parallel. The computational eff
ciency of the algorithms depends on the data structure and the search strategies.
Alton and Eckstein [Alton 77} proposed a parallel algorithm for a depth-first
search. Reghbati and Corneil [Reghbati 78] conjectured that a depth-first search
‘was inherently sequential. It is generally assumed that the use of DFS is incom-
patible with efforts to process the search space in parallel, meaning it seems that
the problem of finding a depth-first search tree is hardly parallelizable. Hence,
‘many fast parallel computations in graph theory avoid depth-first search com-
putations. For the moment, consider the instructions of the depth-first search
procedure given earlier. The crucial issue in an effort to parallelize the algorithm.
are the lines
for each vertex w adjacent to v do
if w is marked “unvisited"
then ..
‘which mean to find the next unvisited vertex on the adjacency list of v. Alterna-
tively, instead of an adjacency list representation of the adjacent vertices to each
vertex, we consider an “adjacency list matrix” such that every row represents all
the adjacent vertices to each vertex. With this assumption, different processors
can simultaneously examine successive vertices to identify whether they are
visited or unvisited. We also define an “unvisited adjacency list” U(v) whichChapter 7. Parallel Search Algorithms 327
lists all vertices that are adjacent to v and are still labeled “unvisited.” As soon
as a vertex w is “visited,” it will be removed from the lists U(v) for all v adja-
‘cent to w. Of course, the problem of finding an “unvisited” vertex adjacent to v
now becomes trivial, by taking the first element of U(v) if U(v) is not empty.
Such an approach of deleting elements from “unvisited” adjacent lists is com-
patible with DFS, since the flow of control of DFS-based algorithms, the order
in which the various recursive calls are performed, depends only on the vertices
which remain “unvisited.” In this approach the need for communication between
processors is eliminated.
Two lists, ARC_LIST and FROND_LIST, as the output of the DFS are de-
fined such that the final FROND_LIST(v) isa list of vertices w such that there is
1 frond from v to w, and the final ARC_LIST is a list of vertices w such that
there is an arc from v to w. Figure 7.3 illustrates the representation of a graph in
the adjacency list matrix, adjacency list, associated end-marker vector, and un-
visited adjacency matrix forms.
The Adjacency List visit i
1): 2434 45 ml UC): null 32 3 4> null
‘L(2): 1 null U(2): null > 1 null
3): 1 null U@3): null 1 — null
‘1L(4): 1 null ‘U(4): null 31 > null
‘The Adjacency List Matrix The er
132331 133
231-300 271
331300 31
4-100 451
Figure 7.3. Representation of graph regarding different forms.
A parallel depth-first search algorithm is now defined follows.328
Parallel Processing and Parallel Algorithms
Input: Adjacency list matrix, ALM(L:n,I:n—1), the associated end-marker
vector EM(|:n), the initial unvisited adjacency list, U(), 1 Si