The Original CHomP Software
|
This class defines a generic coordinator task object for the multi-work distributed computations framework. More...
#include <mwcoord.h>
Public Member Functions | |
mwCoordinator () | |
The default constructor. More... | |
virtual | ~mwCoordinator () |
The virtual destructor. More... | |
void | KeepWorkers (bool keep=true) |
Makes workers keep running after the coordinator's completion. More... | |
int | SaveWorkers (const char *filename) |
Saves addresses of workers to the given file in the form of address:port. More... | |
void | Init (mwData &data) |
Defines a portion of initialization data which will be sent to every newly connected worker. More... | |
int | Coordinate (mwWorker *w=NULL) |
Run the coordinator until all the work has been completed. 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 | Prepare (mwData &data) |
Prepares a piece of data to be sent to a worker. More... | |
virtual int | Accept (mwData &data) |
Accepts a result received from a worker. More... | |
virtual int | Reject (mwData &data) |
Acknowledges data that was rejected by a worker. More... | |
int | RunLoop (bool no_more_data) |
Runs the main communication loop: Sends the data to workers and receives the results of their computations. More... | |
int | RunLoopLocally () |
Runs the main communication loop using the local worker. More... | |
void | ConnectWorkers () |
Connects to all workers in the list. More... | |
void | BeginListening () |
Begins listening at the given port. More... | |
void | DisconnectAll () |
Disconnects all the workers (normally called in the destructor). More... | |
int | SendMessageC (int fd, unsigned int code, const mwData &x) const |
Sends a message with data to the given socket as a coordinator. More... | |
int | RecvMessageC (int fd, unsigned int &code, mwData &x) const |
Receives a message with data from the socket of a worker. More... | |
Static Private Member Functions | |
static void | mwTableDel (int *tab, int len, int pos) |
A helper function for deleting a table entry and shifting the remainder of the table backwards. More... | |
static void | mwTableDel (mwData *tab, int len, int pos) |
A helper function for deleting a table entry and shifting the remainder of the table backwards using the method "Take" of the mwData class. More... | |
Private Attributes | |
bool | singleWork |
Should data be processed locally only? More... | |
mwWorker * | localWorker |
The address of a local worker or 0 if none is available. More... | |
bool | keepWorkers |
Should the workers be kept running after coordinator is done? More... | |
mwData | initData |
The initialization data that has to be sent to workers. More... | |
int | nWaiting |
The number of workers waiting for their data. More... | |
mwWorkerData | xWaiting [mwMAXWORK] |
The workers waiting for their tasks. More... | |
int | nWorking |
The number of workers processing their data. More... | |
mwWorkerData | xWorking [mwMAXWORK] |
The workers processing their data. More... | |
int | nToDo |
The number of data pieces to be sent to working tasks. More... | |
mwData | xToDo [mwMAXWORK] |
The data pieces waiting to be sent to working tasks. More... | |
int | nRejected |
The number of recently rejected pieces of data. More... | |
mwData | xRejected [mwMAXWORK] |
The recently rejected pieces of data. More... | |
int | nDone |
The number of recently finished pieces of data. More... | |
mwData | xDone [mwMAXWORK] |
The recently finished pieces of data. More... | |
int | listensocket |
The socket number at which new workers are listened to. More... | |
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 coordinator task object for the multi-work distributed computations framework.
Each coordinator class defined by the user must inherit from this class.
|
inline |
The default constructor.
Definition at line 288 of file mwcoord.h.
|
inlinevirtual |
The virtual destructor.
Definition at line 342 of file mwcoord.h.
References DisconnectAll().
|
inlineprivatevirtual |
Accepts a result received from a worker.
Should return mwOk on success, mwError to stop the computations. Please, overload this function in the class you derive from mwCoordinator.
Reimplemented in chomp::multiwork::mwSubCoordinator< dim, coord >.
Definition at line 452 of file mwcoord.h.
References chomp::multiwork::mwOk.
Referenced by Coordinate().
|
inlineprivate |
Begins listening at the given port.
Definition at line 603 of file mwcoord.h.
References listensocket, chomp::multiwork::mwTask::logFile, chomp::multiwork::mwListen(), and chomp::multiwork::mwTask::Port().
Referenced by Coordinate().
|
inlineprivate |
Connects to all workers in the list.
Definition at line 554 of file mwcoord.h.
References chomp::multiwork::mwTask::computers, initData, keepWorkers, chomp::multiwork::mwTask::logFile, chomp::multiwork::mwConnect(), chomp::multiwork::mwDontKeepMsg, chomp::multiwork::mwInitMsg, chomp::multiwork::mwKeepMsg, mwMAXWORK, chomp::multiwork::mwOk, nWaiting, chomp::multiwork::mwTask::ports, SendMessageC(), and xWaiting.
Referenced by Coordinate().
|
inline |
Run the coordinator until all the work has been completed.
If a worker object is supplied, the work will be done locally unless any remote worker is connected to the coordinator. Return mwOk or mwError.
Definition at line 1061 of file mwcoord.h.
References Accept(), BeginListening(), ConnectWorkers(), initData, listensocket, localWorker, chomp::multiwork::mwTask::logFile, chomp::multiwork::mwError, chomp::multiwork::mwNoData, chomp::multiwork::mwOk, nDone, nRejected, nToDo, nWaiting, nWorking, Prepare(), Reject(), RunLoop(), RunLoopLocally(), singleWork, xDone, xRejected, and xToDo.
|
inlineprivate |
Disconnects all the workers (normally called in the destructor).
Definition at line 306 of file mwcoord.h.
References keepWorkers, chomp::multiwork::mwTask::logFile, chomp::multiwork::mwByeMsg, chomp::multiwork::mwDisconnect(), chomp::multiwork::mwDontKeepMsg, chomp::multiwork::mwKeepMsg, nWaiting, nWorking, SendMessageC(), xWaiting, and xWorking.
Referenced by ~mwCoordinator().
|
inline |
|
inline |
Makes workers keep running after the coordinator's completion.
Definition at line 350 of file mwcoord.h.
References keepWorkers.
|
inlinestaticprivate |
|
inlinestaticprivate |
A helper function for deleting a table entry and shifting the remainder of the table backwards using the method "Take" of the mwData class.
Definition at line 1218 of file mwcoord.h.
|
inlineprivatevirtual |
Prepares a piece of data to be sent to a worker.
Should return mwOk on success, mwNothing if there is no data to send based on the computations completed so far, mwError to cancel the computations. Please, overload this function in the class you derive from mwCoordinator.
Reimplemented in chomp::multiwork::mwSubCoordinator< dim, coord >.
Definition at line 447 of file mwcoord.h.
References chomp::multiwork::mwNoData.
Referenced by Coordinate().
|
inlineprivate |
Receives a message with data from the socket of a worker.
Returns mwOk on success or mwError in the case of failure.
Definition at line 483 of file mwcoord.h.
References chomp::multiwork::mwTask::ControlNumber(), chomp::multiwork::mwTask::logFile, chomp::multiwork::mwError, chomp::multiwork::mwOk, and chomp::multiwork::mwTask::RecvMessage().
Referenced by RunLoop().
|
inlineprivatevirtual |
Acknowledges data that was rejected by a worker.
Should return mwOk if this is fine, or mwError to cancel the computations. Please, overload this function in the class you derive from mwCoordinator unless the default behavior is fine (returning mwOk and ignoring the data).
Reimplemented in chomp::multiwork::mwSubCoordinator< dim, coord >.
Definition at line 457 of file mwcoord.h.
References chomp::multiwork::mwOk.
Referenced by Coordinate().
|
inlineprivate |
Runs the main communication loop: Sends the data to workers and receives the results of their computations.
If there is no_more_data then waits for the running tasks until they finalize and some data becomes available. Otherwise, returns also when a new worker is ready to acquire a portion of data for processing. Returns mwOk or mwError.
Definition at line 626 of file mwcoord.h.
References initData, keepWorkers, listensocket, localWorker, chomp::multiwork::mwTask::logFile, chomp::multiwork::mwAccept(), chomp::multiwork::mwCanRead, chomp::multiwork::mwCanWrite, chomp::multiwork::mwDisconnect(), chomp::multiwork::mwDontKeepMsg, chomp::multiwork::mwError, chomp::multiwork::mwInitMsg, chomp::multiwork::mwKeepMsg, chomp::multiwork::mwLost, mwMAXWORK, chomp::multiwork::mwNone, chomp::multiwork::mwOk, chomp::multiwork::mwPortMsg, chomp::multiwork::mwReject, chomp::multiwork::mwRejectedMsg, chomp::multiwork::mwSelect(), chomp::multiwork::mwStdMsg, chomp::multiwork::mwTimeOut, nDone, nRejected, nToDo, nWaiting, nWorking, RecvMessageC(), SendMessageC(), singleWork, chomp::multiwork::swap(), chomp::multiwork::mwTask::TimeOut(), xDone, xRejected, xToDo, xWaiting, and xWorking.
Referenced by Coordinate().
|
inlineprivate |
Runs the main communication loop using the local worker.
Returns mwOk or mwError.
Definition at line 507 of file mwcoord.h.
References localWorker, chomp::multiwork::mwTask::logFile, chomp::multiwork::mwError, mwMAXWORK, chomp::multiwork::mwOk, chomp::multiwork::mwReject, nDone, nRejected, nToDo, nWaiting, xDone, xRejected, and xToDo.
Referenced by Coordinate().
|
inline |
Saves addresses of workers to the given file in the form of address:port.
Repeated combinations are saved once only.
Definition at line 356 of file mwcoord.h.
References keepWorkers, chomp::multiwork::mwError, chomp::multiwork::mwOk, nWaiting, nWorking, xWaiting, and xWorking.
|
inlineprivate |
Sends a message with data to the given socket as a coordinator.
Returns mwOk on success and mwError in the case of failure.
Definition at line 473 of file mwcoord.h.
References chomp::multiwork::mwTask::ControlNumber(), and chomp::multiwork::mwTask::SendMessage().
Referenced by ConnectWorkers(), DisconnectAll(), and RunLoop().
|
private |
The initialization data that has to be sent to workers.
Definition at line 224 of file mwcoord.h.
Referenced by ConnectWorkers(), Coordinate(), Init(), and RunLoop().
|
private |
Should the workers be kept running after coordinator is done?
Definition at line 219 of file mwcoord.h.
Referenced by ConnectWorkers(), DisconnectAll(), KeepWorkers(), RunLoop(), and SaveWorkers().
|
private |
The socket number at which new workers are listened to.
Definition at line 261 of file mwcoord.h.
Referenced by BeginListening(), Coordinate(), and RunLoop().
|
private |
The address of a local worker or 0 if none is available.
Definition at line 216 of file mwcoord.h.
Referenced by Coordinate(), RunLoop(), and RunLoopLocally().
|
private |
The number of recently finished pieces of data.
Definition at line 253 of file mwcoord.h.
Referenced by Coordinate(), RunLoop(), and RunLoopLocally().
|
private |
The number of recently rejected pieces of data.
Definition at line 247 of file mwcoord.h.
Referenced by Coordinate(), RunLoop(), and RunLoopLocally().
|
private |
The number of data pieces to be sent to working tasks.
Definition at line 241 of file mwcoord.h.
Referenced by Coordinate(), RunLoop(), and RunLoopLocally().
|
private |
The number of workers waiting for their data.
Definition at line 229 of file mwcoord.h.
Referenced by ConnectWorkers(), Coordinate(), DisconnectAll(), RunLoop(), RunLoopLocally(), and SaveWorkers().
|
private |
The number of workers processing their data.
Definition at line 235 of file mwcoord.h.
Referenced by Coordinate(), DisconnectAll(), RunLoop(), and SaveWorkers().
|
private |
Should data be processed locally only?
Definition at line 213 of file mwcoord.h.
Referenced by Coordinate(), and RunLoop().
The recently finished pieces of data.
Definition at line 256 of file mwcoord.h.
Referenced by Coordinate(), RunLoop(), and RunLoopLocally().
The recently rejected pieces of data.
Definition at line 250 of file mwcoord.h.
Referenced by Coordinate(), RunLoop(), and RunLoopLocally().
The data pieces waiting to be sent to working tasks.
Definition at line 244 of file mwcoord.h.
Referenced by Coordinate(), RunLoop(), and RunLoopLocally().
|
private |
The workers waiting for their tasks.
Definition at line 232 of file mwcoord.h.
Referenced by ConnectWorkers(), DisconnectAll(), RunLoop(), and SaveWorkers().
|
private |
The workers processing their data.
Definition at line 238 of file mwcoord.h.
Referenced by DisconnectAll(), RunLoop(), and SaveWorkers().