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