THE ALGORITHM
12.4 THE ALGORITHM
This section provides a formal description of the parallel alpha-beta algorithm as implemented on an EREW SM MIMD computer. We begin by defining three aspects of the implementation.
12.4.1 Procedures and Processes
An MIMD algorithm is a collection of procedures and processes. Syntactically, a process is the same as a procedure. Furthermore, both a procedure and a process can call other procedures and create other processes. Where the two differ is in the semantics. In the parallel alpha-beta
we shall distinguish between processes and procedures in the following way:
(i) When a procedure is called, control is transferred from the calling context to the procedure.
(ii) When a process is invoked, it is initiated to run asynchronously, and the invoking context continues execution.
12.4.2 Semaphores
Semaphores are used by the algorithm for process communication and syn-
chronization. Here a semaphore consists of an integer value and a queue of processes.
324 Traversing Combinatorial Spaces Chap. 12
When a semaphore is declared, it is initialized to have a value and a null queue. There are two operations allowed on semaphores, denoted by
and
1. Operation examines the integer value: (i) If it is greater than zero, it decrements it by 1, and the process doing the
operation proceeds. (ii) If the value is zero, the process doing the operation suspends itself and
enters the queue.
2. Operation V examines the queue: (i) If it is nonempty, it lets the first waiting process continue. (ii) If no processes are waiting, the integer value is incremented by 1. Both
and V are indivisible operations.
12.4.3 Score Tables
In the parallel alpha-beta algorithm, many parts of the tree are traversed simulta- neously. Therefore, a single global score table cannot be used as in the sequential case. Instead, an individual score table is assigned to each node when a process is generated to search the
rooted at that node. This table is initialized to the values in the score table of the node's parent. We are now ready to state the parallel alpha-beta algorithm. The algorithm is given in what follows as procedure MIMD ALPHA BETA together with the procedures and processes it uses. Some of the procedures are entirely game dependent and therefore are not fully specified.
procedure MIMD ALPHA BETA (Board, Depth, Principal Continuation) {This procedure uses three variables
Board: a description of the board configuration from which a move is to be made, Depth: the depth to which the tree is to be traversed,
Root Table: the root's score table; and three semaphores RootHandled, and
Step 1: (1.1) Read Board and Depth (1.2) Initialize RootTable (1.3)
Step 2: (Create a process to begin the search) HANDLE (Board, true, true, false, 0, RootTable, RootHandled, LeftOffspringDone).
Step 3: {Has the root been assigned a final score?) (RootHandled).
12.4 The Algorithm 325 process HANDLE (Board, MyTurn, Left,
Ply, ParentTable, Done, LeftSiblingDone)
{This process uses the following variables MyTurn: true if ply is even, false otherwise, Left: true if the process is a left process, false otherwise, ParentLeft: true if the parent process is a left process, false otherwise, Ply: the ply number, ParentTable: the parent's score table,
the score table created automatically when this process was invoked, and initialized to the parent's core table; and three semaphores Done, LeftSiblingDone, and
Step 1: {If this is a terminal node, score it; otherwise, generate its offspring} (1.1) (1.2) if Ply = Depth
then SCORE (Board, MyTable) else GENERATE (Board)
end if.
Step 2: {Update parent's score table} UPDATE (ParentTable).
Step 3: if Left and then V (LeftSiblingDone)
end if.
Step 4: procedure SCORE (Board, Table)
{This procedure evaluates the given board configuration (Board) associated with a terminal node and puts the resulting static score in the given score table (Table). The evaluation function is game dependent and is left unspecified.)
procedure GENERATE (Board) {This procedure searches a
rooted at a nonterminal node. It calls procedure GENERATE MOVES to produce a list of moves from the current position. The moves are stored in an array Moves whose ith location is denoted Moves [i]. The number of moves is kept in the variable NumberMoves.
and are semaphores. Procedure APPLY is then used to apply each of the generated moves to the given Board thereby producing board configurations for its offspring. Variable
is used to store each new configuration. The variable Cutoff is assigned the value true if a cutoff is to occur, false otherwise.}
Step 1: GENERATE MOVES (Board, Moves, NumberMoves). Step 2: {If the root of the
to be searched is a left node, then process HANDLE is invoked once for each offspring. The processes thus created run concurrently and procedure GENERATE waits until they all terminate}
326 Traversing Combinatorial Spaces Chap. 12
then (2.1) for = 1 to NurnberMoves do (i) APPLY (Board,
NewBoard)
HANDLE (NewBoard, not MyTurn, 1 = 1, Left, Ply + 1, MyTable,
OffspringDone,
end for
(2.2) for = 1 to NurnberMoves do (OffspringDone)
end for
{If the root of the to be searched is a right node, then its offspring are searched in sequence by calling process HANDLE for one of them, waiting for it to complete, and performing a cutoff check before handling the next offspring)
else (2.3) Cutoff false
(2.4) (2.5) while
NurnberMoves and not Cutoff) do (i) APPLY (Board,
NewBoard)
HANDLE (NewBoard, not
1 = 1, Left, Ply + 1,
OffspringDone,
(OffspringDone) (iv) {Has the
(iii)
sibling received a final score?}
(LeftSiblingDone)
(v) V (vi) if (Ply is odd) and (offspring's score parent's score)
then Cutoff true
else if (Ply is even) and (offspring's score parent's score)
then Cutoff
end while end if.
procedure UPDATE (ParentTable) {This procedure waits until the parent's score table is free. Then, if the score calculated for the
current node improves on the parent's score, it is copied into the parent's score table. The semaphore ParentTableFree is used. This semaphore is created and initialized simulta- neously with variable ParentTable.)
Step 1: (ParentTableFree). Step
2: Copy value if applicable. Step 3:
V (ParentTableFree). procedure GENERATE MOVES (Board, Moves, NurnberMoves)
(This procedure produces all the legal moves from a position given by variable Board, stores them in array Moves, and sets variable NumberMoves to their number. The procedure is game dependent and is therefore left unspecified.}
12.5 Analysis and Examples
procedure APPLY (Board, Moves, NewBoard) {This procedure changes the current position given by variable Board by making
the move received in variable Moves. The result is a new board configuration The procedure is game dependent and is therefore left unspecified.)