Commit 58dd708a authored by Andreas Kempe's avatar Andreas Kempe

Added the possibility of shutting down the rendering processes remotely.

parent 98c53188
......@@ -33,6 +33,10 @@ main_window::main_window(unsigned int port, QWidget* parent) :
connect(rnd_btn, &QPushButton::clicked, this, &main_window::send_img_render);
layout->addWidget(rnd_btn);
QPushButton* exit_btn = new QPushButton("Kill render processes", this);
connect(exit_btn, &QPushButton::clicked, this, &main_window::handle_kill_renderer);
layout->addWidget(exit_btn);
server = new mandel_tcp_server(this);
connect(server, &QTcpServer::newConnection, this, &main_window::handle_new_connection);
server->listen(QHostAddress::Any, port);
......@@ -79,6 +83,15 @@ void main_window::send_img_render()
socket->send_data_packet(rnd_packet);
}
void main_window::handle_kill_renderer()
{
if (!socket)
return;
data_packet kill_packet(op_codes::EXIT, 0, nullptr);
socket->send_data_packet(kill_packet);
}
void main_window::handle_new_connection()
{
socket = server->nextPendingConnection();
......@@ -123,3 +136,4 @@ void main_window::handle_recv_data()
delete packet;
}
......@@ -30,6 +30,7 @@ class main_window : public QWidget
public slots:
void show_image();
void send_img_render();
void handle_kill_renderer();
private slots:
void handle_new_connection();
......
......@@ -11,7 +11,8 @@ enum op_codes : quint32
* encoded as base64 using ImageMagicks
* Blob-class. */
IMG_DATA = 0x1,
RENDER_IMG = 0x2
RENDER_IMG = 0x2,
EXIT = 0x3
};
#endif
......@@ -102,19 +102,18 @@ void mandel_render_srv::mpi_event_loop()
double recv_buf[8];
while (true)
{
cout << "Process " << id << " in event loop!";
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);
cout << "Received opcode: " << recv_buf[0] << endl;
mpi_opcodes op_code = static_cast<mpi_opcodes>(recv_buf[0]);
switch (op_code)
{
case mpi_opcodes::EXIT:
{
MPI_Finalize();
exit(0);
break;
}
......@@ -145,6 +144,7 @@ void mandel_render_srv::handle_recv_data()
{
case op_codes::RENDER_IMG:
{
cout << "Dispatching and starting image rendering!" << endl;
QByteArray payload;
QDataStream stream(&payload, QIODevice::ReadWrite);
......@@ -177,6 +177,20 @@ void mandel_render_srv::handle_recv_data()
start_drawing();
break;
}
case op_codes::EXIT:
{
double 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_Finalize();
exit(0);
break;
}
default:
qDebug() << "Unrecognised op code received: " << static_cast<quint32>(packet->get_op_code());
}
......
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