Presentation is loading. Please wait.

Presentation is loading. Please wait.

Cellular Automata: Life with Simple Rules

Similar presentations


Presentation on theme: "Cellular Automata: Life with Simple Rules"— Presentation transcript:

1 Cellular Automata: Life with Simple Rules
Sharks and Fish: Predator/Prey Relationships Bill Madden, Nancy Ricca and Jonathan Rizzo Graduate Students, Computer Science Department Research Project using Department’s 20-CPU Cluster

2 Overview 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 2

3 Overview 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 3

4 Here’s the number 2 million
Fish: red; sharks: yellow; empty: black 4

5 Rules 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. 5

6 Do 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 6

7 Do 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 !!! 7

8 Rules 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) 8

9 Rules in detail: Breeding Rule
Breeding rule: if the current cell is empty If there are >= 4 neighbors of one species, and >= 3 of them are of breeding age, Fish breeding age >= 2, Shark breeding age >=3, and there are <4 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) 9

10 Breeding Rule: Before EMPTY 10

11 Breeding Rule: After 11

12 Rules in Detail: Fish Rules
If the current cell contains a fish: Fish live for 10 generations If >=5 neighbors are sharks, fish dies (shark food) If all 8 neighbors are fish, fish dies (overpopulation) If a fish does not die, increment age 12

13 Rules in Detail: Shark Rules
If the current cell contains a shark: Sharks live for 20 generations If >=6 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 13

14 Shark Random Death: Before
I Sure Hope that the random number chosen is >.031 14

15 Shark Random Death: After
YES IT IS!!! I LIVE  15

16 Programming 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 16

17 Sample Code (C++): Breeding
17

18 Parallelism 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 18

19 Parallelism 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 19

20 Send Right Boundary Values
Subdivide grid into 18 vertical slices Each slice has a left boundary and a right boundary Set the left boundary of the left-most slice to a preset value (we used 0=empty) Do same for right boundary of right-most slice (and top and bottom of all slices) Each slave sends its boundary results to its left and right neighbor slaves Each slave receives boundary information from its neighbor slaves At intervals, all slaves update the master CPU 20

21 Receive Left Boundary Values
21

22 Send Left Boundary Values
22

23 Receive Right Boundary Values
23

24 Send Right Boundary Values
24

25 Receive Left Boundary Values
25

26 Send Left Boundary Values
26

27 Receive Right Boundary Values
27

28 At intervals, update the master CPU
has copy of entire array 28

29 MPI 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! 29

30 Results Next several screens show behavior over a span of 10,000+ generations (about 25 minutes on Gal) 30

31 Generation: 0 31

32 Generation: 100 32

33 Generation: 500 33

34 Generation: 1,000 34

35 Generation: 2,000 35

36 Generation: 4,000 36

37 Generation: 8,000 37

38 Generation: 10,500 38

39 Long-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’ 39

40 Variations 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 40

41 Medium-sized population (1/16 of grid)
Generation 100 1000 2000 4000 8000 41

42 Very 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 42

43 Very Small Populations
Gen. 100 1500 4000 6000 8000 10,000 12,000 14,000 Ultimate welfare of sharks depends on initial random placement of fish and sharks 43

44 Very 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 44

45 Parallel 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 45

46 Speed-up 46

47 Communication Overhead
47

48 Acknowledgements 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 48

49 Parallel Processing Laboratory
This presentation is available on-line at: The web site above also hosts a number of other interesting parallel computing projects and is the on-line “home” of the Computer Science Department’s Parallel Processing Laboratory. GO PARALLEL !!! 49


Download ppt "Cellular Automata: Life with Simple Rules"

Similar presentations


Ads by Google