DAPPLE Homework

  1. Look at the quicksort animation again. Is this parallel sorting algorithm efficient? In what way is the parallelism in this algorithm limited?

  2. Copy the DAPPLE Package from the Parallel Computing part of the CS15 PUBLIC folder. That folder includes a C++ project to which you can add a source file for running under DAPPLE. Be sure to read the README file there.

  3. Write a DAPPLE program to simulate Conway's game of Life. In the game of Life, there are N rows of M cells that can each hold an organism. Initially, some of the cells are occupied and some are empty. In each generation some organisms will die and some new organisms will be born, according to the following rules:
    1. If an organism has 0 or 1 neighbors, it dies of loneliness.
    2. If an organism has 2 or 3 neighbors, it survives.
    3. If an organism has 4 or more neighbors, it dies of overcrowding.
    4. If an empty cell has exactly 3 neighbors, a new organism is born.
    There are imaginary empty cells surrounding the N by M game board.

    Your program should read in the values of N and M, and then the initial state of an N by M game of life. It should then loop through generations, printing out the state of the game and the number of live organisms after each generation, then pausing for the user to press return (so the generations don't go flying by so fast you can't see them!). Here is a sample output for a 10 by 20 game with a simple initial state:

    Initial state:
    ....................
    ....................
    ....................
    ....................
    ....OOOOOOOOO.......
    ....................
    ....................
    ....................
    ....................
    ....................
    
    Generation 1, 21 alive
    ....................
    ....................
    ....................
    .....OOOOOOO........
    .....OOOOOOO........
    .....OOOOOOO........
    ....................
    ....................
    ....................
    ....................
    
    press return:
    Generation 2, 16 alive
    ....................
    ....................
    ......OOOOO.........
    .....O.....O........
    ....O.......O.......
    .....O.....O........
    ......OOOOO.........
    ....................
    ....................
    ....................
    
    press return:
    Generation 3, 34 alive
    ....................
    .......OOO..........
    ......OOOOO.........
    .....OOOOOOO........
    ....OO.....OO.......
    .....OOOOOOO........
    ......OOOOO.........
    .......OOO..........
    ....................
    ....................
    
    press return:
    Generation 4, 16 alive
    ........O...........
    ......O...O.........
    .....O.....O........
    ....O.......O.......
    ....O.......O.......
    ....O.......O.......
    .....O.....O........
    ......O...O.........
    ........O...........
    ....................
    
    press return:
    
    and so forth.

    Hint: Represent the cells as a charMatrix, with 'O' representing an organism and '.' representing an empty cell. This is easy to input and print. When it comes time to count neighbors, create an intMatrix whose elements are 1 in cells that are occupied, and 0 in cells that are empty. Use that to compute the number of neighbors for each cell, and then convert back to the charMatrix form for printing.

    Hint: Edit an initial state using an editor with a fixed-width font, and then paste it into the console window every time you run your program. It's easier than re-typing the initial state every time.


Back to DAPPLE.