Last active
August 29, 2015 14:19
-
-
Save disa-mhembere/451fc602409bdadb96a8 to your computer and use it in GitHub Desktop.
A stub for the game of life
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// gameoflife.c | |
// Name: YOUR NAME HERE | |
// JHED: YOUR JHED HERE | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <assert.h> | |
#include <string.h> | |
#include "mpi.h" | |
#define ITERATIONS 64 | |
#define GRID_WIDTH 256 | |
#define DIM 16 // assume a square grid | |
int main ( int argc, char** argv ) { | |
int global_grid[ 256 ] = {0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | |
0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0, | |
1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0, | |
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | |
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | |
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | |
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | |
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | |
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | |
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | |
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | |
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | |
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | |
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | |
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | |
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }; | |
// MPI Standard variable | |
int num_procs; | |
int ID, j; | |
int iters = 0; | |
// Messaging variables | |
MPI_Status stat; | |
// TODO add other variables as necessary | |
// MPI Setup | |
if ( MPI_Init( &argc, &argv ) != MPI_SUCCESS ) | |
{ | |
printf ( "MPI_Init error\n" ); | |
} | |
MPI_Comm_size ( MPI_COMM_WORLD, &num_procs ); // Set the num_procs | |
MPI_Comm_rank ( MPI_COMM_WORLD, &ID ); | |
assert ( DIM % num_procs == 0 ); | |
// TODO Setup your environment as necessary | |
for ( iters = 0; iters < ITERATIONS; iters++ ) { | |
// TODO: Add Code here or a function call to you MPI code | |
// Output the updated grid state | |
// FIXME: Feel free to print more iterations when you debug but only | |
// submit with the 64th iteration printing and do not change the | |
// format of the printed output. | |
if ( ID == 0 && iters == ITERATIONS-1) { | |
printf ( "\nIteration %d: final grid:\n", iters ); | |
for ( j = 0; j < GRID_WIDTH; j++ ) { | |
if ( j % DIM == 0 ) { | |
printf( "\n" ); | |
} | |
printf ( "%d ", global_grid[j] ); | |
} | |
printf( "\n" ); | |
} | |
} | |
// TODO: Clean up memory | |
MPI_Finalize(); // finalize so I can exit | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment