From c1b75ab6a06947bd3b2880928cf1d896f96e204e Mon Sep 17 00:00:00 2001 From: josh Date: Sat, 6 Dec 2008 21:54:19 +0000 Subject: [PATCH] skeleton NewtonComputation added, more base logic present git-svn-id: svn://anubis/gvsu@319 45c1a28c-8058-47b2-ae61-ca45b979098e --- cs677/final/Computation.h | 12 ++++ cs677/final/Makefile | 1 + cs677/final/NewtonComputation.cc | 7 ++ cs677/final/NewtonComputation.h | 13 ++++ cs677/final/mpi-fractals.cc | 107 +++++++++++++++++++++++-------- 5 files changed, 113 insertions(+), 27 deletions(-) create mode 100644 cs677/final/Computation.h create mode 100644 cs677/final/NewtonComputation.cc create mode 100644 cs677/final/NewtonComputation.h diff --git a/cs677/final/Computation.h b/cs677/final/Computation.h new file mode 100644 index 0000000..8da6884 --- /dev/null +++ b/cs677/final/Computation.h @@ -0,0 +1,12 @@ + +#ifndef COMPUTATION_H +#define COMPUTATION_H COMPUTATION_H + +class Computation +{ +private: +public: + virtual unsigned int compute(double x, double y) = 0; +}; + +#endif diff --git a/cs677/final/Makefile b/cs677/final/Makefile index 1a3df29..a0f34f2 100644 --- a/cs677/final/Makefile +++ b/cs677/final/Makefile @@ -4,6 +4,7 @@ CXXFLAGS := `sdl-config --cflags` LDFLAGS := `sdl-config --libs` TARGET := mpi-fractals OBJS := mpi-fractals.o +OBJS += NewtonComputation.o all: $(TARGET) diff --git a/cs677/final/NewtonComputation.cc b/cs677/final/NewtonComputation.cc new file mode 100644 index 0000000..c9bcfc2 --- /dev/null +++ b/cs677/final/NewtonComputation.cc @@ -0,0 +1,7 @@ + +#include "NewtonComputation.h" + +unsigned int NewtonComputation::compute(double x, double y) +{ + return 0x00FF8800; +} diff --git a/cs677/final/NewtonComputation.h b/cs677/final/NewtonComputation.h new file mode 100644 index 0000000..04e3fda --- /dev/null +++ b/cs677/final/NewtonComputation.h @@ -0,0 +1,13 @@ + +#ifndef NEWTONCOMPUTATION_H +#define NEWTONCOMPUTATION_H NEWTONCOMPUTATION_H + +#include "Computation.h" + +class NewtonComputation : public Computation +{ + public: + unsigned int compute(double x, double y); +}; + +#endif diff --git a/cs677/final/mpi-fractals.cc b/cs677/final/mpi-fractals.cc index cfe0e68..bd5b58b 100644 --- a/cs677/final/mpi-fractals.cc +++ b/cs677/final/mpi-fractals.cc @@ -7,63 +7,93 @@ #include #include #include +#include "Computation.h" +#include "NewtonComputation.h" using namespace std; #define PROGNAME "Josh's CS677 Final : MPI Fractal Generator" +#define getXVirt(x) (((x) - (width >> 1)) * zoom + x_center) +#define getYVirt(y) ((-((y) - (height >> 1))) * zoom + y_center) bool createWindow(int width, int height, SDL_Surface ** screen, Uint32 ** pixels); void getSizes(int * rank, int * size, int * nprocs); +void draw(int rank, int size, int nprocs, int width, int height, + Uint32 * pixels, Computation * computation); + +static double x_center = 0.0; +static double y_center = 0.0; +static double zoom = 1/300.0; int main(int argc, char * argv[]) { - int width = 800; + int width = 600; int height = 600; - int my_rank; - int world_size; - int nprocs; + int my_rank = 0; + int world_size = 0; + int nprocs = 0; + Computation * computation = NULL; + int fractal_type = 0; SDL_Surface * screen; Uint32 * pixels; MPI_Init(&argc, &argv); + for (int i = 1; i < argc; i++) + { + if (!strncmp(argv[i], "-w", 2)) + { + width = atoi(strlen(argv[i]) > 2 ? argv[i] + 1 : argv[++i]); + } + else if (!strncmp(argv[i], "-h", 2)) + { + height = atoi(strlen(argv[i]) > 2 ? argv[i] + 1 : argv[++i]); + } + else if (!strncmp(argv[i], "-t", 2)) + { + fractal_type = atoi(strlen(argv[i]) > 2 ? argv[i] + 1 : argv[++i]); + } + } getSizes(&my_rank, &world_size, &nprocs); + switch (fractal_type) + { + case 0: + default: + computation = new NewtonComputation(); + break; + } + if (my_rank == 0) { + SDL_Event event; + bool going = true; bool window_success = createWindow(width, height, &screen, &pixels); - if (window_success) - { - for (int y = 0; y < height; y++) - { - for (int x = 0; x < width; x++) - { - *pixels++ = (((x * 255 / width) & 0xFF) << 8) - + ((y * 255 / height) & 0xFF); - } - } - SDL_UpdateRect(screen, 0, 0, 0, 0); - bool going = true; - SDL_Event event; - while (going && SDL_WaitEvent(&event) != 0) + if (!window_success) + going = false; + + while (going && SDL_WaitEvent(&event) != 0) + { + draw(my_rank, world_size, nprocs, width, height, + pixels, computation); + SDL_UpdateRect(screen, 0, 0, 0, 0); + switch (event.type) { - switch (event.type) - { - case SDL_QUIT: + case SDL_QUIT: + going = false; + break; + case SDL_KEYDOWN: + if (event.key.keysym.sym == SDLK_q) going = false; - break; - case SDL_KEYDOWN: - if (event.key.keysym.sym == SDLK_q) - going = false; - break; - } + break; } } } MPI_Finalize(); + delete computation; return 0; } @@ -122,3 +152,26 @@ void getSizes(int * rank, int * size, int * nprocs) cout << "Total number of cores: " << total_nprocs << endl; } } + +void draw(int rank, int size, int nprocs, int width, int height, + Uint32 * pixels, Computation * computation) +{ + if (size == 1) + { + for (int y = 0; y < height; y++) + { + for (int x = 0; x < width; x++) + { + double x_virt = getXVirt(x); + double y_virt = getYVirt(y); + *pixels++ = computation->compute(x_virt, y_virt); + } + } + } + else if (rank == 0) + { + } + else + { + } +}