Scippy

UG

Ubiquity Generator framework

paraSolver.cpp
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-2024 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.cpp
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#include <cstdlib>
38#include <cfloat>
39#include <climits>
40#include <cassert>
41#include <cstring>
42#include <algorithm>
43#include "paraComm.h"
44#include "paraTask.h"
45#include "paraInstance.h"
46#include "paraSolver.h"
47#include "paraSolution.h"
50#include "paraSolverState.h"
51#ifdef _COMM_PTH
52#include "paraCommPth.h"
53#endif
54#ifdef _COMM_CPP11
55#include "paraCommCPP11.h"
56#endif
57
58using namespace UG;
59
60ParaSolver::ParaSolver(
61 int argc,
62 char **argv,
63 int inNHandlers,
65 ParaParamSet *inParaParamSet,
66 ParaInstance *inParaInstance,
67 ParaDeterministicTimer *inParaDetTimer
68 )
69 : nHandlers(inNHandlers),
70 messageHandler(0),
71 notificationIdGenerator(0),
72 paraComm(comm),
73 paraParams(inParaParamSet),
74 racingParams(0),
75 winnerRacingParams(0),
76 paraDetTimer(inParaDetTimer),
77 globalBestIncumbentValue(DBL_MAX),
78 globalBestIncumbentSolution(0),
79 localIncumbentSolution(0),
80 pendingSolution(0),
81 pendingIncumbentValue(DBL_MAX),
82 paraInstance(inParaInstance),
83 currentTask(0),
84 newTask(0),
85 terminationMode(NoTerminationMode),
86 warmStarted(false),
87 rampUp(false),
88 racingInterruptIsRequested(false),
89 racingIsInterrupted(false),
90 racingWinner(false),
91 waitingSpecificMessage(false),
92 memoryLimitIsReached(false),
93 previousNotificationTime(0.0),
94 paraTaskStartTime(0.0),
95 previousStopTime(-DBL_MAX),
96 idleTimeToFirstParaTask(0.0),
97 idleTimeBetweenParaTasks(0.0),
98 idleTimeAfterLastParaTask(0.0),
99 idleTimeToWaitNotificationId(0.0),
100 idleTimeToWaitAckCompletion(0.0), idleTimeToWaitToken(0.0), previousIdleTimeToWaitToken(0.0), offsetTimeToWaitToken(0.0),
101 nImprovedIncumbent(0),
102 nParaTasksReceived(0),
103 nParaTasksSolved(0),
104 updatePendingSolutionIsProceeding(false),
105 globalIncumbnetValueUpdateFlag(false),
106 notificationProcessed(false),
108 previousCommTime(0.0),
109 subproblemFreed(false),
110 stayAliveAfterInterrupt(false)
111{
112 if( paraComm )
113 {
114 /** create timer for this ParaSolver */
118 {
119 assert(paraDetTimer);
120 }
121
123 ///
124 /// register message handlers
125 ///
126 for( int i = 0; i < nHandlers; i++ )
127 {
128 messageHandler[i] = 0;
129 }
139
141 * (paraComm->getRank() - 1);
142
143 for(int i = 0; i < argc; i++ )
144 {
145 if( strcmp(argv[i], "-w") == 0 )
146 {
147 warmStarted = true;
148 }
149 }
150 }
151}
152
154 )
155{
156 if(racingParams) delete racingParams;
160 if(currentTask) delete currentTask;
161 if(newTask) delete newTask;
162
163 delete paraTimer;
164
165 if( paraInstance ) delete paraInstance;
166
167 delete [] messageHandler;
168}
Base class of communicator object.
Definition: paraComm.h:102
virtual ParaTimer * createParaTimer()=0
create ParaTimer object
virtual int getSize()=0
get number of UG processes or UG threads depending on run-time environment
virtual int getRank()=0
get rank of this process or this thread depending on run-time environment
class for deterministic timer
class for instance data
Definition: paraInstance.h:51
class ParaParamSet
Definition: paraParamSet.h:850
bool getBoolParamValue(int param)
get bool parameter value
double getRealParamValue(int param)
get real parameter value
virtual int processTagNotificationId(int source, int tag)=0
process TagNotificationId
ParaParamSet * paraParams
ParaParamSet object.
Definition: paraSolver.h:83
ParaComm * paraComm
ParaCommunicator object.
Definition: paraSolver.h:82
ParaTask * currentTask
solving task
Definition: paraSolver.h:97
double offsetTimeToWaitToken
offset time to wait token
Definition: paraSolver.h:125
virtual int processTagWinner(int source, int tag)
process TagWinner
Definition: paraSolver.h:252
virtual int processTagTerminateRequest(int source, int tag)=0
process TagTerminateRequest
ParaSolution * globalBestIncumbentSolution
global best solution. However, this is not always feasible for the current sub-MIP
Definition: paraSolver.h:92
virtual int processTagRampUp(int source, int tag)
process TagRampUp
Definition: paraSolver.h:177
ParaRacingRampUpParamSet * winnerRacingParams
Winner ParaRacingRampUpParamSet object.
Definition: paraSolver.h:86
bool warmStarted
indicate whether if system is warm started or not
Definition: paraSolver.h:103
virtual int processTagSolution(int source, int tag)=0
process TagSolution
ParaSolution * localIncumbentSolution
incumbent solution generated in local solver
Definition: paraSolver.h:93
int(ParaSolver::* MessageHandlerFunctionPointer)(int, int)
Definition: paraSolver.h:75
ParaTimer * paraTimer
timer for this ParaSolver
Definition: paraSolver.h:88
virtual int processTagIncumbentValue(int source, int tag)
process TagIncumbentValue
Definition: paraSolver.h:199
virtual int processTagTaskReceived(int source, int tag)=0
process TagTaskReceived
ParaRacingRampUpParamSet * racingParams
ParaRacingRampUpParamSet object. This is also a flag to indicate running with racing ramp-up.
Definition: paraSolver.h:84
virtual int processTagWinnerRacingRampUpParamSet(int source, int tag)
process TagWinnerRacingRampUpParamSet
Definition: paraSolver.h:239
virtual int processTagToken(int source, int tag)
process TagToken
Definition: paraSolver.h:265
ParaTask * newTask
new task to solve
Definition: paraSolver.h:98
virtual ~ParaSolver()
destructor
Definition: paraSolver.cpp:153
ParaDeterministicTimer * paraDetTimer
deterministic timer for this ParaSolver
Definition: paraSolver.h:89
int nHandlers
number of valid message handlers
Definition: paraSolver.h:77
MessageHandlerFunctionPointer * messageHandler
table for message handlers
Definition: paraSolver.h:78
ParaInstance * paraInstance
root problem instance
Definition: paraSolver.h:96
virtual void init(ParaComm *paraComm)=0
initialize timer
static ScipParaCommTh * comm
Definition: fscip.cpp:73
static const int TagWinner
Definition: paraTagDef.h:60
static const int TagSolution
Definition: paraTagDef.h:51
static const int TagToken
Definition: paraTagDef.h:63
static const int TagTaskReceived
Definition: paraTagDef.h:48
static const double eps
static const int NotificationInterval
Definition: paraParamSet.h:105
static const int TagNotificationId
Definition: paraTagDef.h:55
static const int NoTerminationMode
termination mode
Definition: paraSolver.h:60
static const int TagIncumbentValue
Definition: paraTagDef.h:52
static const int TagTerminateRequest
Definition: paraTagDef.h:56
static const int TagRampUp
Definition: paraTagDef.h:50
static const int Deterministic
Definition: paraParamSet.h:76
static const int TagRacingRampUpParamSet
Definition: paraTagDef.h:59
Base class for calculation state.
ParaComm extension for C++11 thread communication.
ParaComm extension for Pthreads communication.
Base class of communicator for UG Framework.
#define MINEPSILON
Definition: paraDef.h:50
Base class for instance data.
Base class for solution.
This class has solver state to be transferred.
This class contains solver termination state which is transferred form Solver to LC.
Base class for solver: Generic parallelized solver.
Base class for ParaTask.