
USF COP 6611
Problem Set #5.
Due: March 12 before class.
1. Certain algorithms that work very well when all of the data fit in memory do not work
so well when the virtual memory exceeds the available physical memory, due to the
amount of time that may be spent on page replacement. The following program
multiplies two matrices, where each matrix is stored as a two dimensional array. The
array is stored in row-order, meaning that consecutive elements in the same row of
the array will be stored in consecutive locations in memory.
multiply(A,B,C)
{
int A[SIZE][SIZE]. B[SIZE][SIZE], C[SIZE][SIZE];
int i,j,k,temp;
for all i /* this done in parallel */
for (j=0; j<SIZE; j++) {
temp = 0;
for (k=0; k<SIZE; k++)
temp += a[i][k] * b[k][j];
c[i][j] = temp;
}
}
Suppose the above program was written for a shared-memory multiprocessor. Each
processor has a number assigned to it to use for the variable i. Therefore, each processor
is responsible for computing a row of C. Furthermore, assume that they all execute in
parallel at the same rate. We will be interested in the performance of this program in light
of very large arrays, which will not all fit in memory at the same time. For this problem,
assume an optimal page replacement algorithm, where 1000 pages are available for the
arrays (you can ignore i,j,k and the source program). Each page may hold up to 1000
elements of any array.
Assume there are 100 processors, assigned numbers from 0 to 99. Each will be
responsible for doing a set of rows in the multiplication. For example, when multiplying
1000x1000 matrices, Processor 0 will find the first 10 rows, Processor 1 the next 10, and
so on. The code each processor runs will be as follows:
int A[SIZE][SIZE], B[SIZE][SIZE], C[SIZE][SIZE];
multiply(A,B,C){
int i,j,k,temp;
int mult = SIZE / 100;
for (i=mult*ProcN ; i<mult * (ProcN + 1); i++)
for (j=0; j<SIZE; j++){
temp = 0;
for (k=0; k<SIZE; k++)
temp += a[i][k] * b[k][j];