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

Sending the data to rendering processes as the correct types.

Removed casting to and from double data types when sending MPI data.
parent 7795b9c4
Branches
Tags
No related merge requests found
...@@ -99,15 +99,15 @@ void mandel_render_srv::root_process_handling(unsigned long *receive_buffer) ...@@ -99,15 +99,15 @@ void mandel_render_srv::root_process_handling(unsigned long *receive_buffer)
void mandel_render_srv::mpi_event_loop() void mandel_render_srv::mpi_event_loop()
{ {
double recv_buf[8]; int recv_op_code;
while (true) while (true)
{ {
MPI_Status status; MPI_Status status;
// Sending the opcode as a double as well to only have to use one transmission. // Sending the opcode as a double as well to only have to use one transmission.
MPI_Recv(&recv_buf, 8, MPI_DOUBLE, 0, 0, MPI_COMM_WORLD, &status); MPI_Recv(&recv_op_code, 1, MPI_INT, 0, 0, MPI_COMM_WORLD, &status);
mpi_opcodes op_code = static_cast<mpi_opcodes>(recv_buf[0]); mpi_opcodes op_code = static_cast<mpi_opcodes>(recv_op_code);
switch (op_code) switch (op_code)
{ {
case mpi_opcodes::EXIT: case mpi_opcodes::EXIT:
...@@ -118,13 +118,18 @@ void mandel_render_srv::mpi_event_loop() ...@@ -118,13 +118,18 @@ void mandel_render_srv::mpi_event_loop()
} }
case mpi_opcodes::RENDER: case mpi_opcodes::RENDER:
{ {
mandel_settings recv_settings = { .re_max = recv_buf[1], qDebug() << "Starting rendering!";
.re_min = recv_buf[2], double mpi_data[4];
.im_max = get_max_im(recv_buf[3], recv_buf[4], id, procs), unsigned long mpi_data1[3];
.im_min = get_min_im(recv_buf[3], recv_buf[4], id, procs), MPI_Recv(&mpi_data, 4, MPI_DOUBLE, 0, 0, MPI_COMM_WORLD, &status);
.img_width = static_cast<unsigned long>(recv_buf[5]), MPI_Recv(&mpi_data1, 3, MPI_UNSIGNED_LONG, 0, 0, MPI_COMM_WORLD, &status);
.img_height = static_cast<unsigned long>(recv_buf[6]), mandel_settings recv_settings = { .re_max = mpi_data[0],
.iterations = static_cast<unsigned long>(recv_buf[7])}; .re_min = mpi_data[1],
.im_max = get_max_im(mpi_data[2], mpi_data[3], id, procs),
.im_min = get_min_im(mpi_data[2], mpi_data[3], id, procs),
.img_width = mpi_data1[0],
.img_height = mpi_data1[1],
.iterations = mpi_data1[2] };
settings = recv_settings; settings = recv_settings;
...@@ -157,22 +162,29 @@ void mandel_render_srv::handle_recv_data() ...@@ -157,22 +162,29 @@ void mandel_render_srv::handle_recv_data()
settings.img_height /= procs; settings.img_height /= procs;
double mpi_data[8]; double mpi_data[4];
mpi_data[0] = static_cast<double>(mpi_opcodes::RENDER); mpi_data[0] = settings.re_max;
mpi_data[1] = settings.re_max; mpi_data[1] = settings.re_min;
mpi_data[2] = settings.re_min; mpi_data[2] = settings.im_max;
mpi_data[3] = settings.im_max; mpi_data[3] = settings.im_min;
mpi_data[4] = settings.im_min;
mpi_data[5] = settings.img_width; unsigned long mpi_data1[3];
mpi_data[6] = settings.img_height; mpi_data1[0] = settings.img_width;
mpi_data[7] = settings.iterations; mpi_data1[1] = settings.img_height;
mpi_data1[2] = settings.iterations;
// Send current render settings to other processes. // Send current render settings to other processes.
if (procs >= 2) if (procs >= 2)
{ {
for (int i = 1; i < procs; ++i) for (int i = 1; i < procs; ++i)
MPI_Send(mpi_data, 8, MPI_DOUBLE, i, 0, MPI_COMM_WORLD); {
// Send op code
int op_code = static_cast<int>(mpi_opcodes::RENDER);
MPI_Send(&op_code, 1, MPI_INT, i, 0, MPI_COMM_WORLD);
MPI_Send(mpi_data, 4, MPI_DOUBLE, i, 0, MPI_COMM_WORLD);
MPI_Send(mpi_data1, 3, MPI_UNSIGNED_LONG, i, 0, MPI_COMM_WORLD);
}
} }
// Update the settings for the root process. // Update the settings for the root process.
...@@ -186,12 +198,12 @@ void mandel_render_srv::handle_recv_data() ...@@ -186,12 +198,12 @@ void mandel_render_srv::handle_recv_data()
} }
case op_codes::EXIT: case op_codes::EXIT:
{ {
double mpi_data = 0; int mpi_data = 0;
// Send exit command. // Send exit command.
if (procs >= 2) if (procs >= 2)
{ {
for (int i = 1; i < procs; ++i) for (int i = 1; i < procs; ++i)
MPI_Send(&mpi_data, 1, MPI_DOUBLE, i, 0, MPI_COMM_WORLD); MPI_Send(&mpi_data, 1, MPI_INT, i, 0, MPI_COMM_WORLD);
} }
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