skeleton NewtonComputation added, more base logic present
git-svn-id: svn://anubis/gvsu@319 45c1a28c-8058-47b2-ae61-ca45b979098e
This commit is contained in:
parent
de91797a58
commit
c1b75ab6a0
12
cs677/final/Computation.h
Normal file
12
cs677/final/Computation.h
Normal file
@ -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
|
@ -4,6 +4,7 @@ CXXFLAGS := `sdl-config --cflags`
|
|||||||
LDFLAGS := `sdl-config --libs`
|
LDFLAGS := `sdl-config --libs`
|
||||||
TARGET := mpi-fractals
|
TARGET := mpi-fractals
|
||||||
OBJS := mpi-fractals.o
|
OBJS := mpi-fractals.o
|
||||||
|
OBJS += NewtonComputation.o
|
||||||
|
|
||||||
all: $(TARGET)
|
all: $(TARGET)
|
||||||
|
|
||||||
|
7
cs677/final/NewtonComputation.cc
Normal file
7
cs677/final/NewtonComputation.cc
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
|
||||||
|
#include "NewtonComputation.h"
|
||||||
|
|
||||||
|
unsigned int NewtonComputation::compute(double x, double y)
|
||||||
|
{
|
||||||
|
return 0x00FF8800;
|
||||||
|
}
|
13
cs677/final/NewtonComputation.h
Normal file
13
cs677/final/NewtonComputation.h
Normal file
@ -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
|
@ -7,63 +7,93 @@
|
|||||||
#include <SDL/SDL.h>
|
#include <SDL/SDL.h>
|
||||||
#include <mpi.h>
|
#include <mpi.h>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include "Computation.h"
|
||||||
|
#include "NewtonComputation.h"
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
#define PROGNAME "Josh's CS677 Final : MPI Fractal Generator"
|
#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,
|
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);
|
||||||
|
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 main(int argc, char * argv[])
|
||||||
{
|
{
|
||||||
int width = 800;
|
int width = 600;
|
||||||
int height = 600;
|
int height = 600;
|
||||||
int my_rank;
|
int my_rank = 0;
|
||||||
int world_size;
|
int world_size = 0;
|
||||||
int nprocs;
|
int nprocs = 0;
|
||||||
|
Computation * computation = NULL;
|
||||||
|
int fractal_type = 0;
|
||||||
|
|
||||||
SDL_Surface * screen;
|
SDL_Surface * screen;
|
||||||
Uint32 * pixels;
|
Uint32 * pixels;
|
||||||
|
|
||||||
MPI_Init(&argc, &argv);
|
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);
|
getSizes(&my_rank, &world_size, &nprocs);
|
||||||
|
|
||||||
|
switch (fractal_type)
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
default:
|
||||||
|
computation = new NewtonComputation();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
if (my_rank == 0)
|
if (my_rank == 0)
|
||||||
{
|
{
|
||||||
|
SDL_Event event;
|
||||||
|
bool going = true;
|
||||||
bool window_success = createWindow(width, height, &screen, &pixels);
|
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;
|
if (!window_success)
|
||||||
SDL_Event event;
|
going = false;
|
||||||
while (going && SDL_WaitEvent(&event) != 0)
|
|
||||||
|
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:
|
||||||
{
|
going = false;
|
||||||
case SDL_QUIT:
|
break;
|
||||||
|
case SDL_KEYDOWN:
|
||||||
|
if (event.key.keysym.sym == SDLK_q)
|
||||||
going = false;
|
going = false;
|
||||||
break;
|
break;
|
||||||
case SDL_KEYDOWN:
|
|
||||||
if (event.key.keysym.sym == SDLK_q)
|
|
||||||
going = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MPI_Finalize();
|
MPI_Finalize();
|
||||||
|
|
||||||
|
delete computation;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -122,3 +152,26 @@ void getSizes(int * rank, int * size, int * nprocs)
|
|||||||
cout << "Total number of cores: " << total_nprocs << endl;
|
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
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user