Open main menu

CDOT Wiki β

Changes

Assorted Algorithm Alliteration

3,286 bytes added, 15:12, 5 October 2012
Created page with '{{GPU610/DPS915 Index | 20123}} = Assorted Algorithm Alliteration = == Team Members == # [mailto:mddelacruz1@myseneca.ca?subject=GPU610 Mark de la Cruz] # [mailto:elim2@mysene…'
{{GPU610/DPS915 Index | 20123}}
= Assorted Algorithm Alliteration =


== Team Members ==
# [mailto:mddelacruz1@myseneca.ca?subject=GPU610 Mark de la Cruz]
# [mailto:elim2@myseneca.ca?subject=GPU610 Edwin Lim]
# [mailto:mdafidchao@myseneca.ca?subject=GPU610 Michael Afidchao]
# [mailto:mddelacruz1@myseneca.ca;elim2@myseneca.ca;mdafidchao@myseneca.ca?subject=GPU610 eMail All]

== Proposal ==
=== Game of Life ===
The Game of Life is a "0 player game" cellular automaton. With an initial configuration,
the game uses a set of rules to determine what happens to the life forms from generation
to generation. More information can be found at http://en.wikipedia.org/wiki/Conway%27s_Game_of_Life

Source code can be found here:

http://www.shodor.org/media/content//petascale/materials/UPModules/exercises/Game_of_Life/GoL_Serial_Source_Files.zip

==== Profile ====
These results were taken with an execution of 50000 generations and default settings for the rest of the options.
<pre>
Each sample counts as 0.01 seconds.
% cumulative self self total
time seconds seconds calls Ts/call Ts/call name
55.82 14.76 14.76 eval_rules
41.75 25.80 11.04 do_draw
2.23 26.39 0.59 update_grid
0.19 26.44 0.05 copy_bounds
0.00 26.44 0.00 11025 0.00 0.00 rand_double
0.00 26.44 0.00 1 0.00 0.00 allocate_grids
0.00 26.44 0.00 1 0.00 0.00 free_grids
0.00 26.44 0.00 1 0.00 0.00 init_grids
0.00 26.44 0.00 1 0.00 0.00 moveWindow
0.00 26.44 0.00 1 0.00 0.00 parse_args
0.00 26.44 0.00 1 0.00 0.00 randomize_grid
0.00 26.44 0.00 1 0.00 0.00 setupWindow
0.00 26.44 0.00 1 0.00 0.00 write_grid
</pre>

==== Code Snippet ====
<pre>
/*
eval_rules()
Evaluate the rules of Life for each cell; count
neighbors and update current state accordingly.
*/
void eval_rules (struct life_t * life) {
int i,j,k,l,neighbors;

int ncols = life->ncols;
int nrows = life->nrows;

int ** grid = life->grid;
int ** next_grid = life->next_grid;

for (i = 1; i <= ncols; i++) {
for (j = 1; j <= nrows; j++) {
neighbors = 0;

// count neighbors
for (k = i-1; k <= i+1; k++) {
for (l = j-1; l <= j+1; l++) {
if (!(k == i && l == j) && grid[k][l] != DEAD)
neighbors++;
}
}

// update state
if (neighbors < LOWER_THRESH || neighbors > UPPER_THRESH)
next_grid[i][j] = DEAD;
else if (grid[i][j] != DEAD || neighbors == SPAWN_THRESH)
next_grid[i][j] = grid[i][j]+1;
}
}
}
</pre>


== Instructor's Comments ==
1
edit