converted computations to use the C++ complex<double> class
git-svn-id: svn://anubis/gvsu@325 45c1a28c-8058-47b2-ae61-ca45b979098e
This commit is contained in:
parent
fc4cf4b420
commit
22f840d3d5
@ -1,7 +1,8 @@
|
||||
|
||||
#include <math.h> /* sqrt() */
|
||||
#include <complex.h> /* complex, I, creal(), cimag() */
|
||||
#include <complex>
|
||||
#include "FatouComputation.h"
|
||||
using namespace std;
|
||||
|
||||
#define LEEWAY 0.001
|
||||
#define ITERATIONS 100
|
||||
@ -12,13 +13,13 @@ static unsigned int colors[] = {0xFF0000, 0x00FF00, 0x0000FF};
|
||||
|
||||
unsigned int FatouComputation::compute(double x, double y)
|
||||
{
|
||||
double complex z = 0.1;
|
||||
double complex p = x + I * y;
|
||||
complex<double> z(0.1);
|
||||
complex<double> p(x, y);
|
||||
|
||||
for (int iter = 0; iter < ITERATIONS; iter++)
|
||||
{
|
||||
z = p * (1 - z) * z;
|
||||
if (cabs(z) > 2.0)
|
||||
z = p * (complex<double>(1) - z) * z;
|
||||
if (abs(z) > 2.0)
|
||||
{
|
||||
return colors[iter % (sizeof(colors)/sizeof(colors[0]))];
|
||||
}
|
||||
|
@ -1,12 +1,13 @@
|
||||
|
||||
#include <math.h> /* sqrt() */
|
||||
#include <complex.h> /* complex, I, creal(), cimag() */
|
||||
#include <complex>
|
||||
#include "NewtonComputation.h"
|
||||
using namespace std;
|
||||
|
||||
#define LEEWAY 0.001
|
||||
#define ITERATIONS 32
|
||||
#define CLOSE_ENOUGH(z, x, y) \
|
||||
(fabs(creal(z) - (x)) < LEEWAY && fabs(cimag(z) - (y)) < LEEWAY)
|
||||
(fabs(real(z) - (x)) < LEEWAY && fabs(imag(z) - (y)) < LEEWAY)
|
||||
|
||||
/*
|
||||
* This Computation class generates a design in the complex plane
|
||||
@ -15,7 +16,7 @@
|
||||
*/
|
||||
unsigned int NewtonComputation::compute(double x, double y)
|
||||
{
|
||||
double complex rootGuess = x + I * y;
|
||||
complex<double> rootGuess(x, y);
|
||||
static double halfRoot3 = sqrt(3) / 2.0;
|
||||
|
||||
for (int iter = 0; iter < ITERATIONS; iter++)
|
||||
@ -61,6 +62,6 @@ unsigned int NewtonComputation::compute(double x, double y)
|
||||
* More information can be found at:
|
||||
* http://www.willamette.edu/~sekino/fractal/fractal.htm
|
||||
*/
|
||||
rootGuess -= (cpow(rootGuess, 6.0) - 1.0) / (6.0 * cpow(rootGuess, 5.0));
|
||||
rootGuess -= (pow(rootGuess, 6.0) - 1.0) / (6.0 * pow(rootGuess, 5.0));
|
||||
}
|
||||
}
|
||||
|
@ -147,6 +147,8 @@ int main(int argc, char * argv[])
|
||||
/* slave loop */
|
||||
for (;;)
|
||||
{
|
||||
// DEBUG:
|
||||
cout << "MPI node " << my_rank << " waiting for command." << endl;
|
||||
/* wait for a redraw or quit command */
|
||||
MPI_Recv(&window_vals[0], 4, MPI_DOUBLE,
|
||||
MPI_ANY_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD, NULL);
|
||||
@ -155,6 +157,9 @@ int main(int argc, char * argv[])
|
||||
x_center = window_vals[1];
|
||||
y_center = window_vals[2];
|
||||
zoom = window_vals[3];
|
||||
// DEBUG:
|
||||
cout << "MPI node " << my_rank << " received ("
|
||||
<< x_center << ", " << y_center << "), zoom " << zoom << endl;
|
||||
draw(my_rank, world_size, nprocs, width, height,
|
||||
NULL, taskVals, computation);
|
||||
}
|
||||
@ -226,6 +231,8 @@ void getSizes(int * rank, int * size, int * nprocs)
|
||||
void draw(int rank, int world_size, int nprocs, int width, int height,
|
||||
Uint32 * pixels, Uint32 * taskVals, Computation * computation)
|
||||
{
|
||||
// DEBUG:
|
||||
cout << "In draw() with rank " << rank << endl;
|
||||
MPI_Status mpi_status;
|
||||
if (world_size == 1)
|
||||
{
|
||||
@ -302,6 +309,8 @@ void draw(int rank, int world_size, int nprocs, int width, int height,
|
||||
|
||||
void sendWindowVals(double * winVals, int world_size)
|
||||
{
|
||||
// DEBUG:
|
||||
cout << "Master sending out new window values" << endl;
|
||||
for (int to_proc = 1; to_proc < world_size; to_proc++)
|
||||
{
|
||||
MPI_Send(winVals, 4, MPI_DOUBLE, to_proc,
|
||||
|
Loading…
x
Reference in New Issue
Block a user