You are on page 1of 5
45 The circuit satisfiability program presented in this chapter has the circuit to be tested “hard wired” into function check_circuit. Explain how the circuit satisfiability program could be modified to check the satisfiability of a circuit input from a data file. a. How would you represent a circuit with and, or, and not gates in a plain text file that could be created and viewed with a text editor? b. How would your program parse this file? c. Describe the data structure you would use to represent the atosthenes program presented in the text ments described in Section 5.9. performance with that of the 5.8 Modify the parallel Sieve of Br to incorporate all three improve d Benchmark your program, comparing i original parallel sieve program. 6.11 Recall the parallel Sieve of Eratosthenes program developed in Chapter 5. Lester suggests that the execution time of the program can be improved by replacing the broadcast step with a pipeline of sends and receives [71]. In other words, instead of process 0 broadcasting the next prime to all the other processes, it sends the next prime to process 1, which receives the value and sends it to process 2, and so on. For each prime found, the maximum number of communication steps per process is reduced from flog p} to 2. a. Implement a new parallel version of the Sieve of Eratosthenes program, replacing the broadcast step with a receive/send step. (Process 0 does not perform a receive, and the process of highest rank does not perform a send.) b. Use the analytical model developed in Chapter 5 to predict the execution time improvement this program will achieve. ¢. Benchmark the original program and the new program on a parallel computer, 6.12 Write two parallel programs that input a topographical map and output the locations that are in the shade given certain predetermined positions of the sun, For both programs the format of the input and output files are the same. The input file is anv x m matrix representing n? evenly spaced points on a square piece of land. ‘The values in the matrix are integers ranging from 0 to about 100, Each value represents the altitude of the land at the corresponding point. The output file is ann x n matrix of Os and 1s, The output value is 0 if the land at that point is in the sunlight and 1 if the land at the point is in the shade. a. Your program should assume that the sun is shinting from the west. A location is in the shade if there is a hill to its west high enough to block the sun, Here is how to compute which locations are in the shade: First, the locations in the leftmost column are by definition in the sunlight. For each remaining location (i, j), it is in the shade if there is another location (i, j — k) whose altitude is at least 4k greater than the altitude at (i, 5), For example, here is a sample input matrix (the directional letters, are to help you orient the map and are not in the file): 0 0 5 3 a: 0 5 7 il 10 8 4 wis 9 16 7 8 36 22 15 4 ll 7 2 to 2 10 9 7 2 0 0 5 7 4 0 s The correct output matrix would be: 0 0 oOo oOo o 0 0 0 0 0 oO 1 oO 1 0 1 1 1 0 1 1 0 1 1 o 1 06 0 oO 1 0 0 0 0 9 12 b. Your program should assume that the sun is shining from the northwest. A location is in the shade if there is a hill to its northwest high enough to block the sun. Here is how to compute which locations are in the shade. First, the locations in the top row and the leftmost column are by definition in the sunlight. For each remaining location (i, j), itis in the shade if there is another location (i — k, j — k) whose altitude is at least 4k greater than the altitude at (, j). For example, given the same input matrix in the previous example, here is the correct output matrix: bHocoo 9.10 A perfect number is a positive integer whose value is equal to the sum of all its positive factors, excluding itself. The first two perfect numbers are 6 and 28 6=142+3 WHl+2+447414 The Greek mathematician Euclid (c. 300 BCE) showed that if 2" — 1 is prime, then (2 — 1)2*~! is a perfect number. For example, 2? — 1 = 3is prime, so (2? — 1)2! = 6 isa perfect number. Write a parallel program to find the first eight perfect numbers. 10.8 Implement a parallel program solving the neutron transport problem described in Section 10.5.1. Let C. = 0.3 and C, = 0.7. Determine the probability of absorption, reflection, and transmission for H = 1,2, 3, ..., 10. Base your results on 10 million tests (neutrons) for each value of H. 10.10 Write a Parallel program implementing the Ising model described in ion 10.5.3. The objective is to find the energy lev cl of system after 1,000,000 iterations. Let J = 1. BO, and kT 1 ee the System a “cold stat” by initializing every site oto “up” in state x Valuate 37, Jo, for every pair of sites that are horizontally or vertically adjacent. Repeat the experiment 1,000 times, rogram solving the parking garage problem eeassume § = 80, A= 3,and M = 240, ccupied by cars, and the Determine the average number of stalls occupit : probability ofa car being tumed away because the garage is full, as 1 — oo, that is, in the steady state. 10.12. Implement a parallel posed in Section 10.5.5. A 10.13 Implement a parallel program solving the traffic circle problem posed in Section 10.5.6. Use the program to answer these two questions: a, For each of the four traffic circle entrances, what is the steady state probabitity that a car will have to wait before entering the circle? b. For each of the four traffic circle entrances, what is the average Iength of the queue of vehicles waiting to enter the traffic circle, in the steady state? 16.17 Figure 16.23 illustrates a puzzle, The puzzle has 21 holes in it. Initially every hole is filled with a peg, except for the center hole (shown in black). Pegs are moved and removed by doing checkers-style hopping. You are allowed to move a peg in a straight line from its hole over an occupied hole to an empty hole on the other side and remove the peg that was just hopped. You may hop pegs in a horizontal, vertical, or diagonal direction. The object of the puzzle is to remove pegs until only one peg remains, and that peg is in the center hole. A sequence of 19 moves (hops) is necessary to reduce the original 20 pegs to a single peg. Write a parallel program to find a solution to the puzzle. Benchmark the execution time of your program for various values of p. Plot the speedup achieved by your program as a function of p. OOO O0000 OO08@00 CCO000 CoOo°Oo Figure 16.23 A peg puzzle. 16.18 The 15-puzzle, invented by Sam Loyd, is a larger version of the 8-puzzle presented in this chapter. Fifteen tiles, numbered 1 through 15, and a hole occupy a 4 x 4 grid. Write a parallel program that takes as input a scrambled version of the 15-puzzle and finds the shortest sequence of moves needed to put the tiles back in order. Benchmark your program on at least five puzzles, each of which requires at Jeast six moves to solve. Plot the speedup achieved by your program on each puzzle, as a function of p.

You might also like