queso-0.53.0
Environment.h
Go to the documentation of this file.
1 //-----------------------------------------------------------------------bl-
2 //--------------------------------------------------------------------------
3 //
4 // QUESO - a library to support the Quantification of Uncertainty
5 // for Estimation, Simulation and Optimization
6 //
7 // Copyright (C) 2008-2015 The PECOS Development Team
8 //
9 // This library is free software; you can redistribute it and/or
10 // modify it under the terms of the Version 2.1 GNU Lesser General
11 // Public License as published by the Free Software Foundation.
12 //
13 // This library is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 // Lesser General Public License for more details.
17 //
18 // You should have received a copy of the GNU Lesser General Public
19 // License along with this library; if not, write to the Free Software
20 // Foundation, Inc. 51 Franklin Street, Fifth Floor,
21 // Boston, MA 02110-1301 USA
22 //
23 //-----------------------------------------------------------------------el-
24 
25 #ifndef UQ_ENVIRONMENT_H
26 #define UQ_ENVIRONMENT_H
27 
28 #include <queso/Defines.h>
29 #undef UQ_USES_COMMAND_LINE_OPTIONS
30 
31 #include <queso/MpiComm.h>
32 #ifdef QUESO_HAS_HDF5
33 #include <hdf5.h>
34 #endif
35 #include <iostream>
36 #include <fstream>
37 
38 #include <queso/RngBase.h>
39 #include <queso/BasicPdfsBase.h>
40 
41 // Forward declarations
42 namespace boost {
43  namespace program_options {
44  class options_description;
45  class variables_map;
46  }
47 }
48 
49 namespace QUESO {
50 
51 // Forward declarations
52 class EnvironmentOptions;
53 class EnvOptionsValues;
54 
55 
63 
71 struct FilePtrSetStruct {
73 
76 
79 
81  std::ofstream* ofsVar;
82 
84  std::ifstream* ifsVar;
85 #ifdef QUESO_HAS_HDF5
86  hid_t h5Var;
87 #endif
88 };
89 
90 //------------------------------------------------------------------------
91 // Library versioning routines: we include them in a QUESO namespace
92 // here so that multiple classes can use them as required (and so we
93 // can have a standalone versioning binary which does not require a full
94 // QUESO MPI environment.
95 //------------------------------------------------------------------------
96 
97  void QUESO_version_print (std::ostream &os);
99 
100 //*****************************************************
101 // Base class
102 //*****************************************************
194 public:
196 
197  BaseEnvironment(const char* passedOptionsInputFileName, EnvOptionsValues* alternativeOptionsValues);
199 
201 
204  virtual ~BaseEnvironment();
206 
208 
209  bool fullEnvIsReady() const;
211 
213  int worldRank () const;
214 
216  int fullRank () const;
217 
219  const MpiComm& fullComm () const;
220 
222  RawType_MPI_Group subGroup () const;
223 
225  int subRank () const;
226 
228  const MpiComm& subComm () const;
229 
231  const MpiComm& selfComm () const;
232 
234  int inter0Rank () const;
235 
237  const MpiComm& inter0Comm () const;
238 
240  std::ofstream* subDisplayFile() const;
241 
243  std::string subDisplayFileName () const;
244 
246  unsigned int numSubEnvironments () const;
247 
249  unsigned int subId () const;
250 
252  const std::string& subIdString () const;
253 
254  //TODO Not implemented?
255  void checkTheParallelEnvironment () const;
256 
258  std::string optionsInputFileName () const;
259 
260  void setOptionsInputFileAccessState(bool newState) const; // Yes, 'const'
261 
262 
263 #ifdef UQ_USES_COMMAND_LINE_OPTIONS
264  const boost::program_options::options_description& allOptionsDesc () const;
265 #endif
266 
269  boost::program_options::variables_map& allOptionsMap () const;
270 
271 
273 
275  void scanInputFileForMyOptions(const boost::program_options::options_description& optionsDesc) const;
276 
279  unsigned int displayVerbosity () const;
280 
282  unsigned int syncVerbosity () const;
283 
285  unsigned int checkingLevel () const;
286 
288  const RngBase* rngObject () const;
289 
291  void resetSeed (int newSeedOption);
292 
294  int seed () const;
295 
297  const BasicPdfsBase* basicPdfs() const;
298 
300  std::string platformName () const;
301 
303  std::string identifyingString () const;
304 
306  void resetIdentifyingString(const std::string& newString);
307 
309  bool isThereInputFile () const;
310 
312  struct timeval timevalBegin () const;
314 
316 
317 
319  bool openOutputFile(const std::string& fileName, const std::string& fileType,
320  const std::set<unsigned int>& allowedSubEnvIds, bool writeOver,
321  FilePtrSetStruct& filePtrSet) const;
322 
324  bool openUnifiedOutputFile (const std::string& fileName, const std::string& fileType,
325  bool writeOver, FilePtrSetStruct& filePtrSet) const;
326 
328  bool openInputFile (const std::string& fileName, const std::string& fileType,
329  const std::set<unsigned int>& allowedSubEnvIds,
330  FilePtrSetStruct& filePtrSet) const;
331 
333  bool openUnifiedInputFile (const std::string& fileName, const std::string& fileType,
334  FilePtrSetStruct& filePtrSet) const;
335 
337  void closeFile (FilePtrSetStruct& filePtrSet, const std::string& fileType) const;
338 
340  void setExceptionalCircumstance (bool value) const;
341 
343  bool exceptionalCircumstance () const;
344 
345 
346  virtual void print (std::ostream& os) const = 0;
347 
349 protected:
352 
357 
359  mutable bool m_optionsInputFileAccessState; // Yes, 'mutable'
360  boost::program_options::options_description* m_allOptionsDesc;
361  boost::program_options::variables_map* m_allOptionsMap;
362 
363  unsigned int m_subId;
364  std::string m_subIdString;
369 
371 
376 
377  mutable std::ofstream* m_subDisplayFile;
380  struct timeval m_timevalBegin;
382 
384 };
385 
386 //*****************************************************
387 // Empty Environment
388 //*****************************************************
393 public:
395 
396 
399 
403 
404 void print(std::ostream& os) const;
405 };
406 
407 //*****************************************************
408 // Full Environment
409 //*****************************************************
417 public:
419 
420 
423  FullEnvironment(RawType_MPI_Comm inputComm, const char* passedOptionsInputFileName, const char* prefix, EnvOptionsValues* alternativeOptionsValues);
424 
428 
430 
431  void print (std::ostream& os) const;
434 
435 private:
437  void readOptionsInputFile();
438  //void queso_terminate_handler();
439 
440 };
441 
442 std::ostream& operator<<(std::ostream& os, const BaseEnvironment& obj);
443 
444 } // End namespace QUESO
445 
446 #endif // UQ_ENVIRONMENT_H
MPI_Comm RawType_MPI_Comm
Definition: MpiComm.h:38
unsigned int displayVerbosity() const
Definition: Environment.C:396
const MpiComm & subComm() const
Access function for MpiComm sub communicator.
Definition: Environment.C:247
void print(std::ostream &os) const
Sends the environment options to the stream.
Definition: Environment.C:1372
virtual void print(std::ostream &os) const =0
This class sets up the environment underlying the use of the QUESO library by an executable.
Definition: Environment.h:392
BasicPdfsBase * m_basicPdfs
Definition: Environment.h:379
int subRank() const
Access function for sub-rank.
Definition: Environment.C:241
boost::program_options::variables_map * m_allOptionsMap
Definition: Environment.h:361
void setOptionsInputFileAccessState(bool newState) const
Definition: Environment.C:318
bool exceptionalCircumstance() const
Decides whether there is an exceptional circumstance.
Definition: Environment.C:1078
void scanInputFileForMyOptions(const boost::program_options::options_description &optionsDesc) const
This method scans the input file provided by the user to QUESO.
Definition: Environment.C:345
int seed() const
Access to the RNG seed.
Definition: Environment.C:423
std::string m_optionsInputFileName
Definition: Environment.h:358
FilePtrSetStruct()
Struct constructor.
Definition: Environment.C:111
~FilePtrSetStruct()
Destructor.
Definition: Environment.C:118
std::ofstream * ofsVar
Provides a stream interface to write data to files.
Definition: Environment.h:81
int fullRank() const
Returns the process full rank.
Definition: Environment.C:222
Struct for handling data input and output from files.
Definition: Environment.h:72
EmptyEnvironment()
Default constructor. Does nothing.
Definition: Environment.C:1087
std::string identifyingString() const
Access function to private attribute m_identifyingString: identifying string.
Definition: Environment.C:448
void readOptionsInputFile()
Checks the options input file and reads the options.
Definition: Environment.C:1401
RawType_MPI_Group subGroup() const
Access function for sub-group.
Definition: Environment.C:235
bool isThereInputFile() const
//TODO Not implemented? it is called in examples/validationCycle/tests_old/results_5_25/uqTgaEx4.h.
const MpiComm & fullComm() const
Access function for MpiComm full communicator.
Definition: Environment.C:228
std::ostream & operator<<(std::ostream &os, const BaseEnvironment &obj)
This class provides a suite options one can pass to a QUESO environment.
void QUESO_version_print(std::ostream &os)
Definition: Environment.C:49
unsigned int syncVerbosity() const
Access function to private attribute m_syncVerbosity.
Definition: Environment.C:403
EnvOptionsValues * m_optionsObj
Definition: Environment.h:383
unsigned int numSubEnvironments() const
Access function to the number of sub-environments.
Definition: Environment.C:288
boost::program_options::variables_map & allOptionsMap() const
Definition: Environment.C:336
const std::string & subIdString() const
Access to the attribute m_subIdString; which stores the string for the sub-environment, and it will be used, for instance, to create the output files for each sub-environment.
Definition: Environment.C:301
int inter0Rank() const
Returns the process inter0 rank.
Definition: Environment.C:261
int QUESO_get_numeric_version()
Definition: Environment.C:79
bool openUnifiedOutputFile(const std::string &fileName, const std::string &fileType, bool writeOver, FilePtrSetStruct &filePtrSet) const
Opens a unified output file, that will contain data from all sub-environments.
Definition: Environment.C:666
The QUESO MPI Communicator Class.
Definition: MpiComm.h:75
virtual ~BaseEnvironment()
Destructor.
Definition: Environment.C:161
FullEnvironment(RawType_MPI_Comm inputComm, const char *passedOptionsInputFileName, const char *prefix, EnvOptionsValues *alternativeOptionsValues)
Default constructor.
Definition: Environment.C:1107
void closeFile(FilePtrSetStruct &filePtrSet, const std::string &fileType) const
Closes the file.
Definition: Environment.C:1020
std::string m_subIdString
Definition: Environment.h:364
~FullEnvironment()
Destructor.
Definition: Environment.C:1367
std::string optionsInputFileName() const
Access to the attribute m_optionsInputFileName, which stores the name of the input file passed by the...
Definition: Environment.C:307
const MpiComm & selfComm() const
Access function for MpiComm self-communicator.
Definition: Environment.C:254
bool fullEnvIsReady() const
Returns whether the full environment class is ready (constructor has successfully been called)...
Definition: Environment.C:210
Class for random number generation (base class for either GSL or Boost RNG).
Definition: RngBase.h:45
This class sets up the full environment underlying the use of the QUESO library by an executable...
Definition: Environment.h:416
std::ofstream * subDisplayFile() const
Access function for m_subDisplayFile (displays file on stream).
Definition: Environment.C:274
RawType_MPI_Group m_fullGroup
Definition: Environment.h:356
~EmptyEnvironment()
Destructor.
Definition: Environment.C:1093
This (virtual) class sets up the environment underlying the use of the QUESO library by an executable...
Definition: Environment.h:193
unsigned int m_subId
Definition: Environment.h:363
void setExceptionalCircumstance(bool value) const
Set an exceptional circumstance.
Definition: Environment.C:1071
boost::program_options::options_description * m_allOptionsDesc
Definition: Environment.h:360
void checkTheParallelEnvironment() const
unsigned int subId() const
Access function to the number of each sub-environment Id: m_subId.
Definition: Environment.C:295
void resetSeed(int newSeedOption)
Reset RNG seed.
Definition: Environment.C:429
TODO: Base class for basic PDFs (via either GSL or Boost).
Definition: BasicPdfsBase.h:44
std::string platformName() const
Access to the platform name.
Definition: Environment.C:442
const MpiComm & inter0Comm() const
Access function for MpiComm inter0-communicator.
Definition: Environment.C:267
struct timeval m_timevalBegin
Definition: Environment.h:380
std::ofstream * m_subDisplayFile
Definition: Environment.h:377
const BasicPdfsBase * basicPdfs() const
Access to Basic PDFs.
Definition: Environment.C:436
RawType_MPI_Group m_inter0Group
Definition: Environment.h:372
const RngBase * rngObject() const
Access to the RNG object.
Definition: Environment.C:417
bool openOutputFile(const std::string &fileName, const std::string &fileType, const std::set< unsigned int > &allowedSubEnvIds, bool writeOver, FilePtrSetStruct &filePtrSet) const
Opens an output file for each sub-environment that was chosen to send data to the file...
Definition: Environment.C:467
std::ifstream * ifsVar
Provides a stream interface to read data from files.
Definition: Environment.h:84
unsigned int checkingLevel() const
Access function to private attribute m_checkingLevel.
Definition: Environment.C:410
std::string subDisplayFileName() const
Access function for m_subDisplayFileName (displays filename on stream).
Definition: Environment.C:280
int worldRank() const
Returns the process world rank.
Definition: Environment.C:216
void resetIdentifyingString(const std::string &newString)
Reset private attribute m_identifyingString with the value newString.
Definition: Environment.C:454
RawType_MPI_Group m_subGroup
Definition: Environment.h:365
BaseEnvironment(const char *passedOptionsInputFileName, EnvOptionsValues *alternativeOptionsValues)
Default constructor.
Definition: Environment.C:132
void queso_terminate_handler()
Function for unhandled exceptions in Queso.
Definition: Environment.C:1378
bool openUnifiedInputFile(const std::string &fileName, const std::string &fileType, FilePtrSetStruct &filePtrSet) const
Opens the unified input file.
Definition: Environment.C:928
void print(std::ostream &os) const
Definition: Environment.C:1098
bool openInputFile(const std::string &fileName, const std::string &fileType, const std::set< unsigned int > &allowedSubEnvIds, FilePtrSetStruct &filePtrSet) const
Opens an input file.
Definition: Environment.C:834
MPI_Group RawType_MPI_Group
Definition: MpiComm.h:39

Generated on Thu Jun 11 2015 13:52:31 for queso-0.53.0 by  doxygen 1.8.5