Skip to content
Snippets Groups Projects
Commit 037b9943 authored by Andreas Kempe's avatar Andreas Kempe
Browse files

Multithreaded drawing working.

parent de9b9a76
Branches
Tags
No related merge requests found
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
#include <Magick++.h> #include <Magick++.h>
#include <complex> #include <complex>
#include <cmath> #include <cmath>
#include <sstream>
#define IMG_WIDTH 800 #define IMG_WIDTH 800
#define IMG_HEIGHT 600 #define IMG_HEIGHT 600
...@@ -17,6 +18,8 @@ ...@@ -17,6 +18,8 @@
using namespace std; using namespace std;
using namespace Magick; using namespace Magick;
int effective_height = IMG_HEIGHT;
struct MandelResult struct MandelResult
{ {
unsigned int end_iterations; unsigned int end_iterations;
...@@ -58,30 +61,36 @@ MandelResult IsMandelbrotPoint(int x, int y, unsigned int iterations) ...@@ -58,30 +61,36 @@ MandelResult IsMandelbrotPoint(int x, int y, unsigned int iterations)
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
int id; int id;
int numprocs; int procs;
MPI_Init(&argc, &argv); MPI_Init(&argc, &argv);
MPI_Comm_size(MPI_COMM_WORLD, &procs);
MPI_Comm_rank(MPI_COMM_WORLD, &id); MPI_Comm_rank(MPI_COMM_WORLD, &id);
cout << id << endl;
Image my_image(IMG_SIZE, "white"); // Calculate this threads working area.
effective_height /= procs;
Image my_image(Geometry(IMG_WIDTH, effective_height), "white");
for (int x = 0; x < IMG_WIDTH; ++x) for (int x = 0; x < IMG_WIDTH; ++x)
{ {
for (int y = 0; y < IMG_HEIGHT; ++y) for (int y = effective_height * id; y < effective_height * (id + 1); ++y)
{ {
MandelResult result = IsMandelbrotPoint(x, y, ITERATIONS); MandelResult result = IsMandelbrotPoint(x, y, ITERATIONS);
if (result.belongs) if (result.belongs)
my_image.pixelColor(x, y, Color("purple")); my_image.pixelColor(x, y - effective_height * id, Color("purple"));
else else
my_image.pixelColor(x, y, Color(0, 0, MaxRGB / ITERATIONS * result.end_iterations)); my_image.pixelColor(x, y - effective_height * id, Color(0, 0, MaxRGB / ITERATIONS * result.end_iterations));
} }
} }
my_image.write("mandelbrot.png"); stringstream ss;
ss << id << ".png";
my_image.write(ss.str());
MPI_Finalize(); MPI_Finalize();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment