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-2026 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{
64public:
65
67 )
68 {
69 }
70
72 )
73 {
74 }
75
76 ///
77 /// output line initiator
78 ///
79 friend std::ostream& operator<<(std::ostream& os, ParaInitiator& paraInitiator)
80 {
81 if( paraInitiator.isPrintComment() )
82 os << "c ";
83
84 return os;
85 }
86
87 ///
88 /// check if comment messages are printed
89 /// @return true if comment messages are printed, false otherwise
90 ///
91 virtual bool isPrintComment(
92 ) = 0;
93
94 ///
95 /// check if the execution is warm started (restarted) or not
96 /// @return true if warm stated (restarted), false if it is not
97 ///
98 virtual bool isWarmStarted(
99 ) = 0;
100
101 ///
102 /// get prefix of warm start (restart) files
103 /// @return prefix string
104 ///
105 virtual const char *getPrefixWarm(
106 ) = 0;
107
108 ///
109 /// get communicator being used
110 /// @return pointer to communicator object
111 ///
113 ) = 0;
114
115 ///
116 /// initialize initiator
117 /// @return 0 if initialized normally, 1 if the problem is solved in init
118 ///
119 virtual int init(
120 ParaParamSet *params, ///< UG parameter used
121 int argc, ///< the number of command line arguments
122 char **argv ///< array of the arguments
123 )
124 {
125 std::cout << *this << "The following solver is parallelized by UG version "
126 << UG_VERSION / 100 << "." << (UG_VERSION / 10) % 10 << "." << UG_VERSION % 10
127 << " [GitHash: " << getGitHash() << "]" << std::endl;
128
129 return 0;
130 }
131
132 ///
133 /// reinitizalie initiator
134 /// TODO: this function should be in inherited class
135 /// @return 0 if reinitialized normally, 1 if the problem is solved in reinit
136 ///
137 virtual int reInit(
138 int nRestartedRacing ///< the number of restarted racing
139 ) = 0;
140
141
142 ///
143 /// get instance object
144 /// @return pointer to ParaInstance object
145 ///
147 ) = 0;
148
149 ///
150 /// send solver initialization message
151 ///
153 ) = 0;
154
155 ///
156 /// generate racing ramp-up parameter sets
157 /// TODO: this function may be in inherited class
158 ///
160 int nParamSets, ///< number of parameter sets to be generated
161 ParaRacingRampUpParamSet **racingRampUpParamSets ///< array of the racing parameter sets
162 ) = 0;
163
164 ///
165 /// get epsilon specified
166 /// @return epsilon
167 ///
168 virtual double getEpsilon() = 0;
169
170 ///
171 /// write solution
172 ///
173 virtual void writeSolution(
174 const std::string& message ///< message head string
175 ) = 0;
176
177 ///
178 /// write ParaInstance
179 ///
180 virtual void writeParaInstance(
181 const std::string& filename ///< output file name
182 ) = 0;
183
184#ifdef UG_WITH_ZLIB
185
186 ///
187 /// write checkpoint solution
188 ///
190 const std::string& filename ///< output file name
191 ) = 0;
192
193 ///
194 /// read solution from checkpoint file
195 /// @return objective function value of the solution
196 ///
198 char *afterCheckpointingSolutionFileName ///< name of after checkpointing solution file
199 ) = 0;
200
201#endif
202
203 ///
204 /// write solver runtime parameters
205 ///
207 std::ostream *os ///< output stream to write solver parameters
208 ) = 0;
209
210 ///
211 /// output final solver statistics
212 ///
214 std::ostream *os, ///< output stream to write final solver statistics
215 double time ///< computing time
216 ) = 0;
217
218 ///
219 /// get solving status string
220 /// @return string to show solving status
221 ///
222 virtual std::string getStatus(
223 ) = 0;
224
225 ///
226 /// print solver version
227 ///
228 virtual void printSolverVersion(
229 std::ostream *os ///< output file (or NULL for standard output)
230 ) = 0;
231
232#ifdef UG_WITH_UGS
233
234 ///
235 /// read ugs incumbent solution **/
236 ///
237 virtual bool readUgsIncumbentSolution(
238 UGS::UgsParaCommMpi *ugsComm, ///< communicator used to communicate with ugs solvers
239 int source ///< source ugs solver rank
240 ) = 0;
241
242 ///
243 /// write ugs incumbent solution
244 ///
245 virtual void writeUgsIncumbentSolution(
246 UGS::UgsParaCommMpi *ugsComm ///< communicator used to communicate with ugs solvers
247 ) = 0;
248
249#endif
250
251};
252
254
255}
256
257#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
virtual bool isPrintComment()=0
check if comment messages are printed
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
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
friend std::ostream & operator<<(std::ostream &os, ParaInitiator &paraInitiator)
output line initiator
Definition: paraInitiator.h:79
virtual void writeSolution(const std::string &message)=0
write solution
virtual bool isWarmStarted()=0
check if the execution is warm started (restarted) or not
virtual void generateRacingRampUpParameterSets(int nParamSets, ParaRacingRampUpParamSet **racingRampUpParamSets)=0
generate racing ramp-up parameter sets TODO: this function may be in inherited class
virtual ~ParaInitiator()
Definition: paraInitiator.h:71
virtual const char * getPrefixWarm()=0
get prefix of warm start (restart) files
virtual ParaComm * getParaComm()=0
get communicator being used
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)
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