Scippy

UG

Ubiquity Generator framework

bbParaCommMpi.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-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 bbParaCommMpi.h
27 * @brief ParaComm extension for MPI communication.
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 __BB_PARA_COMM_MPI_H__
38#define __BB_PARA_COMM_MPI_H__
39
40#ifdef _MUTEX_CPP11
41#include <thread>
42#include <mutex>
43#endif
44#include <mpi.h>
45#include <stdexcept>
46#include <iostream>
47#include <ostream>
48#include <fstream>
49#include <sstream>
50#include <string>
51#include <iomanip>
52#include "ug/paraDef.h"
53#include "ug/paraCommMpi.h"
54#include "ug/paraInstance.h"
56#include "ug/paraSolution.h"
57#include "ug/paraParamSetMpi.h"
59#include "bbParaNodeMpi.h"
62#include "ug/paraTimerMpi.h"
63
64#include "bbParaTagDef.h"
65
66#ifdef UG_WITH_UGS
67#include "ugs/ugsParaCommMpi.h"
68#endif
69
70namespace UG
71{
72
73///
74/// Communicator object for MPI communications
75///
77{
78protected:
79 static MPI_Datatype datatypes[TYPE_LIST_SIZE]; ///< data type mapping table to MPI data type
80 static const char *tagStringTable[]; ///< table for tag name string
81
82#ifdef _MUTEX_CPP11
83 std::mutex tokenAccessLock; ///< mutex for c++11 thread
84#else
85 pthread_mutex_t tokenAccessLock; ///< mutex for pthread thread
86#endif
87
88#ifdef UG_WITH_UGS
89 UGS::UgsParaCommMpi *commUgs; ///< communicator for UGS
90#endif
91
92 ///
93 /// check if tag string table (for debugging) set up correctly
94 /// @return true if tag string table is set up correctly, false otherwise
95 ///
97 );
98
99 ///
100 /// get Tag string for debugging
101 /// @return string which shows Tag
102 ///
103 virtual const char *getTagString(
104 int tag /// tag to be converted to string
105 );
106
107public:
108
109 ///
110 /// default constructor of ParaCommMpi
111 ///
113 )
114 : ParaCommMpi()
115#ifdef UG_WITH_UGS
116 , commUgs(0)
117#endif
118 {
119#ifndef _MUTEX_CPP11
120 pthread_mutex_init(&tokenAccessLock, NULL);
121#endif
122 token[0]=-1;
123 token[1]=-1;
124 }
125
126 ///
127 /// constructor of ParaCommMpi with MPI communicator
128 ///
130 MPI_Comm comm ///< my communicator
131 )
133#ifdef UG_WITH_UGS
134 , commUgs(0)
135#endif
136 {
137 }
138
139 ///
140 /// destructor of this communicator
141 ///
143 )
144 {
145 }
146
147 ///
148 /// create ParaCalculationState object by default constructor
149 /// @return pointer to ParaCalculationState object
150 ///
152 );
153
154 ///
155 /// create ParaCalculationState object
156 /// @return pointer to ParaCalculationState object
157 ///
159 double compTime, ///< computation time of this ParaNode
160 double rootTime, ///< computation time of the root node
161 int nSolved, ///< the number of nodes solved
162 int nSent, ///< the number of ParaNodes sent
163 int nImprovedIncumbent, ///< the number of improved solution generated in this ParaSolver
164 int terminationState, ///< indicate whether if this computation is terminationState or not. 0: no, 1: terminationState
165 int nSolvedWithNoPreprocesses, ///< number of nodes solved when it is solved with no preprocesses
166 int nSimplexIterRoot, ///< number of simplex iteration at root node
167 double averageSimplexIter, ///< average number of simplex iteration except root node
168 int nTransferredLocalCuts, ///< number of local cuts transferred from a ParaNode
169 int minTransferredLocalCuts, ///< minimum number of local cuts transferred from a ParaNode
170 int maxTransferredLocalCuts, ///< maximum number of local cuts transferred from a ParaNode
171 int nTransferredBendersCuts, ///< number of benders cuts transferred from a ParaNode
172 int minTransferredBendersCuts, ///< minimum number of benders cuts transferred from a ParaNode
173 int maxTransferredBendersCuts, ///< maximum number of benders cuts transferred from a ParaNode
174 int nRestarts, ///< number of restarts
175 double minIisum, ///< minimum sum of integer infeasibility
176 double maxIisum, ///< maximum sum of integer infeasibility
177 int minNii, ///< minimum number of integer infeasibility
178 int maxNii, ///< maximum number of integer infeasibility
179 double dualBound, ///< final dual bound value
180 int nSelfSplitNodesLeft ///< number of self-split nodes left
181 );
182
183 ///
184 /// create ParaNode object by default constructor
185 /// @return pointer to ParaNode object
186 ///
187 virtual ParaTask *createParaTask(
188 );
189
190 ///
191 /// create ParaNode object
192 /// @return pointer to ParaNode object
193 ///
194 virtual ParaTask *createParaNode(
195 TaskId inNodeId, ///< node id
196 TaskId inGeneratorNodeId, ///< generator node id
197 int inDepth, ///< node depth in global search tree
198 double inDualBoundValue, ///< dual bound value
199 double inOriginalDualBoundValue, ///< original dual bound value
200 double inEstimatedValue, ///< estimated value
201 ParaDiffSubproblem *inDiffSubproblem ///< diff subproblem info. from the original problem
202 );
203
204 ///
205 /// create ParaSolverState object by default constructor
206 /// @return pointer to ParaSolverState object
207 ///
209 );
210
211 ///
212 /// create ParaSolverState object
213 /// @return pointer to ParaSolverState object
214 ///
216 int racingStage, ///< if this value is 1, solver is in racing stage
217 unsigned int notificationId, ///< id for this notification
218 int lcId, ///< lc id of current ParaNode
219 int globalSubtreeId, ///< global subtree id of current ParaNode
220 long long nodesSolved, ///< number of nodes solved
221 int nodesLeft, ///< number of remaining nodes
222 double bestDualBoundValue, ///< best dual bound value in that of remaining nodes
223 double globalBestPrimalBoundValue, ///< global best primal bound value
224 double detTime, ///< deterministic time, -1: should be non-deterministic
225 double averageDualBoundGain ///< average dual bound gain received
226 );
227
228 ///
229 /// create ParaSolverTerminationState object by default constructor
230 /// @return pointer to ParaSolverTerminationState object
231 ///
233 );
234
235 ///
236 /// create ParaSolverTerminationState object
237 /// @return pointer to ParaSolverTerminationState object
238 ///
240 int interrupted, ///< indicate that this solver is interrupted or not. 0: not interrupted, 1: interrupted
241 ///< 2: checkpoint, 3: racing-ramp up
242 int rank, ///< rank of this solver
243 int totalNSolved, ///< accumulated number of nodes solved in this ParaSolver
244 int minNSolved, ///< minimum number of subtree nodes rooted from ParaNode
245 int maxNSolved, ///< maximum number of subtree nodes rooted from ParaNode
246 int totalNSent, ///< accumulated number of nodes sent from this ParaSolver
247 int totalNImprovedIncumbent, ///< accumulated number of improvements of incumbent value in this ParaSolver
248 int nParaNodesReceived, ///< number of ParaNodes received in this ParaSolver
249 int nParaNodesSolved, ///< number of ParaNodes solved ( received ) in this ParaSolver
250 int nParaNodesSolvedAtRoot, ///< number of ParaNodes solved at root node before sending
251 int nParaNodesSolvedAtPreCheck, ///< number of ParaNodes solved at pre-checking of root node solvability
252 int nTransferredLocalCutsFromSolver, ///< number of local cuts transferred from this Solver
253 int minTransferredLocalCutsFromSolver, ///< minimum number of local cuts transferred from this Solver
254 int maxTransferredLocalCutsFromSolver, ///< maximum number of local cuts transferred from this Solver
255 int nTransferredBendersCutsFromSolver, ///< number of benders cuts transferred from this Solver
256 int minTransferredBendersCutsFromSolver, ///< minimum number of benders cuts transferred from this Solver
257 int maxTransferredBendersCutsFromSolver, ///< maximum number of benders cuts transferred from this Solver
258 int nTotalRestarts, ///< number of total restarts
259 int minRestarts, ///< minimum number of restarts
260 int maxRestarts, ///< maximum number of restarts
261 int nTightened, ///< number of tightened variable bounds during racing stage
262 int nTightenedInt, ///< number of tightened integral variable bounds during racing stage
263 int calcTerminationState, ///< termination sate of a calculation in a Solver
264 double runningTime, ///< this solver running time
265 double idleTimeToFirstParaNode, ///< idle time to start solving the first ParaNode
266 double idleTimeBetweenParaNodes, ///< idle time between ParaNodes processing
267 double iddleTimeAfterLastParaNode, ///< idle time after the last ParaNode was solved
268 double idleTimeToWaitNotificationId, ///< idle time to wait notification Id messages
269 double idleTimeToWaitAckCompletion, ///< idle time to wait ack completion message
270 double idleTimeToWaitToken, ///< idle time to wait token
271 double totalRootNodeTime, ///< total time consumed by root node processes
272 double minRootNodeTime, ///< minimum time consumed by root node processes
273 double maxRootNodeTime, ///< maximum time consumed by root node processes
274 double detTime ///< deterministic time, -1: should be non-deterministic
275 );
276
277 ///
278 /// create ParaRacingRampUpParamSet object by default constructor
279 /// @return pointer to ParaRacingRampUpParamSet object
280 ///
282 )
283 {
284 THROW_LOGICAL_ERROR1("*** createParaRacingRampUpParamSet() is called in BbParaComm class ***");
285 }
286
287};
288
289#define DEF_BB_PARA_COMM( para_comm, comm ) UG::BbParaCommMpi *para_comm = dynamic_cast< UG::BbParaCommMpi* >(comm)
290
291}
292
293#endif // __BB_PARA_COMM_MPI_H__
CalcutationStte object extension for MPI communication.
BbParaNode extension for MIP communication.
BbParaSolverState extension for MPI communication.
BbParaSolverTerminationState extension for MIP communication.
ug_bb Tag definitions
Communicator object for MPI communications.
Definition: bbParaCommMpi.h:77
virtual ParaCalculationState * createParaCalculationState()
create ParaCalculationState object by default constructor
virtual ParaSolverState * createParaSolverState()
create ParaSolverState object by default constructor
virtual ParaTask * createParaTask()
create ParaNode object by default constructor
static MPI_Datatype datatypes[TYPE_LIST_SIZE]
data type mapping table to MPI data type
Definition: bbParaCommMpi.h:79
virtual bool tagStringTableIsSetUpCoorectly()
check if tag string table (for debugging) set up correctly
virtual ParaSolverTerminationState * createParaSolverTerminationState()
create ParaSolverTerminationState object by default constructor
virtual ParaRacingRampUpParamSet * createParaRacingRampUpParamSet()
create ParaRacingRampUpParamSet object by default constructor
virtual ParaTask * createParaNode(TaskId inNodeId, TaskId inGeneratorNodeId, int inDepth, double inDualBoundValue, double inOriginalDualBoundValue, double inEstimatedValue, ParaDiffSubproblem *inDiffSubproblem)
create ParaNode object
virtual const char * getTagString(int tag)
get Tag string for debugging
virtual ~BbParaCommMpi()
destructor of this communicator
static const char * tagStringTable[]
table for tag name string
Definition: bbParaCommMpi.h:80
pthread_mutex_t tokenAccessLock
mutex for pthread thread
Definition: bbParaCommMpi.h:85
BbParaCommMpi()
default constructor of ParaCommMpi
BbParaCommMpi(MPI_Comm comm)
constructor of ParaCommMpi with MPI communicator
Base class of Calculation state in a ParaSolver.
Communicator object for MPI communications.
Definition: paraCommMpi.h:94
int token[2]
index 0: token index 1: token color -1: green > 0: yellow ( termination origin solver number ) -2: re...
Definition: paraCommMpi.h:105
Class for the difference between instance and subproblem.
class ParaRacingRampUpParamSet (parameter set for racing ramp-up)
class ParaSolverState (ParaSolver state object for notification message)
class ParaSolverTerminationState (Solver termination state in a ParaSolver)
class ParaTask
Definition: paraTask.h:542
TaskId class.
Definition: paraTask.h:223
static ScipParaCommTh * comm
Definition: fscip.cpp:73
static bool interrupted
Definition: fscip.cpp:78
static const int TYPE_LIST_SIZE
Definition: paraComm.h:81
ParaComm extension for MPI communication.
Defines for UG Framework.
#define THROW_LOGICAL_ERROR1(msg1)
Definition: paraDef.h:52
Base class for a container which has difference between instance and subproblem.
Base class for instance data.
ParaParamSet extension for MPI communication.
Base class for solution.
ParaTimer extension for MPI timer.