Scippy

UG

Ubiquity Generator framework

paraInitiator.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-2025 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 paraInitiator.h
27 * @brief Base class of initiator that maintains original problem and incumbent solution.
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_INITIATOR_H__
38#define __PARA_INITIATOR_H__
39
40#include <string>
41#include "paraComm.h"
42#include "paraParamSet.h"
43#include "paraInstance.h"
44#include "paraDiffSubproblem.h"
45#include "paraSolution.h"
46#include "paraTask.h"
48#include "paraInitialStat.h"
49#include "uggithash.h"
50
51#ifdef UG_WITH_UGS
52#include "ugs/ugsDef.h"
53#include "ugs/ugsParaCommMpi.h"
54#endif
55
56namespace UG
57{
58
59///
60/// Class for initiator
61///
63{
64
65protected:
66 ParaComm *paraComm; ///< communicator used
67 ParaTimer *timer; ///< timer used
68 char *prefixWarm; ///< prefix of warm start files
69
70public:
71 bool comment; ///< print comment messages
72
73 ///
74 /// constructor
75 ///
77 ParaComm *inComm, ///< communicator used
78 ParaTimer *inTimer ///< timer used
79 ) :
80 paraComm(inComm),
81 timer(inTimer),
82 prefixWarm(0),
83 comment(false)
84 {
85 }
86
87 ///
88 /// destructor
89 ///
91 )
92 {
93 }
94
95 ///
96 /// output line initiator
97 ///
98 friend std::ostream& operator<<(std::ostream& os, const ParaInitiator& paraInitiator)
99 {
100 if( paraInitiator.comment )
101 os << "c ";
102
103 return os;
104 }
105
106 ///
107 /// check if the execution is warm started (restarted) or not
108 /// @return true if warm stated (restarted), false if it is not
109 ///
111 )
112 {
113 return prefixWarm != 0;
114 }
115
116 ///
117 /// get prefix of warm start (restart) files
118 /// @return prefix string
119 ///
120 const char *getPrefixWarm(
121 )
122 {
123 return prefixWarm;
124 }
125
126 ///
127 /// get communicator being used
128 /// @return pointer to communicator object
129 ///
131 )
132 {
133 return paraComm;
134 }
135
136 ///
137 /// initialize initiator
138 /// @return 0 if initialized normally, 1 if the problem is solved in init
139 ///
140 virtual int init(
141 ParaParamSet *params, ///< UG parameter used
142 int argc, ///< the number of command line arguments
143 char **argv ///< array of the arguments
144 )
145 {
146 std::cout << *this << "The following solver is parallelized by UG version "
147 << UG_VERSION / 100 << "." << (UG_VERSION / 10) % 10 << "." << UG_VERSION % 10
148 << " [GitHash: " << getGitHash() << "]" << std::endl;
149
150 return 0;
151 }
152
153 ///
154 /// reinitizalie initiator
155 /// TODO: this function should be in inherited class
156 /// @return 0 if reinitialized normally, 1 if the problem is solved in reinit
157 ///
158 virtual int reInit(
159 int nRestartedRacing ///< the number of restarted racing
160 ) = 0;
161
162
163 ///
164 /// get instance object
165 /// @return pointer to ParaInstance object
166 ///
168 ) = 0;
169
170 ///
171 /// send solver initialization message
172 ///
174 ) = 0;
175
176 ///
177 /// generate racing ramp-up parameter sets
178 /// TODO: this function may be in inherited class
179 ///
181 int nParamSets, ///< number of parameter sets to be generated
182 ParaRacingRampUpParamSet **racingRampUpParamSets ///< array of the racing parameter sets
183 ) = 0;
184
185 ///
186 /// get epsilon specified
187 /// @return epsilon
188 ///
189 virtual double getEpsilon() = 0;
190
191 ///
192 /// write solution
193 ///
194 virtual void writeSolution(
195 const std::string& message ///< message head string
196 ) = 0;
197
198 ///
199 /// write ParaInstance
200 ///
201 virtual void writeParaInstance(
202 const std::string& filename ///< output file name
203 ) = 0;
204
205#ifdef UG_WITH_ZLIB
206
207 ///
208 /// write checkpoint solution
209 ///
211 const std::string& filename ///< output file name
212 ) = 0;
213
214 ///
215 /// read solution from checkpoint file
216 /// @return objective function value of the solution
217 ///
219 char *afterCheckpointingSolutionFileName ///< name of after checkpointing solution file
220 ) = 0;
221
222#endif
223
224 ///
225 /// write solver runtime parameters
226 ///
228 std::ostream *os ///< output stream to write solver parameters
229 ) = 0;
230
231 ///
232 /// output final solver statistics
233 ///
235 std::ostream *os, ///< output stream to write final solver statistics
236 double time ///< computing time
237 ) = 0;
238
239 ///
240 /// get solving status string
241 /// @return string to show solving status
242 ///
243 virtual std::string getStatus(
244 ) = 0;
245
246 ///
247 /// print solver version
248 ///
249 virtual void printSolverVersion(
250 std::ostream *os ///< output file (or NULL for standard output)
251 ) = 0;
252
253#ifdef UG_WITH_UGS
254
255 ///
256 /// read ugs incumbent solution **/
257 ///
258 virtual bool readUgsIncumbentSolution(
259 UGS::UgsParaCommMpi *ugsComm, ///< communicator used to communicate with ugs solvers
260 int source ///< source ugs solver rank
261 ) = 0;
262
263 ///
264 /// write ugs incumbent solution
265 ///
266 virtual void writeUgsIncumbentSolution(
267 UGS::UgsParaCommMpi *ugsComm ///< communicator used to communicate with ugs solvers
268 ) = 0;
269
270#endif
271
272};
273
275
276}
277
278#endif // __PARA_INITIATOR_HPP__
Base class of communicator object.
Definition: paraComm.h:102
Class for initiator.
Definition: paraInitiator.h:63
virtual void writeParaInstance(const std::string &filename)=0
write ParaInstance
ParaComm * paraComm
communicator used
Definition: paraInitiator.h:66
virtual int init(ParaParamSet *params, int argc, char **argv)
initialize initiator
virtual std::string getStatus()=0
get solving status string
virtual int reInit(int nRestartedRacing)=0
reinitizalie initiator TODO: this function should be in inherited class
ParaInitiator(ParaComm *inComm, ParaTimer *inTimer)
constructor
Definition: paraInitiator.h:76
ParaComm * getParaComm()
get communicator being used
bool comment
print comment messages
Definition: paraInitiator.h:71
virtual void sendSolverInitializationMessage()=0
send solver initialization message
virtual double readSolutionFromCheckpointFile(char *afterCheckpointingSolutionFileName)=0
read solution from checkpoint file
virtual void printSolverVersion(std::ostream *os)=0
print solver version
virtual void writeCheckpointSolution(const std::string &filename)=0
write checkpoint solution
virtual void writeSolution(const std::string &message)=0
write solution
virtual void generateRacingRampUpParameterSets(int nParamSets, ParaRacingRampUpParamSet **racingRampUpParamSets)=0
generate racing ramp-up parameter sets TODO: this function may be in inherited class
char * prefixWarm
prefix of warm start files
Definition: paraInitiator.h:68
ParaTimer * timer
timer used
Definition: paraInitiator.h:67
virtual ~ParaInitiator()
destructor
Definition: paraInitiator.h:90
const char * getPrefixWarm()
get prefix of warm start (restart) files
friend std::ostream & operator<<(std::ostream &os, const ParaInitiator &paraInitiator)
output line initiator
Definition: paraInitiator.h:98
bool isWarmStarted()
check if the execution is warm started (restarted) or not
virtual void writeSolverParameters(std::ostream *os)=0
write solver runtime parameters
virtual ParaInstance * getParaInstance()=0
get instance object
virtual double getEpsilon()=0
get epsilon specified
virtual void outputFinalSolverStatistics(std::ostream *os, double time)=0
output final solver statistics
class for instance data
Definition: paraInstance.h:51
class ParaParamSet
Definition: paraParamSet.h:850
class ParaRacingRampUpParamSet (parameter set for racing ramp-up)
class ParaTimer
Definition: paraTimer.h:49
static ScipParaInitiator * paraInitiator
Definition: fscip.cpp:76
ParaInitiator * ParaInitiatorPtr
const char * getGitHash()
Definition: uggithash.cpp:33
Base class of communicator for UG Framework.
#define UG_VERSION
Definition: paraDef.h:48
Base class for a container which has difference between instance and subproblem.
Base class for initial statistics collecting class.
Base class for instance data.
Parameter set for UG framework.
Base class for racing ramp-up parameter set.
Base class for solution.
Base class for ParaTask.
returns the current git hash of UG