Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F63198373
client.cc
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Sat, May 18, 10:15
Size
2 KB
Mime Type
text/x-c
Expires
Mon, May 20, 10:15 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
17744033
Attached To
rSCMINICLUSTER SCITAS Mini Cluster
client.cc
View Options
#include "client.hh"
#include <QByteArray>
#include <QDataStream>
#include <QTcpSocket>
#include <iostream>
enum
{
READ_IMAGE
=
-
1
,
READ_IMAGE_WAIT
=
-
2
,
WAIT
=
-
3
,
CONFIGURE
=
-
4
,
};
/* -------------------------------------------------------------------------- */
GridSender
::
GridSender
(
const
Grid
&
grid
)
:
_grid
(
grid
),
prank
(
0
),
psize
(
0
)
{}
void
GridSender
::
setParallelContext
(
int
prank
,
int
psize
)
{
this
->
prank
=
prank
;
this
->
psize
=
psize
;
}
void
GridSender
::
connect
(
const
std
::
string
&
server_name
,
int
port
)
{
socket
=
new
QTcpSocket
();
qDebug
()
<<
prank
<<
"Connecting to"
<<
server_name
.
c_str
();
socket
->
connectToHost
(
QString
(
server_name
.
c_str
()),
port
);
socket
->
waitForConnected
();
qDebug
()
<<
prank
<<
"Connected"
;
char
command
=
CONFIGURE
;
socket
->
putChar
(
command
);
QByteArray
data
;
QDataStream
buffer
(
&
data
,
QIODevice
::
WriteOnly
);
buffer
<<
prank
;
buffer
<<
psize
;
buffer
<<
int
(
_grid
.
size
(
0
));
buffer
<<
int
(
_grid
.
size
(
1
));
buffer
<<
int
(
_grid
.
globalSize
(
0
));
buffer
<<
int
(
_grid
.
globalSize
(
1
));
buffer
<<
int
(
_grid
.
offset
(
0
));
buffer
<<
int
(
_grid
.
offset
(
1
));
buffer
<<
int
(
_grid
.
ghost
());
socket
->
write
(
data
);
qDebug
()
<<
prank
<<
"Waiting for connection confirmation..."
;
socket
->
waitForReadyRead
();
socket
->
getChar
(
&
command
);
qDebug
()
<<
prank
<<
"command"
<<
int
(
command
)
<<
"ok!"
;
}
/* -------------------------------------------------------------------------- */
GridSender
::~
GridSender
()
{
socket
->
disconnectFromHost
();
socket
->
waitForDisconnected
();
}
/* -------------------------------------------------------------------------- */
void
GridSender
::
send
(
bool
wait
)
{
char
command
=
wait
?
READ_IMAGE_WAIT
:
READ_IMAGE
;
socket
->
putChar
(
command
);
qDebug
()
<<
prank
<<
"Sending"
<<
_grid
.
fullSize
()
<<
"chars"
;
socket
->
write
(
_grid
.
data
(),
_grid
.
fullSize
());
socket
->
waitForBytesWritten
();
if
(
wait
)
{
qDebug
()
<<
prank
<<
"Waiting..."
;
if
(
socket
->
waitForReadyRead
())
{
socket
->
getChar
(
&
command
);
qDebug
()
<<
prank
<<
"command"
<<
int
(
command
)
<<
"ok!"
;
}
else
{
qFatal
(
"Confirmation timeout!!!"
);
}
}
}
void
GridSender
::
wait
()
{
char
command
=
WAIT
;
socket
->
putChar
(
command
);
qDebug
()
<<
prank
<<
"Sending wait"
<<
int
(
command
);
socket
->
waitForReadyRead
();
socket
->
getChar
(
&
command
);
qDebug
()
<<
prank
<<
"command"
<<
int
(
command
)
<<
"ok!"
;
}
Event Timeline
Log In to Comment