Scippy

UG

Ubiquity Generator framework

paraSolver.h
Go to the documentation of this file.
1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2 /* */
3 /* This file is part of the program and software framework */
4 /* UG --- Ubquity Generator Framework */
5 /* */
6 /* Copyright Written by Yuji Shinano <shinano@zib.de>, */
7 /* Copyright (C) 2021 by Zuse Institute Berlin, */
8 /* licensed under LGPL version 3 or later. */
9 /* Commercial licenses are available through <licenses@zib.de> */
10 /* */
11 /* This code is free software; you can redistribute it and/or */
12 /* modify it under the terms of the GNU Lesser General Public License */
13 /* as published by the Free Software Foundation; either version 3 */
14 /* of the License, or (at your option) any later version. */
15 /* */
16 /* This program is distributed in the hope that it will be useful, */
17 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
18 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
19 /* GNU Lesser General Public License for more details. */
20 /* */
21 /* You should have received a copy of the GNU Lesser General Public License */
22 /* along with this program. If not, see <http://www.gnu.org/licenses/>. */
23 /* */
24 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
25 
26 /**@file paraSolver.h
27  * @brief Base class for solver: Generic parallelized solver.
28  * @author Yuji Shinano
29  *
30  *
31  */
32 
33 
34 /*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
35 
36 
37 #ifndef __PARA_SOLVER_H__
38 #define __PARA_SOLVER_H__
39 
40 #include "paraDef.h"
41 #include "paraComm.h"
42 #include "paraParamSet.h"
44 #include "paraTask.h"
45 #include "paraTimer.h"
46 #include "paraDeterministicTimer.h"
47 #include "paraSolution.h"
48 // #ifdef _MSC_VER
49 // #include "pthread.h"
50 // #endif
51 
52 #define ENFORCED_THRESHOLD 5
53 
54 namespace UG
55 {
56 
57 ///
58 /// termination mode
59 ///
60 static const int NoTerminationMode = 0;
61 static const int NormalTerminationMode = 1;
62 static const int InterruptedTerminationMode = 2;
63 static const int TimeLimitTerminationMode = 3;
64 ///----------------------------------------------
65 static const int UgBaseTerminationModeLast = 3;
66 
67 ///
68 /// class ParaSolver
69 ///
71 {
72 
73 protected:
74 
75  typedef int(ParaSolver::*MessageHandlerFunctionPointer)(int, int);
76 
77  int nHandlers; ///< number of valid message handlers
78  MessageHandlerFunctionPointer *messageHandler; ///< table for message handlers
79 
81 
82  ParaComm *paraComm; ///< ParaCommunicator object
83  ParaParamSet *paraParams; ///< ParaParamSet object
84  ParaRacingRampUpParamSet *racingParams; ///< ParaRacingRampUpParamSet object.
85  ///< This is also a flag to indicate running with racing ramp-up
86  ParaRacingRampUpParamSet *winnerRacingParams; ///< Winner ParaRacingRampUpParamSet object
87 
88  ParaTimer *paraTimer; ///< timer for this ParaSolver
89  ParaDeterministicTimer *paraDetTimer; ///< deterministic timer for this ParaSolver
90 
91  double globalBestIncumbentValue; ///< global best incumbent value
92  ParaSolution *globalBestIncumbentSolution; ///< global best solution. However, this is not always feasible for the current sub-MIP
93  ParaSolution *localIncumbentSolution; ///< incumbent solution generated in local solver
94  ParaSolution *pendingSolution; ///< solution which is pending to update in case of deterministic runs
95  double pendingIncumbentValue; ///< incumbent value which is pending to update in case of deterministic runs
96  ParaInstance *paraInstance; ///< root problem instance
97  ParaTask *currentTask; ///< solving task
98  ParaTask *newTask; ///< new task to solve
99  int terminationMode; ///< indicate that termination mode
100  ///< 0: no termination mode
101  ///< 1: normal termination mode
102  ///< 2: interrupted termination
103  bool warmStarted; ///< indicate whether if system is warm started or not
104  bool rampUp; ///< indicate whether if ramp-up phase is finished or not: true - finish
105  bool racingInterruptIsRequested; ///< indicate a racing interrupt is requested
106  bool racingIsInterrupted; ///< indicate whether if racing phases is interrupted or not: true - interrupted
107  bool racingWinner; ///< indicate racing ramp-up winner or not: true - winner
108  bool waitingSpecificMessage; ///< indicate that this solver is waiting for a specific message
109  bool memoryLimitIsReached; ///< indicate if memory limit is reached or not, when base solver has memory management feature
110 
111  double previousNotificationTime; ///< previous notification time
112  double paraTaskStartTime; ///< start time of current ParaTask
113 
114  ///
115  /// Idle Times
116  ///
117  double previousStopTime; ///< previous stop solving time of this Solver: For measurement
118  double idleTimeToFirstParaTask; ///< idle time to start solving the first ParaTask
119  double idleTimeBetweenParaTasks; ///< idle time between ParaTasks processing
120  double idleTimeAfterLastParaTask; ///< idle time after the last ParaTask was solved
121  double idleTimeToWaitNotificationId; ///< idle time to wait a message within collecting mode
122  double idleTimeToWaitAckCompletion; ///< idle time to wait acknowledgment of completion
123  double idleTimeToWaitToken; ///< idle time to wait token
124  double previousIdleTimeToWaitToken; ///< previous idle time to wait token
125  double offsetTimeToWaitToken; ///< offset time to wait token
126 
127  ///
128  /// Counters related to the current ParaTask
129  ///
130  int nImprovedIncumbent; ///< number of improvements of incumbent value
131 
132  ///
133  /// Counters related to this ParaSolver
134  ///
135  int nParaTasksReceived; ///< number of ParaTasks received in this ParaSolver
136  int nParaTasksSolved; ///< number of ParaTasks solved ( received ) in this ParaSolver
137 
138  bool updatePendingSolutionIsProceeding; ///< update pending solution process is proceeding
139  bool globalIncumbnetValueUpdateFlag; ///< indicate that global incumbent value is updated in iReceiveMessages() routine
140  bool notificationProcessed; ///< if true, notification is issued but not receive the corresponding LCB
141 
142  double eps; ///< absolute values smaller than this are considered zero
143  ///< esp should be set in the constructor of the derived class of ParaSolver
144 
145  double previousCommTime; ///< previous communication time for deterministic execution
146 
147  bool subproblemFreed; ///< indicate that subproblem is already freed or not
148 
149  bool stayAliveAfterInterrupt; ///< indicate that stay alive this solver after interrupt request
150 
151  ///-------------------
152  /// Message handlers
153  ///-------------------
154 
155  ///
156  /// process TagTask
157  /// @return always 0 (for extension)
158  ///
159  virtual int processTagTask(
160  int source, ///< source rank
161  int tag ///< TagTask
162  ) = 0;
163 
164  ///
165  /// process TagTaskReceived
166  /// @return always 0 (for extension)
167  ///
168  virtual int processTagTaskReceived(
169  int source, ///< source rank
170  int tag ///< TagTaskReceived
171  ) = 0;
172 
173  ///
174  /// process TagRampUp
175  /// @return always 0 (for extension)
176  ///
177  virtual int processTagRampUp(
178  int source, ///< source rank
179  int tag ///< TagRampUp
180  )
181  {
182  std::cout << "*** virtual function ParaSolver::processTagRampUp is called ***" << std::endl;
183  return 0;
184  }
185 
186  ///
187  /// process TagSolution
188  /// @return always 0 (for extension)
189  ///
190  virtual int processTagSolution(
191  int source, ///< source rank
192  int tag ///< TagSolution
193  ) = 0;
194 
195  ///
196  /// process TagIncumbentValue
197  /// @return always 0 (for extension)
198  ///
200  int source, ///< source rank
201  int tag ///< TagIncumbentValue
202  )
203  {
204  std::cout << "*** virtual function ParaSolver::processTagIncumbentValue is called ***" << std::endl;
205  return 0;
206  }
207 
208  ///
209  /// process TagNotificationId
210  /// @return always 0 (for extension)
211  ///
212  virtual int processTagNotificationId(
213  int source, ///< source rank
214  int tag ///< TagNotificationId
215  ) = 0;
216 
217  ///
218  /// process TagTerminateRequest
219  /// @return always 0 (for extension)
220  ///
221  virtual int processTagTerminateRequest(
222  int source, ///< source rank
223  int tag ///< TagTerminateRequest
224  ) = 0;
225 
226  ///
227  /// process TagInterruptRequest
228  /// @return always 0 (for extension)
229  ///
230  virtual int processTagInterruptRequest(
231  int source, ///< source rank
232  int tag ///< TagInterruptRequest
233  ) = 0;
234 
235  ///
236  /// process TagWinnerRacingRampUpParamSet
237  /// @return always 0 (for extension)
238  ///
240  int source, ///< source rank
241  int tag ///< TagWinnerRacingRampUpParamSet
242  )
243  {
244  std::cout << "*** virtual function ParaSolver::processTagWinnerRacingRampUpParamSet is called ***" << std::endl;
245  return 0;
246  }
247 
248  ///
249  /// process TagWinner
250  /// @return always 0 (for extension)
251  ///
252  virtual int processTagWinner(
253  int source, ///< source rank
254  int tag ///< TagWinner
255  )
256  {
257  std::cout << "*** virtual function ParaSolver::processTagWinner is called ***" << std::endl;
258  return 0;
259  }
260 
261  ///
262  /// process TagToken
263  /// @return always 0 (for extension)
264  ///
265  virtual int processTagToken(
266  int source, ///< source rank
267  int tag ///< TagToken
268  )
269  {
270  std::cout << "*** virtual function ParaSolver::processTagToken is called ***" << std::endl;
271  return 0;
272  }
273 
274  ///
275  /// wait for receiving a new task and reactivate solver
276  /// @return true if a new task is received, false esle
277  ///
278  virtual bool receiveNewTaskAndReactivate(
279  ) = 0;
280 
281  ///
282  /// wait notification id message to synchronized with LoadCoordinator
283  ///
284  virtual void waitNotificationIdMessage(
285  ) = 0;
286 
287  ///
288  /// wait ack completion to synchronized with LoadCoordinator
289  ///
290  virtual void waitAckCompletion(
291  ) = 0;
292 
293  ///
294  /// restart racing
295  ///
296 // void restartRacing(
297 // );
298 
299  ///
300  /// send completion of calculation
301  ///
302  virtual void sendCompletionOfCalculation(
303  double stopTime ///< stopping time
304  ) = 0;
305 
306  ///
307  /// update global best incumbent solution
308  /// @return true if the best incumbent solution was updated, false otherwise
309  ///
311  ParaSolution *sol ///< pointer to new solution object
312  )
313  {
314  std::cout << "*** virtual function ParaSolver::updateGlobalBestIncumbentSolution is called ***" << std::endl;
315  return false;
316  }
317 
318  ///
319  /// update global best incumbent value
320  /// @return true if the best incumbent value was updated, false otherwise
321  ///
323  double newValue ///< new incumbent value
324  )
325  {
326  std::cout << "*** virtual function ParaSolver::updateGlobalBestIncumbentValue is called ***" << std::endl;
327  return false;
328  }
329 
330  ///
331  /// set racing parameters
332  ///
333  virtual void setRacingParams(
334  ParaRacingRampUpParamSet *racingParms, ///< pointer to racing parameter set object
335  bool winnerParam ///< indicate if the parameter set is winner one
336  )
337  {
338  std::cout << "*** virtual function ParaSolver::setRacingParams is called ***" << std::endl;
339  }
340 
341  ///
342  /// set winner racing parameters
343  ///
344  virtual void setWinnerRacingParams(
345  ParaRacingRampUpParamSet *racingParms ///< pointer to winner racing parameter set object
346  )
347  {
348  std::cout << "*** virtual function ParaSolver::setWinnerRacingParams is called ***" << std::endl;
349  }
350 
351  ///
352  /// create subproblem
353  ///
354  virtual void createSubproblem(
355  )
356  {
357  std::cout << "*** virtual function ParaSolver::createSubproblem is called ***" << std::endl;
358  }
359 
360  ///
361  /// free subproblem
362  ///
363  virtual void freeSubproblem(
364  )
365  {
366  std::cout << "*** virtual function ParaSolver::freeSubproblem is called ***" << std::endl;
367  }
368 
369  ///
370  /// solve (sub)problem
371  ///
372  virtual void solve(
373  ) = 0;
374 
375  ///
376  /// re-initialized instance
377  ///
378  virtual void reinitialize(
379  )
380  {
381  std::cout << "*** virtual function ParaSolver::reinitializeInstance is called ***" << std::endl;
382  }
383 
384 public:
385 
386  ///
387  /// constructor
388  ///
390  )
391  {
392  THROW_LOGICAL_ERROR1("Default constructor of ParaSolver is called");
393  }
394 
395  ///
396  /// constructor
397  ///
398  ParaSolver(
399  int argc, ///< number of arguments
400  char **argv, ///< array of arguments
401  int nHandlers, ///< number of valid message handlers
402  ParaComm *comm, ///< communicator used
403  ParaParamSet *inParaParamSet, ///< pointer to ParaParamSet object
404  ParaInstance *paraInstance, ///< pointer to ParaInstance object
405  ParaDeterministicTimer *detTimer ///< pointer to deterministic timer object
406  );
407 
408  ///
409  /// destructor
410  ///
411  virtual ~ParaSolver(
412  );
413 
414  ///
415  /// get paraParaComm
416  /// @return communicator used
417  ///
419  )
420  {
421  return paraComm;
422  }
423 
424  ///
425  /// check if current execution is warm start (restart) or not
426  /// @return true if the execution is warm start (restart), false otherwise
427  ///
429  )
430  {
431  return warmStarted;
432  }
433 
434  ///
435  /// run this Solver
436  ///
437  virtual void run(
438  ) = 0;
439 
440  ///
441  /// run this Solver with ParaTask object
442  ///
443  virtual void run(
444  ParaTask *paraTask ///< pointer to ParaTask object
445  )
446  {
447  currentTask = paraTask;
448  run();
449  }
450 
451  ///
452  /// run this solver with racing parameters
453  ///
454  virtual void run(
455  ParaRacingRampUpParamSet *inRacingRampUpParamSet ///< pointer to ParaRacingRampUpParamSet object
456  )
457  {
458  std::cout << "*** virtual function ParaSolver::run(araRacingRampUpParamSet *) is called ***" << std::endl;
459 
460  // Example code is below:
461  //----------------------------------------------------------------
462  // ParaTask *rootTask = paraComm->createParaTask();
463  // PARA_COMM_CALL(
464  // rootTask->bcast(paraComm, 0)
465  // );
466  // nParaTasksReceived++;
467  // racingParams = inRacingRampUpParamSet;
468  // setRacingParams(racingParams, false);
469  // if( paraParams->getBoolParamValue(Deterministic) )
470  // {
471  // do
472  // {
473  // iReceiveMessages();
474  // } while( !waitToken(paraComm->getRank()) );
475  // }
476  // iReceiveMessages(); // Feasible solution may be received.
477  // if( paraParams->getBoolParamValue(Deterministic) )
478  // {
479  // passToken(paraComm->getRank());
480  // }
481  // run( rootTask );
482 
483  }
484 
485  ///
486  /// the following functions may be called from callback routines of the target Solver
487  ///
488 
489  ///
490  /// get elapsed time of task solving
491  /// @return elapsed time
492  ///
494  )
495  {
496  return (paraTimer->getElapsedTime() - paraTaskStartTime);
497  }
498 
499  ///
500  /// non-blocking receive messages
501  ///
502  virtual void iReceiveMessages(
503  ) = 0;
504 
505  ///
506  /// check if this solver is ramp-up or not
507  /// @return true if ramp-upped, false otherwise
508  ///
509  bool isRampUp(
510  )
511  {
512  return rampUp;
513  }
514 
515  ///
516  /// check if this solver is in racing ramp-up or not
517  /// @return true if this solver is in racing ramp-up, false otherwise
518  ///
519 // bool isRacingRampUp(
520 // )
521 // {
522 // return ( ( paraParams->getIntParamValue(RampUpPhaseProcess) == 1 ) ||
523 // ( paraParams->getIntParamValue(RampUpPhaseProcess) == 2 ) );
524 // }
525 
526  ///
527  /// check if this solver is the racing winner or not
528  /// @return true if this solver is the racing winner, false otherwise
529  ///
531  )
532  {
533  return racingWinner;
534  }
535 
536  ///
537  /// send improved solution if it was found in this Solver
538  ///
540  ParaSolution *sol ///< solution found in this Solver
541  )
542  {
543  std::cout << "*** virtual function ParaSolver::sendIfImprovedSolutionWasFound is called ***" << std::endl;
544  return false;
545  }
546 
547  ///
548  /// save improved solution if it was found in this Solver
549  ///
551  ParaSolution *sol ///< solution found in this Solver
552  )
553  {
554  std::cout << "*** virtual function ParaSolver::saveIfImprovedSolutionWasFound is called ***" << std::endl;
555  return false;
556  }
557 
558  ///
559  /// send solution found in this Solver
560  ///
561  virtual void sendLocalSolution(
562  )
563  {
564  std::cout << "*** virtual function ParaSolver::sendLocalSolution is called ***" << std::endl;
565  }
566 
567  ///
568  /// check if a notification message needs to send or not
569  /// TODO: function name should be isNotificationNecessary
570  /// @return true if the notification message needs to send, false otherwise
571  ///
572  virtual bool notificationIsNecessary(
573  ) = 0;
574 
575  ///
576  /// check if Solver is in interrupting phase or not
577  /// @return true if Solver is in interrupting phase, false otherwise
578  ///
580  )
581  {
582  return ( terminationMode == InterruptedTerminationMode );
583  }
584 
585  ///
586  /// check if termination was requested or not
587  /// @return true if termination was requested, false otherwise
588  ///
590  )
591  {
592  return ( terminationMode == NormalTerminationMode );
593  }
594 
595  ///
596  /// check if a new ParaTask was received or not
597  /// @return true if a new ParaTask was received, false otherwise
598  ///
600  )
601  {
602  return (newTask != 0);
603  }
604 
605  ///
606  /// check if Solver is in notification process or not
607  /// TODO: function name should be changed
608  /// @return true if Solver is in notification process, false otherwise
609  ///
611  )
612  {
613  return notificationProcessed;
614  }
615 
616  ///
617  /// get current ParaTask object
618  /// @return pointer to ParaTask object
619  ///
621  )
622  {
623  return currentTask;
624  }
625 
626  ///
627  /// get ParaInstance object
628  /// @return pointer to ParaInstance object
629  ///
631  )
632  {
633  return paraInstance;
634  }
635 
636  ///
637  /// get ParaParamSet object
638  /// @return pointer to ParaParamSet object
639  ///
641  )
642  {
643  return paraParams;
644  }
645 
646  ///
647  /// get rank of this Solver
648  /// @return rank of this Solver
649  ///
650  virtual int getRank(
651  )
652  {
653  return paraComm->getRank();
654  }
655 
656  ///
657  /// wait a notification id message if it is needed to synchronize with LoadCoordinaor
658  ///
659  virtual void waitMessageIfNecessary(
660  ) = 0;
661 
662  ///
663  /// check if Solver is in racing stage or not
664  /// @return true if Solver is in racing stage, false otherwise
665  ///
666 // bool isRacingStage(
667 // )
668 // {
669 // return (racingParams &&
670 // (paraParams->getIntParamValue(RampUpPhaseProcess) == 1 ||
671 // paraParams->getIntParamValue(RampUpPhaseProcess) == 2 ) );
672 // }
673 
674  ///
675  /// terminate racing stage
676  ///
678  {
679  assert(racingParams);
680  delete racingParams;
681  racingParams = 0;
682  racingInterruptIsRequested = false;
683  racingIsInterrupted = false; // rampUp message might have been received before terminate racing
684  // Then, this flag should be set false
685  }
686 
687  ///
688  /// get global best incumbent solution
689  /// @return pointer to ParaSolution object
690  ///
692  )
693  {
695  }
696 
697  ///
698  /// check if Solver is waiting for a specific message or not
699  /// @return true if Solver is waiting for a specific message, false otherwise
700  ///
702  )
703  {
704  return waitingSpecificMessage;
705  }
706 
707  ///
708  /// wait token for deterministic mode
709  /// @return true when token is received, false otherwise
710  ///
711  virtual bool waitToken(
712  int rank ///< rank of this Solver
713  )
714  {
715  std::cout << "*** virtual function ParaSolver::waitToken is called ***" << std::endl;
716  return false;
717 // bool result;
718 // double startTimeToWaitToken = paraTimer->getElapsedTime();
719 // result = paraComm->waitToken(rank);
720 // idleTimeToWaitToken += (paraTimer->getElapsedTime() - startTimeToWaitToken);
721 // return result;
722  }
723 
724  ///
725  /// pass token to the next process
726  ///
727  virtual void passToken(
728  int rank ///< rank of this Solver
729  )
730  {
731  std::cout << "*** virtual function ParaSolver::passToken is called ***" << std::endl;
732 // paraComm->passToken(rank);
733  }
734 
735  ///
736  /// get deterministic timer object
737  /// @return pointer to deterministic timer object
738  ///
740  )
741  {
742  return paraDetTimer;
743  }
744 
745  ///
746  /// get offset time to wait token
747  /// @return offset time
748  ///
750  )
751  {
752  return offsetTimeToWaitToken;
753  }
754 
755  ///
756  /// update pending solution
757  /// @note there is a case that solution cannot updated immediately for some timing issue
758  ///
759  virtual void updatePendingSolution(
760  )
761  {
762  if( updatePendingSolutionIsProceeding == false )
763  {
764  updatePendingSolutionIsProceeding = true;
765  if( !pendingSolution )
766  {
767  updateGlobalBestIncumbentValue(pendingIncumbentValue);
768  pendingIncumbentValue = DBL_MAX;
769  updatePendingSolutionIsProceeding = false;
770  return;
771  }
772  if( updateGlobalBestIncumbentSolution(pendingSolution) )
773  {
774  tryNewSolution(pendingSolution);
775  }
776  else
777  {
778  delete pendingSolution;
779  }
780  pendingIncumbentValue = DBL_MAX;
781  pendingSolution = 0;
782  updatePendingSolutionIsProceeding = false;
783  }
784  }
785 
786  ///
787  /// check if Solver was terminated normally or not
788  /// @return true if Solver was terminated normally, false otherwise
789  ///
790  virtual bool wasTerminatedNormally(
791  ) = 0;
792 
793  ///
794  /// write current task problem
795  /// (this method is always useful for debugging, so we should implement this method)
796  ///
797  virtual void writeCurrentTaskProblem(
798  const std::string& filename ///< file name to write
799  ) = 0;
800 
801  ///
802  /// try to enter solution to base solver environment
803  ///
804  virtual void tryNewSolution(
805  ParaSolution *sol ///< solution to be enterred
806  ) = 0;
807 
808  ///
809  /// write subproblem
810  ///
811  virtual void writeSubproblem(
812  ) = 0;
813 
814  ///
815  /// set previous communication time for deterministic execution
816  ///
818  double detTime ///< deterministic time
819  )
820  {
821  previousCommTime = detTime;
822  }
823 
824  ///
825  /// get previous communication time for deterministic execution
826  /// @return previous communication time in deterministic time
827  ///
829  )
830  {
831  return previousCommTime;
832  }
833 
834  ///
835  /// set termination mode
836  ///
838  int tm ///< terminiation mode to be set
839  )
840  {
841  terminationMode = tm;
842  }
843 
844  ///
845  /// get termination mode
846  /// @return termination mode
847  ///
849  )
850  {
851  return terminationMode;
852  }
853 
854 };
855 
856 }
857 
858 #endif // __PARA_SOLVER_H__
ParaParamSet * getParaParamSet()
get ParaParamSet object
Definition: paraSolver.h:640
virtual void writeCurrentTaskProblem(const std::string &filename)=0
write current task problem (this method is always useful for debugging, so we should implement this m...
ParaSolver()
constructor
Definition: paraSolver.h:389
virtual bool sendIfImprovedSolutionWasFound(ParaSolution *sol)
send improved solution if it was found in this Solver
Definition: paraSolver.h:539
bool notificationProcessed
if true, notification is issued but not receive the corresponding LCB
Definition: paraSolver.h:140
int nImprovedIncumbent
Counters related to the current ParaTask.
Definition: paraSolver.h:130
double idleTimeToFirstParaTask
idle time to start solving the first ParaTask
Definition: paraSolver.h:118
virtual int processTagTaskReceived(int source, int tag)=0
process TagTaskReceived
virtual void createSubproblem()
create subproblem
Definition: paraSolver.h:354
static ScipParaCommTh * comm
Definition: fscip.cpp:73
ParaSolution * pendingSolution
solution which is pending to update in case of deterministic runs
Definition: paraSolver.h:94
bool stayAliveAfterInterrupt
indicate that stay alive this solver after interrupt request
Definition: paraSolver.h:149
bool memoryLimitIsReached
indicate if memory limit is reached or not, when base solver has memory management feature ...
Definition: paraSolver.h:109
virtual void setRacingParams(ParaRacingRampUpParamSet *racingParms, bool winnerParam)
set racing parameters
Definition: paraSolver.h:333
virtual void sendLocalSolution()
send solution found in this Solver
Definition: paraSolver.h:561
bool racingInterruptIsRequested
indicate a racing interrupt is requested
Definition: paraSolver.h:105
void terminateRacing()
check if Solver is in racing stage or not
Definition: paraSolver.h:677
virtual double getElapsedTime()=0
get elapsed time
int nParaTasksSolved
number of ParaTasks solved ( received ) in this ParaSolver
Definition: paraSolver.h:136
ParaParamSet * paraParams
ParaParamSet object.
Definition: paraSolver.h:83
virtual int getRank()
get rank of this Solver
Definition: paraSolver.h:650
virtual bool updateGlobalBestIncumbentSolution(ParaSolution *sol)
update global best incumbent solution
Definition: paraSolver.h:310
static const int NormalTerminationMode
Definition: paraSolver.h:61
Base class for ParaTask.
static const int InterruptedTerminationMode
Definition: paraSolver.h:62
virtual void sendCompletionOfCalculation(double stopTime)=0
restart racing
virtual int processTagInterruptRequest(int source, int tag)=0
process TagInterruptRequest
double globalBestIncumbentValue
global best incumbent value
Definition: paraSolver.h:91
virtual bool waitToken(int rank)
wait token for deterministic mode
Definition: paraSolver.h:711
static const int UgBaseTerminationModeLast
Definition: paraSolver.h:65
ParaRacingRampUpParamSet * racingParams
ParaRacingRampUpParamSet object. This is also a flag to indicate running with racing ramp-up...
Definition: paraSolver.h:84
ParaDeterministicTimer * paraDetTimer
deterministic timer for this ParaSolver
Definition: paraSolver.h:89
double previousIdleTimeToWaitToken
previous idle time to wait token
Definition: paraSolver.h:124
Base class for deterministic timer.
ParaComm * getParaComm()
get paraParaComm
Definition: paraSolver.h:418
virtual int processTagNotificationId(int source, int tag)=0
process TagNotificationId
Defines for UG Framework.
virtual bool updateGlobalBestIncumbentValue(double newValue)
update global best incumbent value
Definition: paraSolver.h:322
virtual int processTagWinnerRacingRampUpParamSet(int source, int tag)
process TagWinnerRacingRampUpParamSet
Definition: paraSolver.h:239
bool subproblemFreed
indicate that subproblem is already freed or not
Definition: paraSolver.h:147
double pendingIncumbentValue
incumbent value which is pending to update in case of deterministic runs
Definition: paraSolver.h:95
ParaDeterministicTimer * getDeterministicTimer()
get deterministic timer object
Definition: paraSolver.h:739
static const int TimeLimitTerminationMode
Definition: paraSolver.h:63
class for deterministic timer
double getOffsetTimeToWaitToken()
get offset time to wait token
Definition: paraSolver.h:749
ParaSolution * localIncumbentSolution
incumbent solution generated in local solver
Definition: paraSolver.h:93
virtual void waitAckCompletion()=0
wait ack completion to synchronized with LoadCoordinator
virtual void freeSubproblem()
free subproblem
Definition: paraSolver.h:363
virtual int getRank()=0
get rank of this process or this thread depending on run-time environment
Base class for Timer.
virtual void run()=0
run this Solver
bool isTerminationRequested()
check if termination was requested or not
Definition: paraSolver.h:589
virtual ~ParaSolver()
destructor
Definition: paraSolver.cpp:153
bool rampUp
indicate whether if ramp-up phase is finished or not: true - finish
Definition: paraSolver.h:104
virtual int processTagIncumbentValue(int source, int tag)
process TagIncumbentValue
Definition: paraSolver.h:199
double getElapsedTimeOfTaskSolving()
the following functions may be called from callback routines of the target Solver ...
Definition: paraSolver.h:493
virtual void run(ParaTask *paraTask)
run this Solver with ParaTask object
Definition: paraSolver.h:443
int nHandlers
number of valid message handlers
Definition: paraSolver.h:77
bool waitingSpecificMessage
indicate that this solver is waiting for a specific message
Definition: paraSolver.h:108
void setTerminationMode(int tm)
set termination mode
Definition: paraSolver.h:837
bool isRacingWinner()
check if this solver is in racing ramp-up or not
Definition: paraSolver.h:530
int nParaTasksReceived
Counters related to this ParaSolver.
Definition: paraSolver.h:135
Parameter set for UG framework.
virtual int processTagRampUp(int source, int tag)
process TagRampUp
Definition: paraSolver.h:177
double previousStopTime
Idle Times.
Definition: paraSolver.h:117
double idleTimeAfterLastParaTask
idle time after the last ParaTask was solved
Definition: paraSolver.h:120
#define THROW_LOGICAL_ERROR1(msg1)
Definition: paraDef.h:52
int terminationMode
indicate that termination mode 0: no termination mode 1: normal termination mode 2: interrupted termi...
Definition: paraSolver.h:99
Base class of communicator for UG Framework.
ParaTimer * paraTimer
timer for this ParaSolver
Definition: paraSolver.h:88
Base class for racing ramp-up parameter set.
double getPreviousCommTime()
get previous communication time for deterministic execution
Definition: paraSolver.h:828
double eps
absolute values smaller than this are considered zero esp should be set in the constructor of the der...
Definition: paraSolver.h:142
bool getNotificaionProcessed()
check if Solver is in notification process or not TODO: function name should be changed ...
Definition: paraSolver.h:610
double previousCommTime
previous communication time for deterministic execution
Definition: paraSolver.h:145
void setPreviousCommTime(double detTime)
set previous communication time for deterministic execution
Definition: paraSolver.h:817
virtual void setWinnerRacingParams(ParaRacingRampUpParamSet *racingParms)
set winner racing parameters
Definition: paraSolver.h:344
class ParaParamSet
Definition: paraParamSet.h:850
ParaTask * getCurrentTask()
get current ParaTask object
Definition: paraSolver.h:620
virtual bool wasTerminatedNormally()=0
check if Solver was terminated normally or not
class for instance data
Definition: paraInstance.h:50
bool globalIncumbnetValueUpdateFlag
indicate that global incumbent value is updated in iReceiveMessages() routine
Definition: paraSolver.h:139
ParaSolution * globalBestIncumbentSolution
global best solution. However, this is not always feasible for the current sub-MIP ...
Definition: paraSolver.h:92
double idleTimeBetweenParaTasks
idle time between ParaTasks processing
Definition: paraSolver.h:119
virtual void writeSubproblem()=0
write subproblem
virtual bool receiveNewTaskAndReactivate()=0
wait for receiving a new task and reactivate solver
virtual int processTagTerminateRequest(int source, int tag)=0
process TagTerminateRequest
ParaTask * currentTask
solving task
Definition: paraSolver.h:97
virtual int processTagSolution(int source, int tag)=0
process TagSolution
double offsetTimeToWaitToken
offset time to wait token
Definition: paraSolver.h:125
bool isRampUp()
check if this solver is ramp-up or not
Definition: paraSolver.h:509
double idleTimeToWaitToken
idle time to wait token
Definition: paraSolver.h:123
static const int NoTerminationMode
termination mode
Definition: paraSolver.h:60
virtual bool saveIfImprovedSolutionWasFound(ParaSolution *sol)
save improved solution if it was found in this Solver
Definition: paraSolver.h:550
virtual void updatePendingSolution()
update pending solution
Definition: paraSolver.h:759
virtual void waitMessageIfNecessary()=0
wait a notification id message if it is needed to synchronize with LoadCoordinaor ...
bool updatePendingSolutionIsProceeding
update pending solution process is proceeding
Definition: paraSolver.h:138
bool isInterrupting()
check if Solver is in interrupting phase or not
Definition: paraSolver.h:579
double idleTimeToWaitNotificationId
idle time to wait a message within collecting mode
Definition: paraSolver.h:121
ParaRacingRampUpParamSet * winnerRacingParams
Winner ParaRacingRampUpParamSet object.
Definition: paraSolver.h:86
bool racingIsInterrupted
indicate whether if racing phases is interrupted or not: true - interrupted
Definition: paraSolver.h:106
double paraTaskStartTime
start time of current ParaTask
Definition: paraSolver.h:112
bool newParaTaskExists()
check if a new ParaTask was received or not
Definition: paraSolver.h:599
virtual void reinitialize()
re-initialized instance
Definition: paraSolver.h:378
virtual void waitNotificationIdMessage()=0
wait notification id message to synchronized with LoadCoordinator
bool warmStarted
indicate whether if system is warm started or not
Definition: paraSolver.h:103
unsigned int notificationIdGenerator
Definition: paraSolver.h:80
ParaTask * newTask
new task to solve
Definition: paraSolver.h:98
double previousNotificationTime
previous notification time
Definition: paraSolver.h:111
bool isWarmStarted()
check if current execution is warm start (restart) or not
Definition: paraSolver.h:428
ParaInstance * paraInstance
root problem instance
Definition: paraSolver.h:96
bool isWaitingForSpecificMessage()
check if Solver is waiting for a specific message or not
Definition: paraSolver.h:701
virtual void iReceiveMessages()=0
non-blocking receive messages
ParaComm * paraComm
ParaCommunicator object.
Definition: paraSolver.h:82
class ParaTimer
Definition: paraTimer.h:48
class ParaRacingRampUpParamSet (parameter set for racing ramp-up)
virtual bool notificationIsNecessary()=0
check if a notification message needs to send or not TODO: function name should be isNotificationNece...
virtual void passToken(int rank)
pass token to the next process
Definition: paraSolver.h:727
MessageHandlerFunctionPointer * messageHandler
table for message handlers
Definition: paraSolver.h:78
int(ParaSolver::* MessageHandlerFunctionPointer)(int, int)
Definition: paraSolver.h:75
virtual void run(ParaRacingRampUpParamSet *inRacingRampUpParamSet)
run this solver with racing parameters
Definition: paraSolver.h:454
class ParaSolver
Definition: paraSolver.h:70
virtual int processTagToken(int source, int tag)
process TagToken
Definition: paraSolver.h:265
virtual int processTagWinner(int source, int tag)
process TagWinner
Definition: paraSolver.h:252
ParaInstance * getParaInstance()
get ParaInstance object
Definition: paraSolver.h:630
Base class of communicator object.
Definition: paraComm.h:101
bool racingWinner
indicate racing ramp-up winner or not: true - winner
Definition: paraSolver.h:107
virtual void solve()=0
solve (sub)problem
class for solution
Definition: paraSolution.h:53
double idleTimeToWaitAckCompletion
idle time to wait acknowledgment of completion
Definition: paraSolver.h:122
Base class for solution.
int getTerminationMode()
get termination mode
Definition: paraSolver.h:848
virtual int processTagTask(int source, int tag)=0
Message handlers
class ParaTask
Definition: paraTask.h:541
virtual void tryNewSolution(ParaSolution *sol)=0
try to enter solution to base solver environment
ParaSolution * getGlobalBestIncumbentSolution()
get global best incumbent solution
Definition: paraSolver.h:691