Scippy

UG

Ubiquity Generator framework

paraSolverPool.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 paraSolverPool.h
27 * @brief Solver pool.
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_POOL_H__
38#define __PARA_SOLVER_POOL_H__
39#include <cstdlib>
40#include <map>
41#include "paraTask.h"
42#include "paraTimer.h"
46
47namespace UG
48{
49
50class ParaSolverPoolElement;
51typedef ParaSolverPoolElement * ParaSolverPoolElementPtr;
52
54
55#define SOLVER_POOL_INDEX( rank ) ( rank - originRank )
56
57///
58/// class ParaSolverPool
59/// (Solver Pool base class)
60///
62
63protected:
64
65 int originRank; ///< origin rank of Solvers managed by this Solver pool
66 std::size_t nSolvers; ///< number of Solvers
67 ParaComm *paraComm; ///< communicator
68 ParaParamSet *paraParams; ///< runtime parameters for parallelization
69 ParaTimer *paraTimer; ///< timer
70
71public:
72
73 ///
74 /// constructor
75 ///
77 int inOriginRank, ///< origin rank of Solvers managed by this Solver pool
78 ParaComm *inParaComm, ///< communicator used
79 ParaParamSet *inParaParams, ///< paraParamSet used
80 ParaTimer *inParaTimer ///< timer used
81 )
82 : originRank(inOriginRank),
83 paraComm(inParaComm),
84 paraParams(inParaParams),
85 paraTimer(inParaTimer)
86 {
87 nSolvers = paraComm->getSize() - inOriginRank;
88 }
89
90 ///
91 /// destructor
92 ///
94 )
95 {
96 }
97
98 ///
99 /// get number of Solvers in this Solver pool
100 /// @return number of Solvers
101 ///
102 std::size_t getNSolvers(
103 )
104 {
105 return nSolvers;
106 }
107
108 ///
109 /// get number of active Solvers
110 /// @return number of active Solvers
111 ///
112 virtual std::size_t getNumActiveSolvers(
113 ) = 0;
114
115 ///
116 /// get number of inactive Solvers
117 /// @return number of inactive Solvers
118 ///
119 virtual std::size_t getNumInactiveSolvers(
120 ) = 0;
121
122 ///
123 /// check if the Solver specified by rank is active or not
124 /// @return true if the Solver is active, false otherwise
125 ///
126 virtual bool isSolverActive(
127 int rank ///< rank of the Solver to be checked
128 ) = 0;
129
130 ///
131 /// get current solving ParaTask in the Solver specified by rank
132 /// @return pointer to ParaTask object
133 ///
135 int rank ///< rank of the Solver
136 ) = 0;
137
138 ///
139 /// set the Solver specified by rank is interrupt requested
140 ///
141 virtual void interruptRequested(
142 int rank ///< rank of the Solver
143 ) = 0;
144
145 ///
146 /// check if the Solver specified by rank is interrupt requested or not
147 /// @return return true if the Solver is interrupt requested, false otherwise
148 ///
150 int rank ///< rank of the Solver
151 ) = 0;
152
153 ///
154 /// set the Solver specified by rank is terminate requested
155 ///
156 virtual void terminateRequested(
157 int rank ///< rank of the Solver
158 ) = 0;
159
160 ///
161 /// check if the Solver specified by rank is terminate requested or not
162 /// @return return true if the Solver is terminate requested, false otherwise
163 ///
165 int rank ///< rank of the Solver
166 ) = 0;
167
168 ///
169 /// set the Solver specified by rank is terminated
170 ///
171 virtual void terminated(
172 int rank ///< rank of the Solver
173 ) = 0;
174
175 ///
176 /// check if the Solver specified by rank is terminated or not
177 /// @return return true if the Solver is terminated, false otherwise
178 ///
179 virtual bool isTerminated(
180 int rank ///< rank of the Solver
181 ) = 0;
182
183};
184
185///
186/// class ParaRacingSolverPool
187/// (Racing Solver Pool)
188///
190{
191
192protected:
193
194 int winnerRank; ///< winner rank of racing ramp-up, -1: not decided yet
195 int originRank; ///< origin rank of Solvers managed by this Solver pool
196 int nSolvers; ///< number of Solvers
197 ParaComm *paraComm; ///< communicator
198 ParaParamSet *paraParams; ///< runtime parameters for parallelization
199 ParaTimer *paraTimer; ///< timer used
200 ParaDeterministicTimer *paraDetTimer; ///< deterministic timer used
201
202public:
203
204 ///
205 /// constructor
206 ///
208 int inOriginRank, ///< origin rank of Solvers managed by this Solver pool
209 ParaComm *inParaComm, ///< communicator used
210 ParaParamSet *inParaParams, ///< paraParamSet used
211 ParaTimer *inParaTimer, ///< timer used
212 ParaDeterministicTimer *inParaDetTimer ///< deterministic timer used
213 )
214 : winnerRank(-1),
215 originRank(inOriginRank),
216 paraComm(inParaComm),
217 paraParams(inParaParams),
218 paraTimer(inParaTimer),
219 paraDetTimer(inParaDetTimer)
220 {
221 nSolvers = paraComm->getSize() - inOriginRank;
222 }
223
224 ///
225 /// destructor
226 ///
228 )
229 {
230 }
231
232 ///
233 /// get root ParaTask object of the Solver specified
234 ///
236 int rank ///< rank of the Solver
237 ) = 0;
238
239 ///
240 /// get number of active Solvers
241 /// @return number of active Solvers
242 ///
243 virtual std::size_t getNumActiveSolvers(
244 ) = 0;
245
246
247 ///
248 /// get number of inactive Solvers
249 /// @return number of inactive Solvers
250 ///
251 virtual std::size_t getNumInactiveSolvers(
252 ) = 0;
253
254 ///
255 /// check if the specified Solver is active or not
256 /// @return true if the specified Solver is active, false otherwise
257 ///
258 virtual bool isSolverActive(
259 int rank ///< rank of the Solver
260 ) = 0;
261
262 ///
263 /// get winner Solver rank
264 /// @return rank of the winner Solver
265 ///
267 )
268 {
269 // assert( winnerRank > 0 );
270 return winnerRank; // -1 means that winner is not decided
271 }
272
273 ///
274 /// get number of Solvers in this Solver pool
275 /// @return number of Solvers
276 ///
277 std::size_t getNSolvers(
278 )
279 {
280 return nSolvers;
281 }
282
283};
284
285}
286
287#endif // __PARA_SOLVER_POOL_H__
288
Base class of communicator object.
Definition: paraComm.h:102
virtual int getSize()=0
get number of UG processes or UG threads depending on run-time environment
class for deterministic timer
class ParaParamSet
Definition: paraParamSet.h:850
class ParaRacingSolverPool (Racing Solver Pool)
int originRank
origin rank of Solvers managed by this Solver pool
ParaParamSet * paraParams
runtime parameters for parallelization
ParaComm * paraComm
communicator
virtual ParaTask * getCurrentTask(int rank)=0
get root ParaTask object of the Solver specified
int getWinner()
get winner Solver rank
int nSolvers
number of Solvers
ParaTimer * paraTimer
timer used
ParaRacingSolverPool(int inOriginRank, ParaComm *inParaComm, ParaParamSet *inParaParams, ParaTimer *inParaTimer, ParaDeterministicTimer *inParaDetTimer)
constructor
virtual ~ParaRacingSolverPool()
destructor
virtual bool isSolverActive(int rank)=0
check if the specified Solver is active or not
std::size_t getNSolvers()
get number of Solvers in this Solver pool
int winnerRank
winner rank of racing ramp-up, -1: not decided yet
virtual std::size_t getNumInactiveSolvers()=0
get number of inactive Solvers
virtual std::size_t getNumActiveSolvers()=0
get number of active Solvers
ParaDeterministicTimer * paraDetTimer
deterministic timer used
class ParaSolverPool (Solver Pool base class)
int originRank
origin rank of Solvers managed by this Solver pool
ParaParamSet * paraParams
runtime parameters for parallelization
ParaComm * paraComm
communicator
virtual ParaTask * getCurrentTask(int rank)=0
get current solving ParaTask in the Solver specified by rank
virtual void interruptRequested(int rank)=0
set the Solver specified by rank is interrupt requested
ParaSolverPool(int inOriginRank, ParaComm *inParaComm, ParaParamSet *inParaParams, ParaTimer *inParaTimer)
constructor
virtual bool isInterruptRequested(int rank)=0
check if the Solver specified by rank is interrupt requested or not
std::size_t nSolvers
number of Solvers
virtual bool isTerminateRequested(int rank)=0
check if the Solver specified by rank is terminate requested or not
ParaTimer * paraTimer
timer
virtual void terminateRequested(int rank)=0
set the Solver specified by rank is terminate requested
virtual void terminated(int rank)=0
set the Solver specified by rank is terminated
virtual ~ParaSolverPool()
destructor
virtual bool isSolverActive(int rank)=0
check if the Solver specified by rank is active or not
virtual bool isTerminated(int rank)=0
check if the Solver specified by rank is terminated or not
std::size_t getNSolvers()
get number of Solvers in this Solver pool
virtual std::size_t getNumInactiveSolvers()=0
get number of inactive Solvers
virtual std::size_t getNumActiveSolvers()=0
get number of active Solvers
class ParaTask
Definition: paraTask.h:542
class ParaTimer
Definition: paraTimer.h:49
ParaSolverPoolElement * ParaSolverPoolElementPtr
SolverStatus
@ Terminated
@ Active
@ Dead
@ Reserved
@ TerminateRequested
@ Inactive
@ InterruptRequested
@ Racing
@ RacingEvaluation
Base class for deterministic timer.
Base class for racing ramp-up parameter set.
This class contains solver termination state which is transferred form Solver to LC.
Base class for ParaTask.
Base class for Timer.