Commit 037b9943 authored by Andreas Kempe's avatar Andreas Kempe

Multithreaded drawing working.

parent de9b9a76
......@@ -3,6 +3,7 @@
#include <Magick++.h>
#include <complex>
#include <cmath>
#include <sstream>
#define IMG_WIDTH 800
#define IMG_HEIGHT 600
......@@ -17,6 +18,8 @@
using namespace std;
using namespace Magick;
int effective_height = IMG_HEIGHT;
struct MandelResult
{
unsigned int end_iterations;
......@@ -58,30 +61,36 @@ MandelResult IsMandelbrotPoint(int x, int y, unsigned int iterations)
int main(int argc, char** argv)
{
int id;
int numprocs;
int procs;
MPI_Init(&argc, &argv);
MPI_Comm_size(MPI_COMM_WORLD, &procs);
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 y = 0; y < IMG_HEIGHT; ++y)
for (int y = effective_height * id; y < effective_height * (id + 1); ++y)
{
MandelResult result = IsMandelbrotPoint(x, y, ITERATIONS);
if (result.belongs)
my_image.pixelColor(x, y, Color("purple"));
my_image.pixelColor(x, y - effective_height * id, Color("purple"));
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();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment