added some comments; restored printing # of cores on MPI node #0

git-svn-id: svn://anubis/gvsu@337 45c1a28c-8058-47b2-ae61-ca45b979098e
This commit is contained in:
josh 2008-12-08 18:05:41 +00:00
parent a21c8ff635
commit 60d9bb6178

View File

@ -1,7 +1,9 @@
/* /*
* Josh Holtrop * Josh Holtrop
* 2008-12-11 * 2008-12-11
* barebones SDL program * CS677 Final Project
* This program implements a fractal-image generator and viewer
* that uses OpenMPI and OpenMP.
*/ */
#include <SDL/SDL.h> #include <SDL/SDL.h>
@ -18,6 +20,9 @@ using namespace std;
#define getXVirt(x) (((x) - (width >> 1)) * zoom + x_center) #define getXVirt(x) (((x) - (width >> 1)) * zoom + x_center)
#define getYVirt(y) ((-((y) - (height >> 1))) * zoom + y_center) #define getYVirt(y) ((-((y) - (height >> 1))) * zoom + y_center)
/**************************************************************************
* Utility functions *
*************************************************************************/
bool createWindow(int width, int height, bool createWindow(int width, int height,
SDL_Surface ** screen, Uint32 ** pixels); SDL_Surface ** screen, Uint32 ** pixels);
void getSizes(int * rank, int * size, int * nprocs); 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); Uint32 * pixels, Uint32 * taskVals, Computation * computation);
void sendWindowVals(double * winVals, int world_size); void sendWindowVals(double * winVals, int world_size);
/**************************************************************************
* Global variables *
*************************************************************************/
static double x_center = 0.0; static double x_center = 0.0;
static double y_center = 0.0; static double y_center = 0.0;
static double zoom = 1/300.0; static double zoom = 1/300.0;
/* a "task" will be processing task_size pixels */ /* a "task" will be processing task_size pixels */
static int task_size = 100; static int task_size = 100;
/**************************************************************************
* This is the main entry point for our program *
*************************************************************************/
int main(int argc, char * argv[]) int main(int argc, char * argv[])
{ {
int width = 600; int width = 600;
@ -203,6 +214,10 @@ int main(int argc, char * argv[])
return 0; 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, bool createWindow(int width, int height,
SDL_Surface ** screen, Uint32 ** pixels) SDL_Surface ** screen, Uint32 ** pixels)
{ {
@ -226,6 +241,10 @@ bool createWindow(int width, int height,
return true; 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) void getSizes(int * rank, int * size, int * nprocs)
{ {
MPI_Comm_rank(MPI_COMM_WORLD, rank); MPI_Comm_rank(MPI_COMM_WORLD, rank);
@ -249,8 +268,7 @@ void getSizes(int * rank, int * size, int * nprocs)
{ {
int total_nprocs = 0; int total_nprocs = 0;
cout << "Number of cores on each MPI node:" << endl; cout << "Number of cores on each MPI node:" << endl;
int i = (*size > 1) ? 1 : 0; for (int i = 0; i < *size; i++)
for (; i < *size; i++)
{ {
cout << all_nprocs[i] << " "; cout << all_nprocs[i] << " ";
total_nprocs += 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, void draw(int rank, int world_size, int nprocs, int width, int height,
Uint32 * pixels, Uint32 * taskVals, Computation * computation) 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) void sendWindowVals(double * winVals, int world_size)
{ {
// DEBUG: // DEBUG: