Parallel Processing and Super-Scalar Operation 401
Another similar example may be cited for a chess playing program, where parallel processing is
acceptable to calculate the material advantage and positional advantage of a given board position. In this
case, the board position, indicating the relative position of all pieces of both sides, would be the input
for both calculations, which may be carried out independently by two processors.
The task of sub-dividing a program suitable for parallel execution is not only within the domain of
the software developer, as illustrated through examples above, but also may be implemented by the
compiler, at suitable places. For example, the I/O sub-section of software related with printing of some
intermediate results may be entrusted to another processor, while the main processor proceeds with the
remaining instruction steps. However, the compiler, in such cases, must be careful to handle the shared
data, otherwise, it may lead to unwanted errors, which we are about to discuss now.
13.4.2 Shared Variables and Critical Sections
When different processors share the same set of data or variables, utmost care is necessary so that the
integrity of the data is maintained throughout. As an example case, we may consider two concurrent bank
account transactions belonging to the same account number. Let us assume that the initial balance in the
account is Rs.10,000. At the same time (but through two different terminals located at different places),
an amount of Rs. 5,000 is deposited by one person and an amount of Rs. 8,000 is withdrawn by another
person. If two processors are allowed to access the same variable (the user account in this case), then the
nal balance after both transactions might be Rs. 2,000 or Rs. 15,000. This anomaly might be arising out
of the following steps, executed by two different processors. Both processors are equipped with the same
subroutine of reading the last balance from the given account number (from a shared data base), updating
it (add or subtract depending upon the type of transaction) and writing back the nal balance to its original
location (same shared data base). If both processors are reading the available balance ( rst step of the
subroutine) one after another, both of them would read it as 10,000. Now the rst processor would change
it to 15,000 and write it back. The second processor would change it to 2,000 and write it back. Depend-
ing upon which processor writes back last, the balance would show either of these two incorrect gures.
To eliminate this problem, the portion of software that handles a common or shared data base is
designated as critical section . Entry to this critical section is restricted to only one software at a time.
Figure 13.10 Elements for load calculation of a multi-storied structure
M13_GHOS1557_01_SE_C13.indd 401M13_GHOS1557_01_SE_C13.indd 401 4/29/11 5:26 PM4/29/11 5:26 PM