CSC 429 Mid Fall 14
CSC 429 Mid Fall 14
CSC 429 Mid Fall 14
ASSUMPTIONS: Throughout the exam, if not specially specified, you may assume that n is a
multiple of p, and p is a power of two. You may assume that it takes one operation to compute
a+b and one operation to compute a b (product of a and b), given a and b.
1. In the ________ PRAM, processors must write the same value into the shared memory
cell.
A. Arbitrary
B. Common
C. Priority
D. Comibing
A. EREW
B. CREW
C. ERCW
D. CRCW
A. Star-Connected Network
B. Crossbar Networks
C. 3d-mesh Network
D. Hypercube Network
4. In the completely connected network with N nodes, there are totally ________
linkes(edges).
A. N
B. 2N
C. N(N-1)/2
D. N2
Page 1
CSC429 Fall 2014 Name:
A. 6
B. 8
C. 12
D. 16
6. Consider the problem of sorting n input numbers. Bubble Sort runs in approximately n2
steps and Heap Sort(which is one of the best sorting algorithm) runs in approximately
nlog n steps. With n processing nodes, Odd-even Transposition Sort algorithm runs in
approximately n steps. What is the speedup of Odd-even Transposition Sort algorithm?
__________
A. n
B. log n
C. n/log n
D. none of the above
Page 2
CSC429 Fall 2014 Name:
Problem 4 (8 points)
What is the output of the following MPI program(You may assume any execution order of
processes)?
#include <mpi.h>
int main(int argc, char **argv) {
int nprocs, mypid, myval, i, total;
MPI_Init(&argc,&argv);
MPI_Comm_size(MPI_COMM_WORLD,&nprocs);
MPI_Comm_rank(MPI_COMM_WORLD,&mypid );
printf("Hello world from process %d of total %d\n",mypid,nprocs);
if (pid==0)
myval=15;
MPI_Bcast(&myvalue,1,MPI_INT,0,MPI_COMM_WORLD);
myval=myval+mypid;
printf("Process %d: myvalue is %d. \n", mypid, myval);
MPI_Finalize();
}
Page 3
CSC429 Fall 2014 Name:
A programmer needs to write a program such that (1) each process will compute and print out
the product of its own part of numbers (2) all processes except process 0 send their products to process 0
and print this message (3) after process 0 receive the products from other processes, process 0 will print
out the confirmation that it received the value, multiply all the products including its own product, and
print out the product of all the numbers, that is, the value of 1*2*3*… *1000(that is, ). Note he is
Page 4
CSC429 Fall 2014 Name:
1. (15 points) This user has finished the partial program named parallelProduct.c as below.
Please help him complete the program.
#define N 1000
main (int argc, char **argv)
{
int nprocs, mypid, i, myproduct=1;
int total;
MPI_Status status;
printf( "Product from process %d of total %d is : %d. \n", mypid, nprocs, myproduct);
if (mypid!=0)
{
Page 5
CSC429 Fall 2014 Name:
2. (2 points) The programmer opened the script file, which is shown as follows. Please help
him revise the script file correctly.
#!/bin/bash
#PBS -N job4
#PBS -q production
#PBS -l select=8:ncpus=1
#PBS -l place=free
#PBS -V
cd $PBS_O_WORKDIR
Page 6
CSC429 Fall 2014 Name:
(a) Assume p>=n, give or cite an efficient EREW PRAM algorithm that finds the
parallel sum x. (10 points)
(b) Based on (a), what is the parallel running time, speedup, efficiency, and cost of
your proposed algorithm? Is this algorithm cost-optimal? (7 points)
(c) Assume p<n, give an EREW PRAM algorithm that finds the parallel sum x in at
most n/p + lg p steps. (10 points)
(d) Based on (c), what is the speedup and efficiency of your algorithm? (3 points)
(e) Based on (d), for which values of p (in terms of n) is the speedup of the proposed
algorithm θ(p)? And for which values of p (in terms of n) is the algorithm cost-
optimal? (4 points)
Page 7
CSC429 Fall 2014 Name:
Note: You final grade for this midterm is min{100, (your grade on problem 1-6) + (your grade
on extra credit)}
Page 8