33#ifndef _CHOMP_MULTIWORK_MWWORKER_H_
34#define _CHOMP_MULTIWORK_MWWORKER_H_
165 unsigned int ctrl = 0;
166 int result =
this ->
RecvMessage (fd, ctrl, code, x);
178 *
logFile <<
"Wrong control code received "
179 "from the coordinator: " << ctrl <<
"." << std::endl;
188 bool sendPort = (
this ->
Port () > 0);
189 int timelimit =
this ->
TimeOut ();
203 int result =
mwSelect (portArray, 1, fd, ioFlags,
211 "waiting for data from the "
212 "coordinator." << std::endl;
220 *
logFile <<
"Disconnected while "
221 "waiting for data from the "
222 "coordinator." << std::endl;
230 *
logFile <<
"Time out reached while "
231 "waiting for data from the "
232 "coordinator." << std::endl;
239 unsigned int code = 0;
246 *
logFile <<
"Error while receiving data "
247 "from the coordinator." << std::endl;
255 *
logFile <<
"The connection closed "
256 "by the coordinator." << std::endl;
264 *
logFile <<
"Initializing the worker." <<
277 if (initResult !=
mwOk)
280 *
logFile <<
"The initialization "
281 "failed." << std::endl;
296 *
logFile <<
"Disconnecting upon "
297 "coordinator's request." <<
307 unsigned int retcode = 0;
316 *
logFile <<
"Data processing failed." <<
325 *
logFile <<
"* Data rejected." << std::endl;
334 *
logFile <<
"* Data processed." << std::endl;
342 d <<
this ->
Port ();
350 *
logFile <<
"Error while sending "
351 "the port number." <<
359 *
logFile <<
"* Port number sent." <<
370 *
logFile <<
"Connection lost while sending "
371 "data to the coordinator." <<
380 *
logFile <<
"Error while sending data." <<
391 *
logFile <<
"Running as a WORKER." << std::endl;
395 *
logFile <<
"There is no network in use, "
396 "so exiting right now." << std::endl;
398 *
logFile <<
"Using the sockets interface "
399 "provided by wxWindows." << std::endl;
401 *
logFile <<
"Using the standard sockets "
402 "for network connections." << std::endl;
408 for (
unsigned cur = 0; cur <
this ->
computers. size (); ++ cur)
411 int port =
this ->
ports [cur];
412 const char *name =
this ->
computers [cur]. c_str ();
424 *
logFile <<
"Connection to " << name <<
":" <<
425 port << ((fd < 0) ?
" refused." :
426 " established.") << std::endl;
433 if ((fd < 0) && (
this ->
Port () > 0))
437 *
logFile <<
"Waiting for a coordinator at "
438 "port " <<
this ->
Port () <<
"." <<
446 *
logFile <<
"Error: This port is "
447 "probably in use." <<
453 std::string computer;
462 *
logFile <<
"Time out. Exiting." <<
471 *
logFile <<
"Error while connecting "
472 "to a coordinator." <<
479 *
logFile <<
"Connected to a coordinator "
480 "at '" << computer <<
"'." <<
496 *
logFile <<
"An exception was thrown while "
497 "processing data." << std::endl;
511 *
logFile <<
"============================" <<
This class defines a generic coordinator task object for the multi-work distributed computations fram...
This class is used to convert data structures into a single sequence of bytes and to retrieve this da...
This class defines a generic task object (coordinator or worker) for the multi-work distributed compu...
static int SendMessage(int fd, unsigned int ctrl, unsigned int code, const mwData &x)
Sends a message with data to the given socket.
int Port() const
Returns the current port number.
std::ofstream * logFile
The debug log file stream.
int TimeOut() const
Returns the currently set network connection time-out interval.
unsigned int ControlNumber() const
Returns the currently set identification control number.
static int RecvMessage(int fd, unsigned int &ctrl, unsigned int &code, mwData &x)
Receives a message with data from the given socket.
int timeout
The network communication time-out in seconds.
std::vector< std::string > computers
A list of workers or coordinators to connect to at start-up.
std::vector< int > ports
A list of port numbers of workers to connect to at start-up.
This class defines a generic worker task object for the multi-work distributed computations framework...
int WorkOne(int fd)
Runs one working session after having connected to the coordinator at the socket identified by 'fd'.
int Work()
Runs the worker on this computer.
virtual int Initialize(mwData &data)
This function is called to process initialization data, if any.
virtual int Process(mwData &data)
This function is called to process a data portion and replace it with the result of computation.
virtual ~mwWorker()
The destructor.
mwWorker()
The default constructor.
int RecvMessageW(int fd, unsigned int &code, mwData &x) const
Receives a message with data from the socket of a coordinator.
int SendMessageW(int fd, unsigned int code, const mwData &x) const
Sends a message with data to the given socket as a worker.
void KeepWorker(bool keep=true)
Makes the worker keep running after the coordinator has disconnected.
bool keepWorker
Should the worker remain running after coordinator disconnects?
This file contains the basic configuration of the MultiWork module, mainly as a definition of a serie...
This file contains the definition of the MultiWork data class.
This file contains the definition of some low-level functions for the TCP/IP streams communication an...
This file contains the definition of the MultiWork task class.
@ mwTimeOut
A connection time out has occurred.
@ mwCanRead
Reading possible.
@ mwNone
No flag selected.
@ mwLost
The network connection has been lost.
@ mwReject
The data has been rejected.
@ mwError
A serious error occurred.
@ mwOk
Everything is fine.
int mwListen(int port, int queuesize)
Begins listening at the given port.
int mwSelect(const int *workers, int nworkers, int listensocket, int *ioflags, int timeout)
Determines IOflags for each of the workers and additionally the listensocket (the last flag).
int mwAccept(int fd, std::string &computer, int timeout=-1)
Waits for and accepts a connection at the given socket.
void mwDisconnect(int fd)
Disconnects the given socket.
int mwConnect(const char *name, int port)
Connects to the given computer at the given port.
@ mwKeepMsg
Message to the Worker: Keep running after having disconnected.
@ mwStdMsg
Message to the Worker: A standard piece of data to be processed.
@ mwInitMsg
Message to the Worker: A piece of initialization data to be processed.
@ mwRejectedMsg
Message to the Coordinator: The data has been rejected.
@ mwByeMsg
Message to the Worker: Please, disconnect.
@ mwPortMsg
Message to the Coordinator: I will listen at this port number.
@ mwDontKeepMsg
Message to the Worker: Don't keep running after disconnecting.
This namespace contains the entire CHomP library interface.