Go to the documentation of this file.
27 #ifndef AlpsKnowledgeBrokerMPI_h_
28 #define AlpsKnowledgeBrokerMPI_h_
348 int & numNodesProcessed,
349 int & numNodesBranched,
350 int & numNodesDiscarded,
351 int & numNodesPartial,
353 bool & betterSolution);
358 MPI_Request &request);
378 double receiverWorkload);
383 double receiverWorkload);
396 double recvWL = 0.0);
605 bool showBanner =
true)
640 bool showBanner =
true);
void decSendCount(const char *how, int s=1)
Decrement the number of sent message.
char * smallBuffer_
Small message buffer.
bool blockHubReport_
Indicate whether a hub need to report state to master.
void initializeSearch(int argc, char *argv[], AlpsModel &model, bool showBanner=true)
This function.
int clusterNodeProcessed_
To record how many nodes by a cluster.
MPI_Request forwardRequestR_
void workerAskIndices()
A worker ask for node index from master.
void incSendCount(const char *how, int s=1)
Increment the number of sent message.
int processNum_
The Number of processes launched.
AlpsProcessType processType_
The AlpsProcessType of this process.
void receiveKnowledge(AlpsKnowledgeType type, int sender, int receiver, char *&msgBuffer, int msgSize, int msgTag, MPI_Comm comm, MPI_Status *status, bool blocking)
Receive knowlege.
void hubMain()
Hub generates subtrees and sends them to workers in Round-Robin way.
void spiralDonateNode()
Unpack msg and donate a node.
double systemWorkQuantity_
The workload quantity of the whole system.
AlpsModel is a base class for user application problem data.
double incumbentValue_
Incumbent value.
void init()
Initialize member data.
void sendIncumbent()
Sent the incumbent value and rank to its two child if eixt.
void receiveSizeBuf(char *&buf, int sender, int tag, MPI_Comm comm, MPI_Status *status)
Receive the size of buffer, allocate memory for buffer, then receive the message and put it in buffer...
int hubNum_
The Number of hubs.
void deleteSubTrees()
Delete subTrees in pools and the active subtree.
double rampDownTime_
The time spent in ramp down.
void hubForceWorkerTerm()
Hub tell workers to terminate due to reaching limits or other reason.
~AlpsKnowledgeBrokerMPI()
Destructor.
AlpsKnowledgeBrokerMPI()
Default construtor.
void incRecvCount(const char *how, int s=1)
Increment the number of received message.
void workerMain()
Worker first receive subtrees, then start to explore them.
bool blockWorkerReport_
Indicate whether a worker need to report state to its hub.
bool hubWork_
Whether hub should also work as a worker.
bool * hubReported_
Indicate which hub has been reported its work.
void hubBalanceWorkers()
Hub balances the workloads of its workers.
void sendNodeModelGen(int receiver, int doUnitWork)
Send a node from rampUpSubTree's node pool and generated model knowledge.
void tellMasterRecv()
Inform master that a proc has received workload during a load balance initialized by master.
MPI_Request solRequestL_
Send model knoledge request.
int * hubRanks_
The global ranks of the hubs.
double * workerWorkQualities_
The workload qualities of workers in the cluster to which this proces belongs.
AlpsTimer masterTimer_
Master timer.
void sendFinishInit(const int target, MPI_Comm comm)
Send finish initialization signal to the target process.
int masterDoBalance_
Whether master do load balance.
virtual int getNumKnowledges(AlpsKnowledgeType kt) const
Query the number of knowledge in the given type of a knowledge pool.
double msgTime_
The time spent processing messages (include idle).
void masterMain(AlpsTreeNode *root)
Master generates subtrees and sends them to hubs in Round-Robin way.
bool forceTerminate_
Terminate due to reaching limits (time and node) or other reason.
char * largeBuffer2_
Large message buffer.
void search(AlpsModel *model)
Search best solution for a given model.
AlpsTimer hubTimer_
Hub timer.
void masterBalanceHubs()
Master balance the workload of hubs.
AlpsProcessType
This enumerative constant describes the various process types.
char * largeBuffer_
Large message buffer.
void donateWork(char *&buf, int tag, MPI_Status *status, int recvID=-1, double recvWL=0.0)
A worker donate its workload to the specified worker.
AlpsKnowledgeBrokerMPI(int argc, char *argv[], AlpsModel &model, bool showBanner=true)
Useful construtor.
void sendKnowledge(AlpsKnowledgeType type, int sender, int receiver, char *&msgBuffer, int msgSize, int msgTag, MPI_Comm comm, bool blocking)
Set knowlege.
void masterForceHubTerm()
Master tell hubs to terminate due to reaching limits or other reason.
virtual int getMasterRank() const
Query the global rank of the Master.
void masterAskHubDonate(int donorID, int receiverID, double receiverWorkload)
Master asks a hub to donate its workload to another hub.
int unitWorkNodes_
Number of nodes in one unit of work.
int clusterRecvCount_
The number of new messages received by the processes in clusterComm_ after last survey.
void spiralRecvProcessNode()
Unpack the node, explore it and send load info to master.
virtual double getBestEstimateQuality()
Get best estimalted quality in system.
void broadcastModel(const int id, const int source)
Broadcast the model from source to other processes.
This class holds one node of the search tree.
void hubsShareWork(char *&buf, MPI_Status *status)
Two hubs share their workload.
virtual void printBestSolution(char *outputFile=0) const
Master prints out the best solution that it knows.
bool blockTermCheck_
Indicate whether do termination check.
int globalRank_
The rank of the process in MPI_COMM_WORLD.
MPI_Comm hubComm_
Communicator consists of all hubs.
AlpsTimer workerTimer_
Worker timer.
int sendCount_
The number of new messages sent by the process after last survey.
virtual double getIncumbentValue() const
The process queries the quality of the incumbent this process stores.
double clusterWorkQuantity_
The workload quantity of the cluster to which the process belongs.
double workQuantity_
The workload quantity of the workload on the process.
virtual double getBestQuality() const
The master queries the quality of the best solution it knowns.
int recvCount_
The number of new messages received by the process after last survey.
void hubUpdateCluStatus(char *&buf, MPI_Status *status, MPI_Comm comm)
A hub unpacks the status of a worker from buffer.
void processMessages(char *&buffer, MPI_Status &status, MPI_Request &request)
Processing messages.
void workerReportStatus(int tag, MPI_Comm comm)
A worker report its status (workload and msg counts) to its hub.
int * workerNodeProcesseds_
To record how many nodes processed for each worker in a cluster.
double masterBalancePeriod_
The period that master do load balancing.
AlpsKnowledgeBrokerMPI & operator=(const AlpsKnowledgeBrokerMPI &)
virtual int getProcRank() const
Query the global rank of the process.
double workQuality_
The workload quality of the process.
int haltSearch_
Temporily halt search.
AlpsProcessType * processTypeList_
The AlpsProcessType of all process.
void refreshClusterStatus()
A hub adds its status to the cluster's status.
void updateWorkloadInfo()
Calculate the work quality and quantity on this process.
double * hubWorkQuantities_
The workload quantities of all clusters/hubs.
double idleTime_
The time spent waiting for work.
AlpsKnowledgeType
Type of knowledge like solution, node, cut...
void receiveRampUpNode(int sender, MPI_Comm comm, MPI_Status *status)
First receive the size and the contend of a node, then construct a subtree with this received node.
void refreshSysStatus()
The master re-calculate the system status.
virtual void searchLog()
Log search statistics.
MPI_Group hubGroup_
MPI_Group consists of all hubs.
void receiveSubTree(char *&buf, int sender, MPI_Status *status)
Receive a subtree from the sender process and add it into the subtree pool.
void collectBestSolution(int destination)
Send the best solution from the process having it to destination.
The base class of knowledge broker class.
AlpsReturnStatus doOneUnitWork(int unitWork, double unitTime, AlpsExitStatus &exitStatus, int &numNodesProcessed, int &numNodesBranched, int &numNodesDiscarded, int &numNodesPartial, int &depth, bool &betterSolution)
Explore a subtree from subtree pool for certain units of work/time.
void packEncoded(AlpsEncoded *enc, char *&buf, int &size, int &position, MPI_Comm comm)
Pack an AlpsEncoded instance into buf.
int clusterSize_
The actual size of the cluster to which the process belongs.
void rootSearch(AlpsTreeNode *root)
This function.
int systemRecvCount_
The total number of messages sent by the all processes.
MPI_Request subTreeRequest_
Send subtree request.
void masterUpdateSysStatus(char *&buf, MPI_Status *status, MPI_Comm comm)
Master unpack the status of a hub from buf and update system status.
void sendModelKnowledge(MPI_Comm comm, int receiver=-1)
Set generated knowlege (related to model) to receiver.
double systemWorkQuality_
The workload quality of the whole system.
double systemWorkQuantityForce_
The workload quantity of the whole system before forcing termination.
bool * workerReported_
Indicate which worker has been reported its work.
void recvErrorCode(char *&bufLarge)
Receive error code and set solution status.
int userClusterSize_
The user reqested size of a cluster.
int masterRank_
The global rank of the master.
int modelGenPos_
Size of the shared knowledge.
void workerRecvIndices(char *&bufLarge)
A worker receive node index from master.
void masterSendIndices(char *&bufLarge)
Master send a batch of node indices to the receiving worker.
MPI_Request modelKnowRequestR_
double * workerWorkQuantities_
The workload quantities of workers in the cluster to which this proces belongs.
void hubReportStatus(int tag, MPI_Comm comm)
A hub reports its status (workload and msg counts) to the master.
MPI_Comm clusterComm_
Communicator of the cluster to which the process belongs.
int systemSendCount_
The total number of messages sent by the all processes.
double rampUpTime_
The time spent in ramp up.
int myHubRank_
The global rank of its hub for a worker.
MPI_Request forwardRequestL_
Forward model knoledge request.
int incumbentID_
The process id that store the incumbent.
void tellHubRecv()
Inform hub that a proc has received workload during a load balance initialized by a hub.
double * hubWorkQualities_
The workload qualities of hubs.
void forwardModelKnowledge()
AlpsSubTree * rampUpSubTree_
A subtree used in during up.
void hubAllocateDonation(char *&buf, MPI_Status *status)
Hub allocates the donated workload to its workers.
int clusterSendCount_
The number of new messages sent by the processes in clusterComm_ after last survey.
void decRecvCount(const char *how, int s=1)
Decrement the number of sent message.
void hubAskWorkerDonate(int donorID, int receiverID, double receiverWorkload)
Hub asks a worker to donate its workload to another worker.
int * hubNodeProcesseds_
To record how many nodes processed for each hub.
This class contains the data pertaining to a particular subtree in the search tree.
MPI_Request modelKnowRequestL_
Send model knoledge request.
void spiralMaster(AlpsTreeNode *root)
Static load balancing: spiral.
double clusterWorkQuality_
The workload quality of the cluster to which the process belong.
bool unpackSetIncumbent(char *&buf, MPI_Status *status)
unpack the incumbent value, then store it and the id of the process having the incumbent in AlpsDataP...
virtual int getNumNodeLeftSystem()
void sendSizeBuf(char *&buf, int size, int position, const int target, const int tag, MPI_Comm comm)
Send the size and content of a buffer to the target process.
AlpsPsStats psStats_
More statistics.
char * attachBuffer_
Buffer attached to MPI when sharing generated knowledge.
void hubSatisfyWorkerRequest(char *&buf, MPI_Status *status)
Hub satisfies the workload rquest from a worker.
void changeWorkingSubTree(double &changeWorkThreshold)
Change subtree to be explored if it is too worse.
bool sendSubTree(const int target, AlpsSubTree *&st, int tag)
Send a given subtree to the target process.
void sendRampUpNode(const int target, MPI_Comm comm)
Send the size and the content of the best node of a given subtree to the target process.
int modelGenID_
The global rank of the process that share generated model knowledge.
AlpsEncoded * unpackEncoded(char *&buf, int &position, MPI_Comm comm, int size=-1)
Unpack the given buffer into an AlpsEncoded instance.
bool updateIncumbent_
Indicate whether the incumbent value is updated between two checking point.
double hubReportPeriod_
The period that a hub load balancing and report cluster status.
virtual bool hasKnowledge(AlpsKnowledgeType kt) const
Query whether there are knowledges in the given type of knowledge pools.
int hubDoBalance_
Whether a hub do load balance.
int clusterRank_
The local rank of the process in clusterComm_.
void receiveModelKnowledge(MPI_Comm comm)
Receive generated knowlege (related to model) from sender.
@ AlpsKnowledgeTypeSolution
void sendErrorCodeToMaster(int errorCode)
Send error code to master.
bool allHubReported_
Indicate whether all hubs have reported status to master at least once.
void requestKnowledge(AlpsKnowledgeType type, int sender, int receiver, char *&msgBuffer, int msgSize, int msgTag, MPI_Comm comm, bool blocking)
Request knowlege.
virtual std::pair< AlpsKnowledge *, double > getBestKnowledge(AlpsKnowledgeType kt) const
Get the best knowledge in the given type of knowledge pools.
void rootInitMaster(AlpsTreeNode *root)
Static load balancing: Root Initialization.
virtual AlpsProcessType getProcType() const
Query the type (master, hub, or worker) of the process.
bool blockAskForWork_
Indicate whether a worker need to as for work from its hub.
MPI implementation of AlpsKnowledgeBroker interface.