Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
Andreas Kempe
mpi-mandelbrot
Commits
58dd708a
Commit
58dd708a
authored
Oct 03, 2015
by
Andreas Kempe
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added the possibility of shutting down the rendering processes remotely.
parent
98c53188
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
33 additions
and
3 deletions
+33
-3
client/main_window.cpp
client/main_window.cpp
+14
-0
client/main_window.h
client/main_window.h
+1
-0
network/network_defines.h
network/network_defines.h
+2
-1
server/mandel_render_srv.cpp
server/mandel_render_srv.cpp
+16
-2
No files found.
client/main_window.cpp
View file @
58dd708a
...
...
@@ -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
;
}
client/main_window.h
View file @
58dd708a
...
...
@@ -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
();
...
...
network/network_defines.h
View file @
58dd708a
...
...
@@ -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
server/mandel_render_srv.cpp
View file @
58dd708a
...
...
@@ -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
());
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment