n

advertisement
SI 486L Lab 7: Fire Simulation1
This lab is due on Tuesday, 23-Mar-2015 at 11:59 p.m. All the files should be zipped or tar'd into a
single file and e-mailed (the subject line should contain the phrase “lab 7”) as an attachment to the
instructor. One of the files should be a makefile with a default target that builds an MPI executable
called “fire”. Be sure to include a write-up of results!
Introduction
Suppose the US Forest Service has asked for your help in
simulating a forest fire at Yellowstone National Park. They
want to understand the likelihood and results of such an event.
The park is roughly 9000 km2, which we'll round up to 10,000
km2, or 100 km x 100 km.
“Tree density in primary forests varies from 50,000-100,000
trees per square km” (www.greennature.ca/?q=eco+facts)
Your objective is to run a grid-based simulation large enough to cover 100 x 100 km at a density
described above. That might be something like: 22500 x 22500 (for roughly 50,000 trees/km2). Each
cell in the grid represents a place that might contain a tree (or not). Not every cell will have a tree; that
will be determined by an initial density – populating the forest randomly, based on the density
probability. Each cell that will contain a tree should have a value of 3, 2, or 1, chosen at random. Any
empty cell (no tree) should have a value of 0. These values will correspond to the maturity of the trees
– the older the bigger the tree, but also how long they burn (how many time steps).
If a tree is on fire, set its value negative. Each time step it will decrease in magnitude (e.g., from -3 to
-2) until it reaches 0. At that point the fire is out and the tree is no longer burning – in fact the tree is no
longer, period.
Once a fire has started it is not guaranteed that it will necessarily spread to other trees, however. There
are many factors involved, for example: moisture content and wind speed, to name two. We will
simulate these factors with another probability.
Since this is a simulation based on probability, we will run the simulation multiple times to see what
the likely outcome is, even though any one run of the simulation may differ.
Tasks
Last week you developed the framework for a 2-D simulation of the spread of a forest fire. This week
we'll add the simulation calculation and run it at a big scale and attempt an animation of the results.
The calculation is not unlike the “life” simulation – the neighboring cells are considered for what will
happen to any particular cell in the next time step.
1
This exercise is based in part on Module 10.3 “Spreading of Fire” in “Introduction to Computational Science”, Angela
B. Shiflet and George W. Shiflet, Princeton University Press, 2014.
Populate the Forest
To set up the simulation we need to populate the forest. Last week we filled in each board with a value
of the rank that what handling that piece of the simulation. Now we want to put “trees” there. Assume
an input value (argv[2]?) that is the density of the forest. We'll start with 0.8 which means that 80% of
the cells should have trees. After allocating the memory for its part of the simulation, i.e., its grid, each
rank should step through each cell of its grid and pick a random number between 0 and 1. If that
number is less than 0.8, then put a tree there. How old a tree? 3, 2, or 1? Pick another random number
to decide that – but it doesn't have to be evenly distributed. Let's favor “old growth”, so pick a random
number between 1 and 5 and make that the tree's age – except that 3 is the maximum, so 3, 4 and 5 all
become a 3 for the grid value.
One more factor is involved in our initialization – where did the fire(s) start? Our simulation will be
for the summer months during “fire season”, so there's a chance that trees will be started on fire by
careless campers or random lightning strikes. Let's say the odds are one-in-a-million that would
happen – well that would mean that that about 405 trees will be aflame in our forest of 22500x22500
(at 80% density). So let's make the probability 0.00000001 (one in 100 million). That should average
only 4 fires at any one point in the park.
Time Steps
Much like with Life and simulations, this one should go in time steps. Have the program terminate
when there is no change from one generation to the next. Then report on what % of the forest remains
standing. The main loop might look like this:
while (changing) {
haloExchange(...);
localchange = nextGen(...);
MPI_Allreduce(&localchange, &changing, … MPI_SUM … );
}
finalDensity = density(...);
MPI_Reduce( &finalDensity, … );
// now report on the total (avg.) density of all ranks
The changing flags can be simple integers (acting like a boolean). In each nextGen call, have it start at
0 and increment it any time a change is made to one of the cells. Call allReduce() so each rank can
see if there has been any change anywhere on the board. When there is no change, the loop ends.
When you visit each cell in the grid, if the cell is on fire, add one. Since burning trees are represented
as negative numbers, then they will burn out when the get to zero. If the cell is zero, skip it – nothing
to see. If the cell is greater than zero (i.e., a non-burning tree) then we need to simulate whether or not
it will catch fire. Let's assume that the probability that it catches fire from a burning tree that is
adjacent to it is 0.33. Count up all the neighboring trees (using only the Von Neumann neighbors – N,
S, E, and W) that are on fire. Each neighboring tree on fire has the chance to spread its fire to the tree
in question. Choose that many random numbers (one for each neighboring tree on fire) and see if the
fire spread to that tree. (That is, if random value < 0.33) Simple optimization: once the fire spreads you
don't need to keep checking the other trees. Get this much of the simulation debugged and running.
Adding Wind to the Simulation
Won't fire spread differently on a windy day? How can we take wind into account in our simulation? If
each neighboring cell the same probability of spreading fire, that is analogous to a calm day (no wind).
If the wind is strong from the west, then the fire in cell (x,y) is more likely to spread to (x+1, y) and
less likely to spread to cell (x-1, y). Similarly, but with opposite sign, for an east wind. A wind from
the north will increase the probability of fire spreading from cell (x,y) to ( _____ , ______ ) and
decrease the likelihood of it spreading from cell (x,y) to ( _____ , ______ ) .
We can simulate a wind, then, by having different probabilities for each of the neighboring cell
positions around the cell in question.
N _____
W | | E
_____
S
Have your simulation take a wind direction (N, S, E or W) and wind speed, from 0 to 33 mph as
command line arguments, corresponding to a change in probability of 0.0 to 0.33 in that direction.
Here's how it will work. If the wind is calm (0) there will be no change in probabilities. If the wind is
33 mph from the west, then for a given cell if its western neighbor is on fire the probability of
spreading to this cell will be (0.33+0.33, that is, the original probability plus the effect of wind, or
0.66). Similarly, if it the eastern neighbor of the cell that is on fire, then with a westerly wind of 33
mph, the probability of the fire spreading west will be 0 ( 0.33 original probability minus the 0.33
effect of wind = 0.0). Other values of wind speed will have less dramatic effect; just be sure to add or
subtract depending on direction.
Running the Simulation
Once you've had a single run complete successfully you'll know about how long it may take to run.
Run the simulation five or six times with the same parameters; you may get a different result each run
(provided that you set your random seed with a non-constant value).
What is the average density of forest remaining? What were your best (most remaining) and worst
(fewest trees remaining) densities?
Now run with different wind speed and directions. What happens? (How) Do your results vary?
Now run the simulation with different initial densities – 10%, 20%, 30% … are any of these
“fireproof”, that is, don't ever have much spread of fire? Are some densities too dense such that any
fire always results in extensive spread?
Create a README file with a table of values for input parameters and output results (remaining tree
density – simply count the non-zero cells for each rank and divide by the total number of cells).
Include text describing your results and your conclusions.
Alternate Ending
If memory in a single node allows, you could have each rank send back its piece of the overall
simulation grid every so many iterations. Then the root node could write these to a file, one value for
each grid cell, separated by commas, with a newline after each row of the overall grid. This file is then
something that you could color with your colormap program from Lab 3. A series of these files would
make for an animation of the spread of the fire.
Download