Title: Cellular Automata: Life with Simple Rules
1Cellular AutomataLife with Simple Rules
- Sharks and Fish
- Predator/Prey Relationships
- Bill Madden, Nancy Ricca and Jonathan Rizzo
- Graduate Students, Computer Science Department
- Research Project using Departments 20-CPU
Cluster
2Overview
- Cellular automata can be used to model complex
systems using simple rules. - Key features
- divide problem space into cells
- each cell can be in one of several finite states
- cells are affected by neighbors according to
rules - all cells are affected simultaneously in a
generation - rules are reapplied over many generations
Adapted from Wilkinson,B and M. Allen (1999)
Parallel Programming 2nd Edition, NJ, Pearson
Prentice Hall, p189
3Overview
- This project models a predator/prey relationship
- Begins with a randomly distributed population of
fish, sharks, and empty cells in a 1000x2000 cell
grid (2 million cells) - Initially,
- 50 of the cells are occupied by fish
- 25 are occupied by sharks
- 25 are empty
4Heres the number 2 million
- Fish red sharks yellow empty black
5Rules
- A dozen or so rules describe life in each cell
- birth, longevity and death of a fish or shark
- breeding of fish and sharks
- over- and under-population
- fish/shark interaction
- Important what happens in each cell is
determined only by rules that apply locally, yet
which often yield long-term large-scale patterns.
6Do a LOT of computation!
- Apply a dozen rules to each cell
- Do this for 2 million cells in the grid
- Do this for 20,000 generations
- Well over a trillion calculations per run!
- Do this as quickly as you can
7Do a LOT of computation!
- We used a 20-CPU cluster in the Computer Science
Department (Galaxy) - Gal is the smaller of two clusters run by the
Department (larger one has 64 CPUs) - 15x faster than a single PC
- Longest runs still took about 45 minutes
- GO PARALLEL !!!
8Rules in detail Initial Conditions
- Initially cells contain fish, sharks or are empty
- Empty cells 0 (black pixel)
- Fish 1 (red pixel)
- Sharks 1 (yellow pixel)
9Rules in detail Breeding Rule
- Breeding rule if the current cell is empty
- If there are gt 4 neighbors of one species, and
gt 3 of them are of breeding age, - Fish breeding age gt 2,
- Shark breeding age gt3,
- and there are lt4 of the other species
- then create a species of that type
- 1 baby fish (age 1 at birth)
- -1 baby shark (age -1 at birth)
10Breeding Rule Before
11Breeding Rule After
12Rules in Detail Fish Rules
- If the current cell contains a fish
- Fish live for 10 generations
- If gt5 neighbors are sharks, fish dies (shark
food) - If all 8 neighbors are fish, fish dies
(overpopulation) - If a fish does not die, increment age
13Rules in Detail Shark Rules
- If the current cell contains a shark
- Sharks live for 20 generations
- If gt6 neighbors are sharks and fish neighbors
0, the shark dies (starvation) - A shark has a 1/32 (.031) chance of dying due to
random causes - If a shark does not die, increment age
14Shark Random Death Before
I Sure Hope that the random number chosen is
gt.031
15Shark Random Death After
YES IT IS!!! I LIVE ?
16Programming logic
- Use 2-dimensional array to represent grid
- At any one (x, y) position, value is
- Positive integer (fish present)
- Negative integer (shark present)
- Zero (empty cell)
- Absolute value of cell is age
17Sample Code (C) Breeding
18Parallelism
- A single CPU has to do it all
- Applies rules to first cell in array
- Repeats rules for each successive cell in array
- After 2 millionth cell is processed, array is
updated - One generation has passed
- Repeat this process for many generations
- Every 100 generations or so, convert array to
red, yellow and black pixels and send results to
screen
19Parallelism
- How to split the work among 20 CPUs
- 1 CPU acts as Master (has copy of whole array)
- 18 CPUs act as Slaves (handle parts of the array)
- 1 CPU takes care of screen updates
- Problem communication issue concerning cells
along array boundaries among slaves
20Send Right Boundary Values
21Receive Left Boundary Values
22Send Left Boundary Values
23Receive Right Boundary Values
24Send Right Boundary Values
25Receive Left Boundary Values
26Send Left Boundary Values
27Receive Right Boundary Values
28At intervals, update the master CPU
has copy of entire array
29MPI Classes
- Gal (the 20-CPU cluster we used) has special
enhancements to C, called MPI Classes, which
handle such boundary communication issues - Other than that, each slave processes its portion
of the array much as a single CPU would process
the whole array except, of course, they each have
only 1/18th of the problem to solve!
30Results
- Next several screens show behavior over a span of
10,000 generations (about 25 minutes on Gal)
31Generation 0
32Generation 100
33Generation 500
34Generation 1,000
35Generation 2,000
36Generation 4,000
37Generation 8,000
38Generation 10,500
39Long-term trends
- Borders tended to harden along vertical,
horizontal and diagonal lines - Borders of empty cells form between like species
- Clumps of fish tend to coalesce and form convex
shapes or communities
40Variations of Initial Conditions
- Still using randomly distributed populations
- Medium-sized population. Fish/sharks
occupy 1/16th of total grid Fish 62,703
Sharks 31,301 - Very small population. Fish/sharks
occupy 1/800th of total grid Initial
population Fish 1,298 Sharks 609
41Medium-sized population (1/16 of grid)
Generation 100
2000
1000
4000
8000
42Very Small Populations
- Random placement of very small populations can
favor one species over another - Fish favored sharks die out
- Sharks favored sharks predominate, but fish
survive in stable small numbers
43Very Small Populations
Gen. 100
4000
6000
1500
8000
10,000
12,000
14,000
Ultimate welfare of sharks depends on initial
random placement of fish and sharks
44Very small populations
- Fish can live in stable isolated communities as
small as 20-30 - A community of less than 200 sharks tends not to
be viable
45Parallel Performance
- Parallel processing suggests speedup of close to
18 is possible - Our results 15x speedup
- Reason communication overhead among slaves and
between slaves and master - Communication overhead becomes much worse if
results are communicated more often
46Speed-up
47Communication Overhead
48Acknowledgements
- Bill Madden, Nancy Ricca and Jonathan Rizzo,
Graduate Students, Computer Science Department,
Montclair State University - Dr. Roman Zaritski, Professor, Computer Science
Department, Montclair State University - Galaxy 20-CPU cluster in Computer Science
Department, Montclair State University
49Parallel Processing Laboratory
- This presentation is available on-line at
- http//roman.montclair.edu/Research/Parallel/
- The web site above also hosts a number of other
interesting parallel computing projects and is
the on-line home of the Computer Science
Departments Parallel Processing Laboratory. - GO PARALLEL !!!