Commit de9b9a76 authored by Andreas Kempe's avatar Andreas Kempe

Basic singlethreaded drawing of the set.

parent 151a8c0b
project(mpi-mandel)
cmake_minimum_required(VERSION 2.8)
set(SRC main.cpp)
add_executable(mpi-mandel ${SRC})
include_directories(/home/kempe/lib/include/ImageMagick-6)
link_directories(/home/kempe/lib/lib)
set(CMAKE_C_COMPILER mpicc)
set(CMAKE_CXX_COMPILER mpicxx)
target_link_libraries(mpi-mandel mpi)
set(CMAKE_CXX_FLAGS "-DMAGICKCORE_HDRI_ENABLE=0 -DMAGICKCORE_QUANTUM_DEPTH=16")
target_link_libraries(mpi-mandel mpi Magick++-6.Q16)
#include <mpi.h>
#include <iostream>
#include <Magick++.h>
#include <complex>
#include <cmath>
#define IMG_WIDTH 800
#define IMG_HEIGHT 600
#define IMG_SIZE "800x600"
#define ITERATIONS 100
#define RE_MAX 1
#define RE_MIN -2
#define IM_MAX 2.2
#define IM_MIN -1.7
using namespace std;
using namespace Magick;
struct MandelResult
{
unsigned int end_iterations;
bool belongs;
MandelResult(unsigned int end_iterations, bool belongs) :
end_iterations(end_iterations), belongs(belongs) {}
};
complex<double> GetPixelCoordinate(int x, int y)
{
double re_size = abs(RE_MAX) + abs(RE_MIN);
double im_size = abs(IM_MAX) + abs(IM_MIN);
double re_pp = re_size / IMG_WIDTH;
double im_pp = im_size / IMG_HEIGHT;
return complex<double>(re_pp * x + RE_MIN, im_pp * y + IM_MIN);
}
MandelResult IsMandelbrotPoint(int x, int y, unsigned int iterations)
{
complex<double> point = GetPixelCoordinate(x, y);
complex<double> series_value(0, 0);
for (unsigned int i = 0; i < iterations; ++i)
{
if (real(series_value) * real(series_value) + imag(series_value) * imag(series_value) >= 4)
return MandelResult(i, false);
series_value= pow(series_value, 2) + point;
}
return MandelResult(iterations, true);
}
int main(int argc, char** argv)
{
......@@ -11,7 +63,26 @@ int main(int argc, char** argv)
MPI_Init(&argc, &argv);
MPI_Comm_rank(MPI_COMM_WORLD, &id);
cout << id endl;
cout << id << endl;
Image my_image(IMG_SIZE, "white");
for (int x = 0; x < IMG_WIDTH; ++x)
{
for (int y = 0; y < IMG_HEIGHT; ++y)
{
MandelResult result = IsMandelbrotPoint(x, y, ITERATIONS);
if (result.belongs)
my_image.pixelColor(x, y, Color("purple"));
else
my_image.pixelColor(x, y, Color(0, 0, MaxRGB / ITERATIONS * result.end_iterations));
}
}
my_image.write("mandelbrot.png");
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