The Original CHomP Software
|
This class defines a generic worker task object for the multi-work distributed computations framework. More...
#include <mwworker.h>
Public Member Functions | |
mwWorker () | |
The default constructor. More... | |
virtual | ~mwWorker () |
The destructor. More... | |
int | Work () |
Runs the worker on this computer. More... | |
void | KeepWorker (bool keep=true) |
Makes the worker keep running after the coordinator has disconnected. More... | |
![]() | |
mwTask () | |
The default constructor. More... | |
virtual | ~mwTask () |
The destructor. More... | |
void | Port (int number) |
Sets the port number for the communication or 0 to use none. More... | |
int | Port () const |
Returns the current port number. More... | |
void | ControlNumber (unsigned int number) |
Sets the control number for identification. More... | |
unsigned int | ControlNumber () const |
Returns the currently set identification control number. More... | |
void | TimeOut (int seconds) |
Sets the network connection time-out interval in seconds. More... | |
int | TimeOut () const |
Returns the currently set network connection time-out interval. More... | |
int | LogFile (const char *filename) |
Begins logging detailed communication debug information to the given file. More... | |
void | LogFile (const mwTask &other) |
Uses another task's log file to log this task's information. More... | |
void | LogClose () |
Closes the log file and adds a line with the time information unless this log file was borrowed from another task. More... | |
int | Add (const char *name, int port=-1) |
Adds an address to the list of computers to connect to at the beginning of working or coordinating. More... | |
int | Load (const char *filename) |
Loads computer addresses from the given file. More... | |
int | QuitWorkers () |
Quits all the workers whose addresses were added with the 'Add' and 'Load' functions. More... | |
Private Member Functions | |
virtual int | Process (mwData &data) |
This function is called to process a data portion and replace it with the result of computation. More... | |
virtual int | Initialize (mwData &data) |
This function is called to process initialization data, if any. More... | |
int | WorkOne (int fd) |
Runs one working session after having connected to the coordinator at the socket identified by 'fd'. More... | |
int | SendMessageW (int fd, unsigned int code, const mwData &x) const |
Sends a message with data to the given socket as a worker. More... | |
int | RecvMessageW (int fd, unsigned int &code, mwData &x) const |
Receives a message with data from the socket of a coordinator. More... | |
Private Attributes | |
bool | keepWorker |
Should the worker remain running after coordinator disconnects? More... | |
Friends | |
class | mwCoordinator |
Additional Inherited Members | |
![]() | |
static int | SendMessage (int fd, unsigned int ctrl, unsigned int code, const mwData &x) |
Sends a message with data to the given socket. More... | |
static int | RecvMessage (int fd, unsigned int &ctrl, unsigned int &code, mwData &x) |
Receives a message with data from the given socket. More... | |
![]() | |
std::ofstream * | logFile |
The debug log file stream. More... | |
std::vector< std::string > | computers |
A list of workers or coordinators to connect to at start-up. More... | |
std::vector< int > | ports |
A list of port numbers of workers to connect to at start-up. More... | |
This class defines a generic worker task object for the multi-work distributed computations framework.
Each worker class defined by the user must inherit from this class.
Definition at line 54 of file mwworker.h.
|
inline |
The default constructor.
Definition at line 119 of file mwworker.h.
|
inlinevirtual |
The destructor.
Definition at line 124 of file mwworker.h.
|
inlineprivatevirtual |
This function is called to process initialization data, if any.
This data is sent to a new worker immediately after the connection with the coordinator has been established. It should return mwOk on success or mwError in case of error to quit the program. Please, overload this function in the class you derive from the class 'mwWorker' and program it with the actual code.
Definition at line 144 of file mwworker.h.
References chomp::multiwork::mwOk.
Referenced by WorkOne().
|
inline |
Makes the worker keep running after the coordinator has disconnected.
Otherwise, the worker quits in that situation.
Definition at line 131 of file mwworker.h.
References keepWorker.
|
inlineprivatevirtual |
This function is called to process a data portion and replace it with the result of computation.
It should return mwOk on success, mwReject to reject the data, or mwError in case of error to quit the program. Please, overload this function in the class you derive from the class 'mwWorker' and program it with the actual task.
Reimplemented in chomp::multiwork::mwSubWorker< dim, coord >.
Definition at line 139 of file mwworker.h.
References chomp::multiwork::mwOk.
Referenced by WorkOne().
|
inlineprivate |
Receives a message with data from the socket of a coordinator.
Returns mwOk on success or mwError in the case of failure.
Definition at line 161 of file mwworker.h.
References chomp::multiwork::mwTask::ControlNumber(), chomp::multiwork::mwTask::logFile, chomp::multiwork::mwError, chomp::multiwork::mwOk, and chomp::multiwork::mwTask::RecvMessage().
Referenced by WorkOne().
|
inlineprivate |
Sends a message with data to the given socket as a worker.
Returns mwOk on success and mwError in the case of failure.
Definition at line 151 of file mwworker.h.
References chomp::multiwork::mwTask::ControlNumber(), and chomp::multiwork::mwTask::SendMessage().
Referenced by WorkOne().
|
inline |
Runs the worker on this computer.
Returns mwOk or mwError.
Definition at line 387 of file mwworker.h.
References chomp::multiwork::mwTask::computers, keepWorker, chomp::multiwork::mwTask::logFile, chomp::multiwork::mwAccept(), chomp::multiwork::mwConnect(), chomp::multiwork::mwDisconnect(), chomp::multiwork::mwError, chomp::multiwork::mwListen(), chomp::multiwork::mwOk, chomp::multiwork::mwTimeOut, chomp::multiwork::mwTask::Port(), chomp::multiwork::mwTask::ports, chomp::multiwork::mwTask::TimeOut(), chomp::multiwork::mwTask::timeout, and WorkOne().
|
inlineprivate |
Runs one working session after having connected to the coordinator at the socket identified by 'fd'.
Returns mwOK if everything was fine or mwError if some error occurred and the worker should better exit.
Definition at line 185 of file mwworker.h.
References Initialize(), keepWorker, chomp::multiwork::mwTask::logFile, chomp::multiwork::mwByeMsg, chomp::multiwork::mwCanRead, chomp::multiwork::mwDontKeepMsg, chomp::multiwork::mwError, chomp::multiwork::mwInitMsg, chomp::multiwork::mwKeepMsg, chomp::multiwork::mwLost, chomp::multiwork::mwNone, chomp::multiwork::mwOk, chomp::multiwork::mwPortMsg, chomp::multiwork::mwReject, chomp::multiwork::mwRejectedMsg, chomp::multiwork::mwSelect(), chomp::multiwork::mwStdMsg, chomp::multiwork::mwTimeOut, chomp::multiwork::mwTask::Port(), Process(), RecvMessageW(), SendMessageW(), and chomp::multiwork::mwTask::TimeOut().
Referenced by Work().
|
friend |
Definition at line 103 of file mwworker.h.
|
private |
Should the worker remain running after coordinator disconnects?
Definition at line 100 of file mwworker.h.
Referenced by KeepWorker(), Work(), and WorkOne().