diff --git a/server/mandel_render_srv.cpp b/server/mandel_render_srv.cpp index 82151a11cd36645b73b95e724825a8db04d68f52..6ce2f4ec98a538958926c5262c3f49a38c75e265 100644 --- a/server/mandel_render_srv.cpp +++ b/server/mandel_render_srv.cpp @@ -99,15 +99,15 @@ void mandel_render_srv::root_process_handling(unsigned long *receive_buffer) void mandel_render_srv::mpi_event_loop() { - double recv_buf[8]; + int recv_op_code; while (true) { MPI_Status status; // 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) { case mpi_opcodes::EXIT: @@ -118,13 +118,18 @@ void mandel_render_srv::mpi_event_loop() } case mpi_opcodes::RENDER: { - mandel_settings recv_settings = { .re_max = recv_buf[1], - .re_min = recv_buf[2], - .im_max = get_max_im(recv_buf[3], recv_buf[4], id, procs), - .im_min = get_min_im(recv_buf[3], recv_buf[4], id, procs), - .img_width = static_cast<unsigned long>(recv_buf[5]), - .img_height = static_cast<unsigned long>(recv_buf[6]), - .iterations = static_cast<unsigned long>(recv_buf[7])}; + qDebug() << "Starting rendering!"; + double mpi_data[4]; + unsigned long mpi_data1[3]; + MPI_Recv(&mpi_data, 4, MPI_DOUBLE, 0, 0, MPI_COMM_WORLD, &status); + MPI_Recv(&mpi_data1, 3, MPI_UNSIGNED_LONG, 0, 0, MPI_COMM_WORLD, &status); + mandel_settings recv_settings = { .re_max = mpi_data[0], + .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; @@ -157,22 +162,29 @@ void mandel_render_srv::handle_recv_data() settings.img_height /= procs; - double mpi_data[8]; + double mpi_data[4]; - mpi_data[0] = static_cast<double>(mpi_opcodes::RENDER); - mpi_data[1] = settings.re_max; - mpi_data[2] = settings.re_min; - mpi_data[3] = settings.im_max; - mpi_data[4] = settings.im_min; - mpi_data[5] = settings.img_width; - mpi_data[6] = settings.img_height; - mpi_data[7] = settings.iterations; + mpi_data[0] = settings.re_max; + mpi_data[1] = settings.re_min; + mpi_data[2] = settings.im_max; + mpi_data[3] = settings.im_min; + + unsigned long mpi_data1[3]; + mpi_data1[0] = settings.img_width; + mpi_data1[1] = settings.img_height; + mpi_data1[2] = settings.iterations; // Send current render settings to other processes. if (procs >= 2) { 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. @@ -186,12 +198,12 @@ void mandel_render_srv::handle_recv_data() } case op_codes::EXIT: { - double mpi_data = 0; + int mpi_data = 0; // Send exit command. if (procs >= 2) { 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();