Commit 06b9b553 authored by Andreas Kempe's avatar Andreas Kempe

Moved the root processing to its own function.

parent 3e512777
......@@ -19,6 +19,39 @@
using namespace std;
using namespace Magick;
void root_process_handling(unsigned long *receive_buffer)
{
Image my_image(Geometry(IMG_WIDTH, IMG_HEIGHT), "white");
my_image.modifyImage();
Pixels pixel_cache(my_image);
PixelPacket *pixels = pixel_cache.get(0, 0, IMG_WIDTH, IMG_HEIGHT);
cout << "Assembling image!" << endl;
for (unsigned long y = 0; y < IMG_HEIGHT; ++y)
{
cout << "Progress: " << setprecision(3) <<
static_cast<float>(y * 100) / IMG_HEIGHT << " % \r" << flush;
for (unsigned long x = 0; x < IMG_WIDTH; ++x)
{
const unsigned long& iter_res = receive_buffer[y * IMG_WIDTH + x];
if (iter_res == ITERATIONS)
pixels[y * IMG_WIDTH + x] = Color(MaxRGB * 0.55, MaxRGB * 0.35, MaxRGB * 0.6);
else
pixels[y * IMG_WIDTH + x] = Color(MaxRGB * cosf(exp(iter_res)), 0, MaxRGB * sinf(exp(iter_res)));
}
}
pixel_cache.sync();
cout << "Progress: 100 % " << endl;
stringstream ss;
ss << "output.png";
cout << "Saving image!" << endl;
my_image.write(ss.str());
}
int main(int argc, char** argv)
{
......@@ -48,44 +81,14 @@ int main(int argc, char** argv)
if (id == 0)
receive_buffer = new unsigned long[IMG_WIDTH * IMG_HEIGHT];
cout << "Process: " << id << ", Gathering!" << endl;
cout << "Process: " << id << ", gathering!" << endl;
MPI_Gather(mandel.get_point_array(), IMG_WIDTH * effective_height, MPI_UNSIGNED_LONG, receive_buffer,
IMG_WIDTH * effective_height, MPI_UNSIGNED_LONG, 0, MPI_COMM_WORLD);
cout << "Process: " << id << ", done gathering!" << endl;
if (id == 0)
{
Image my_image(Geometry(IMG_WIDTH, IMG_HEIGHT), "white");
my_image.modifyImage();
Pixels pixel_cache(my_image);
PixelPacket *pixels = pixel_cache.get(0, 0, IMG_WIDTH, IMG_HEIGHT);
cout << "Assembling image!" << endl;
for (unsigned long y = 0; y < IMG_HEIGHT; ++y)
{
cout << "Progress: " << setprecision(3) <<
static_cast<float>(y * 100) / IMG_HEIGHT << " % \r" << flush;
for (unsigned long x = 0; x < IMG_WIDTH; ++x)
{
const unsigned long& iter_res = receive_buffer[y * IMG_WIDTH + x];
if (iter_res == ITERATIONS)
pixels[y * IMG_WIDTH + x] = Color(MaxRGB * 0.55, MaxRGB * 0.35, MaxRGB * 0.6);
else
pixels[y * IMG_WIDTH + x] = Color(MaxRGB * cosf(exp(iter_res)), 0, MaxRGB * sinf(exp(iter_res)));
}
}
pixel_cache.sync();
cout << "Progress: 100 % " << endl;
stringstream ss;
ss << "output.png";
cout << "Saving image!" << endl;
my_image.write(ss.str());
}
root_process_handling(receive_buffer);
delete[] calculated_values;
delete[] receive_buffer;
......
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