From 60d9bb61789268076c47a4c69bbedf383359e57c Mon Sep 17 00:00:00 2001 From: josh Date: Mon, 8 Dec 2008 18:05:41 +0000 Subject: [PATCH] added some comments; restored printing # of cores on MPI node #0 git-svn-id: svn://anubis/gvsu@337 45c1a28c-8058-47b2-ae61-ca45b979098e --- cs677/final/mpi-fractals.cc | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/cs677/final/mpi-fractals.cc b/cs677/final/mpi-fractals.cc index 3f1ef4f..5de6339 100644 --- a/cs677/final/mpi-fractals.cc +++ b/cs677/final/mpi-fractals.cc @@ -1,7 +1,9 @@ /* * Josh Holtrop * 2008-12-11 - * barebones SDL program + * CS677 Final Project + * This program implements a fractal-image generator and viewer + * that uses OpenMPI and OpenMP. */ #include @@ -18,6 +20,9 @@ using namespace std; #define getXVirt(x) (((x) - (width >> 1)) * zoom + x_center) #define getYVirt(y) ((-((y) - (height >> 1))) * zoom + y_center) +/************************************************************************** + * Utility functions * + *************************************************************************/ bool createWindow(int width, int height, SDL_Surface ** screen, Uint32 ** pixels); void getSizes(int * rank, int * size, int * nprocs); @@ -25,12 +30,18 @@ void draw(int rank, int world_size, int nprocs, int width, int height, Uint32 * pixels, Uint32 * taskVals, Computation * computation); void sendWindowVals(double * winVals, int world_size); +/************************************************************************** + * Global variables * + *************************************************************************/ static double x_center = 0.0; static double y_center = 0.0; static double zoom = 1/300.0; /* a "task" will be processing task_size pixels */ static int task_size = 100; +/************************************************************************** + * This is the main entry point for our program * + *************************************************************************/ int main(int argc, char * argv[]) { int width = 600; @@ -203,6 +214,10 @@ int main(int argc, char * argv[]) return 0; } +/************************************************************************** + * This utility function is used by the master MPI node to create a * + * window using SDL for displaying the fractal in and getting user input. * + *************************************************************************/ bool createWindow(int width, int height, SDL_Surface ** screen, Uint32 ** pixels) { @@ -226,6 +241,10 @@ bool createWindow(int width, int height, return true; } +/************************************************************************** + * This utility function returns the MPI node's rank, the total number * + * of MPI nodes, and the number of processing cores on the local node * + *************************************************************************/ void getSizes(int * rank, int * size, int * nprocs) { MPI_Comm_rank(MPI_COMM_WORLD, rank); @@ -249,8 +268,7 @@ void getSizes(int * rank, int * size, int * nprocs) { int total_nprocs = 0; cout << "Number of cores on each MPI node:" << endl; - int i = (*size > 1) ? 1 : 0; - for (; i < *size; i++) + for (int i = 0; i < *size; i++) { cout << all_nprocs[i] << " "; total_nprocs += all_nprocs[i]; @@ -260,6 +278,10 @@ void getSizes(int * rank, int * size, int * nprocs) } } +/************************************************************************** + * This function is executed by each MPI node every time a fractal * + * frame is to be drawn. * + *************************************************************************/ void draw(int rank, int world_size, int nprocs, int width, int height, Uint32 * pixels, Uint32 * taskVals, Computation * computation) { @@ -341,6 +363,10 @@ void draw(int rank, int world_size, int nprocs, int width, int height, } } +/************************************************************************** + * This utility function is used by the master process to update all * + * of the slave processes for the position and zoom-level of the view. * + *************************************************************************/ void sendWindowVals(double * winVals, int world_size) { // DEBUG: