CS 336: Project #2

A Sequential Implementation of Fish Schooling Simulations

On NSCC, create a proj02 directory and cURL the code tarball to it. Then expand the tarball:
  1. curl -O http://cs.colby.edu/courses/S11/cs336/projects/proj02/fish_seq2.tar
  2. tar -xf fish_seq2.tar
The code is organized into the following files:

As you can see, there are many top-level programs. They begin with more IO and less computation (good for debugging) and end with more computation and less IO. We also introduce code to time the computations. Our goal as we parallelize this code in the future will be to speed it up dramatically.

  1. One Simulation at a Time, with I/O

    First, we write the code with the view of making sure it is correct. So, we write code that will simulate one ocean of fish. We supply three functions for initializing the ocean -- one that is random (which is what we will ultimately use, and others that are deterministic). And we write the output to files, so that it can later be visualized.

    1. Write fishStep (in fish_support.c). You should use the following algorithm
        For each "goal" fish,
      • Check to see if there are any fish in its zone of repulsion.
        • If there are, then set the new direction to be away from them according to equation (1) in the paper.
        • If there aren't, then check to see if there are any fish in its zone of attraction/orientation (don't worry about the blind spot - that's an extension). Set the new direction according to equation (2) in the paper.
        • Adjust the new direction by calling correctDirection. Don't worry about fish that turn too far (that's an extension). Also, don't worry about stochastic effects.
      • Set the new position according to the new direction, using equation (3) in the paper.

      Here are some constants that will help you:

        const float repulsionRadius = 1.0;
        const float attractionRadius = 7.0;
        const float weight_attraction = 1.0;
        const float weight_alignment = r;
        const float speed = 1.0;
        const float tau = 0.2;
      
    2. Test it by running sim_slow (I supply sim_slow.c and runSimulationWithIO and correctDirection). You can visualize the output of sim_slow using disp_sim. I have supplied a compiled version of it, calling it taylor_disp_sim. Feel free to use it. Remember to start small (say 2 fish for just 2 steps) and look carefully at the output. There is a function in fishIO called dumpFrame which will print the fish positions/directions to the screen. Make liberal use of it.
    3. Here are some outputs from my version of the code (without any extensions) I ran sim_slow twice.
      ./sim_slow 100 2 2 1 reference1.fsh 1
      ./sim_slow 100 2 100 1 reference2.fsh 1
      
      You can download them here: reference1.fsh, reference2.fsh or cURL them:
      curl -O http://cs.colby.edu/courses/S11/cs336/projects/proj02/reference1.fsh
      curl -O http://cs.colby.edu/courses/S11/cs336/projects/proj02/reference2.fsh
      
      You can display the simulation like this:
      ./taylor_disp_sim reference1.fsh 1
      
  2. One Simulation at a Time, with Statistics

    Now that we know how to run single simulations, let's compute the polarity and elongation values. We continue to allow for certain initial configurations, so that we can debug the statistics.

    1. Write computePolarization (in fish_support.c)
    2. Write runSimulationWithStatistics (in fish_support.c)
    3. Test it by running sim_fast (I supply sim_fast.c and my_timing.c)
  3. Lots of Simulations for one orientation/alignment ratio

    Ultimately, our goal is to run many simulations for each value of r (orientation/alignment ratio) starting from random initial conditions. First, let's write code that runs multiple simulations for one value of r.

    1. Write runRandomSimulationWithStatistics (in fish_support.c)
    2. Write runSimulations (in fish_support.c)
  4. Lots of Simulations for multiple orientation/alignment ratios

    1. Run sim_stats_nr to get a taste of how much time it can take to run sequential code. We need to run at least 32 simulations for each r value on schools of at least 100 fish. How long does it take to run 32 simulations of 100-fish schools for three values of r?

Extensions

Debugging

You can use my executable (this is the version without the extension) to generate additional reference files. Then, if you want to you can dump the data to the screen as numbers. This is more precise than watching the movie.

Here's what you need:

Make dump_sim. Use your version of sim_slow (without extensions) to generate .fsh files with small numbers of fish. Use mine to do the same. Then dump the .fsh file and compare the output.

Handin

To hand in your project, you will gather all of the necessary files into a proj02 directory in your turnin directory:

  1. Create a file named README.txt for your project write-up. This week, I want you to talk about (a) what was the most challenging aspect of the project, (b) which extensions you did, and (c) how long it takes to run sim_stats_1r for different values of r (ranging from 0.25 to 16) for different sizes of fish schools (ranging from 10 to 100), and for different numbers of simulations (you will be limited by the fish school size for this one). For part (c), it is up to you to decide which simulations to run. Make your decision based on how long it takes to run the individual simulations. Don't spend more than an hour on this part (writing and running together).
  2. You should hand in all code necessary to run your solutions. Place all necessary .h, .c, and Makefile files in the proj02 directory. Stephanie will probably want to compile and run the code. It should be possible to do so without looking for any more files.

Email Stephanie to let her know your project is ready for grading.