queso-0.52.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 namespace QUESO {
30  class EnvironmentOptions;
31 } // End namespace QUESO
32 
33 #undef UQ_USES_COMMAND_LINE_OPTIONS
34 
35 #include <queso/MpiComm.h>
36 #ifdef QUESO_HAS_HDF5
37 #include <hdf5.h>
38 #endif
39 #include <boost/program_options.hpp>
40 namespace po = boost::program_options;
41 #include <iostream>
42 #include <fstream>
43 
44 #include <queso/RngBase.h>
45 #include <queso/BasicPdfsBase.h>
46 
47 namespace QUESO {
48 
49 
57 
65 struct FilePtrSetStruct {
67 
70 
73 
75  std::ofstream* ofsVar;
76 
78  std::ifstream* ifsVar;
79 #ifdef QUESO_HAS_HDF5
80  hid_t h5Var;
81 #endif
82 };
83 
84 //------------------------------------------------------------------------
85 // Library versioning routines: we include them in a QUESO namespace
86 // here so that multiple classes can use them as required (and so we
87 // can have a standalone versioning binary which does not require a full
88 // QUESO MPI environment.
89 //------------------------------------------------------------------------
90 
91  void QUESO_version_print (std::ostream &os);
93 
94 //*****************************************************
95 // Base class
96 //*****************************************************
188 public:
190 
191  BaseEnvironment(const char* passedOptionsInputFileName, const EnvOptionsValues* alternativeOptionsValues);
193 
195  BaseEnvironment(const BaseEnvironment& obj);
196 
198 
201  virtual ~BaseEnvironment();
203 
205 
209 
211 
212  bool fullEnvIsReady() const;
214 
216  int worldRank () const;
217 
219  int fullRank () const;
220 
222  const MpiComm& fullComm () const;
223 
225  RawType_MPI_Group subGroup () const;
226 
228  int subRank () const;
229 
231  const MpiComm& subComm () const;
232 
234  const MpiComm& selfComm () const;
235 
237  int inter0Rank () const;
238 
240  const MpiComm& inter0Comm () const;
241 
243  std::ofstream* subDisplayFile() const;
244 
246  std::string subDisplayFileName () const;
247 
249  unsigned int numSubEnvironments () const;
250 
252  unsigned int subId () const;
253 
255  const std::string& subIdString () const;
256 
257  //TODO Not implemented?
258  void checkTheParallelEnvironment () const;
259 
261  std::string optionsInputFileName () const;
262 
263  void setOptionsInputFileAccessState(bool newState) const; // Yes, 'const'
264 
265 
266 #ifdef UQ_USES_COMMAND_LINE_OPTIONS
267  const po::options_description& allOptionsDesc () const;
268 #endif
269 
272  po::variables_map& allOptionsMap () const;
273 
274 
276 
278  void scanInputFileForMyOptions(const po::options_description& optionsDesc) const;
279 
282  unsigned int displayVerbosity () const;
283 
285  unsigned int syncVerbosity () const;
286 
288  unsigned int checkingLevel () const;
289 
291  const RngBase* rngObject () const;
292 
294  void resetSeed (int newSeedOption);
295 
297  int seed () const;
298 
300  const BasicPdfsBase* basicPdfs() const;
301 
303  std::string platformName () const;
304 
306  std::string identifyingString () const;
307 
309  void resetIdentifyingString(const std::string& newString) const; // Yes, const
310 
312  bool isThereInputFile () const;
313 
315  struct timeval timevalBegin () const;
317 
319 
320 
322  bool openOutputFile(const std::string& fileName, const std::string& fileType,
323  const std::set<unsigned int>& allowedSubEnvIds, bool writeOver,
324  FilePtrSetStruct& filePtrSet) const;
325 
327  bool openUnifiedOutputFile (const std::string& fileName, const std::string& fileType,
328  bool writeOver, FilePtrSetStruct& filePtrSet) const;
329 
331  bool openInputFile (const std::string& fileName, const std::string& fileType,
332  const std::set<unsigned int>& allowedSubEnvIds,
333  FilePtrSetStruct& filePtrSet) const;
334 
336  bool openUnifiedInputFile (const std::string& fileName, const std::string& fileType,
337  FilePtrSetStruct& filePtrSet) const;
338 
340  void closeFile (FilePtrSetStruct& filePtrSet, const std::string& fileType) const;
341 
343  void setExceptionalCircumstance (bool value) const;
344 
346  bool exceptionalCircumstance () const;
347 
348 
349  virtual void print (std::ostream& os) const = 0;
350 
352 protected:
355 
360 
362  mutable bool m_optionsInputFileAccessState; // Yes, 'mutable'
363  po::options_description* m_allOptionsDesc;
364  po::variables_map* m_allOptionsMap;
365 
366  unsigned int m_subId;
367  std::string m_subIdString;
372 
374 
379 
380  mutable std::ofstream* m_subDisplayFile;
383  struct timeval m_timevalBegin;
385 
388 };
389 
390 //*****************************************************
391 // Empty Environment
392 //*****************************************************
397 public:
399 
400 
403 
407 
408 void print(std::ostream& os) const;
409 };
410 
411 //*****************************************************
412 // Full Environment
413 //*****************************************************
421 public:
423 
424 
427  FullEnvironment(RawType_MPI_Comm inputComm, const char* passedOptionsInputFileName, const char* prefix, const EnvOptionsValues* alternativeOptionsValues);
428 
432 
434 
435  void print (std::ostream& os) const;
438 
439 private:
441  void readOptionsInputFile();
442  //void queso_terminate_handler();
443 
444 };
445 
446 std::ostream& operator<<(std::ostream& os, const BaseEnvironment& obj);
447 
448 } // End namespace QUESO
449 
450 #endif // UQ_ENVIRONMENT_H
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:335
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:913
std::string m_subIdString
Definition: Environment.h:367
po::options_description * m_allOptionsDesc
Definition: Environment.h:363
virtual void print(std::ostream &os) const =0
int subRank() const
Access function for sub-rank.
Definition: Environment.C:263
Class for random number generation (base class for either GSL or Boost RNG).
Definition: RngBase.h:45
const RngBase * rngObject() const
Access to the RNG object.
Definition: Environment.C:466
void print(std::ostream &os) const
Sends the environment options to the stream.
Definition: Environment.C:1484
unsigned int syncVerbosity() const
Access function to private attribute m_syncVerbosity.
Definition: Environment.C:446
bool openUnifiedInputFile(const std::string &fileName, const std::string &fileType, FilePtrSetStruct &filePtrSet) const
Opens the unified input file.
Definition: Environment.C:1016
struct timeval m_timevalBegin
Definition: Environment.h:383
int inter0Rank() const
Returns the process inter0 rank.
Definition: Environment.C:289
Struct for handling data input and output from files.
Definition: Environment.h:66
std::string subDisplayFileName() const
Access function for m_subDisplayFileName (displays filename on stream).
Definition: Environment.C:311
void resetSeed(int newSeedOption)
Reset RNG seed.
Definition: Environment.C:478
int worldRank() const
Returns the process world rank.
Definition: Environment.C:235
unsigned int checkingLevel() const
Access function to private attribute m_checkingLevel.
Definition: Environment.C:456
const MpiComm & subComm() const
Access function for MpiComm sub communicator.
Definition: Environment.C:269
BaseEnvironment(const char *passedOptionsInputFileName, const EnvOptionsValues *alternativeOptionsValues)
Default constructor.
Definition: Environment.C:130
MPI_Comm RawType_MPI_Comm
Definition: MpiComm.h:38
std::ofstream * subDisplayFile() const
Access function for m_subDisplayFile (displays file on stream).
Definition: Environment.C:305
std::ostream & operator<<(std::ostream &os, const BaseEnvironment &obj)
EmptyEnvironment()
Default constructor. Does nothing.
Definition: Environment.C:1187
const MpiComm & fullComm() const
Access function for MpiComm full communicator.
Definition: Environment.C:247
void print(std::ostream &os) const
Definition: Environment.C:1198
virtual ~BaseEnvironment()
Destructor.
Definition: Environment.C:169
po::variables_map & allOptionsMap() const
Definition: Environment.C:368
void resetIdentifyingString(const std::string &newString) const
Reset private attribute m_identifyingString with the value newString.
Definition: Environment.C:503
This (virtual) class sets up the environment underlying the use of the QUESO library by an executable...
Definition: Environment.h:187
std::string identifyingString() const
Access function to private attribute m_identifyingString: identifying string.
Definition: Environment.C:497
~FilePtrSetStruct()
Destructor.
Definition: Environment.C:116
std::ofstream * ofsVar
Provides a stream interface to write data to files.
Definition: Environment.h:75
std::string m_optionsInputFileName
Definition: Environment.h:361
std::ofstream * m_subDisplayFile
Definition: Environment.h:380
std::string platformName() const
Access to the platform name.
Definition: Environment.C:491
void QUESO_version_print(std::ostream &os)
Definition: Environment.C:47
po::variables_map * m_allOptionsMap
Definition: Environment.h:364
void readOptionsInputFile()
Checks the options input file and reads the options.
Definition: Environment.C:1513
BasicPdfsBase * m_basicPdfs
Definition: Environment.h:382
This class sets up the full environment underlying the use of the QUESO library by an executable...
Definition: Environment.h:420
void closeFile(FilePtrSetStruct &filePtrSet, const std::string &fileType) const
Closes the file.
Definition: Environment.C:1117
std::string optionsInputFileName() const
Access to the attribute m_optionsInputFileName, which stores the name of the input file passed by the...
Definition: Environment.C:341
FilePtrSetStruct()
Struct constructor.
Definition: Environment.C:109
bool isThereInputFile() const
//TODO Not implemented? it is called in examples/validationCycle/tests_old/results_5_25/uqTgaEx4.h.
std::ifstream * ifsVar
Provides a stream interface to read data from files.
Definition: Environment.h:78
void setOptionsInputFileAccessState(bool newState) const
Definition: Environment.C:352
RawType_MPI_Group m_inter0Group
Definition: Environment.h:375
unsigned int m_subId
Definition: Environment.h:366
TODO: Base class for basic PDFs (via either GSL or Boost).
Definition: BasicPdfsBase.h:44
~FullEnvironment()
Destructor.
Definition: Environment.C:1479
bool fullEnvIsReady() const
Returns whether the full environment class is ready (constructor has successfully been called)...
Definition: Environment.C:229
The QUESO MPI Communicator Class.
Definition: MpiComm.h:75
~EmptyEnvironment()
Destructor.
Definition: Environment.C:1193
const BasicPdfsBase * basicPdfs() const
Access to Basic PDFs.
Definition: Environment.C:485
void setExceptionalCircumstance(bool value) const
Set an exceptional circumstance.
Definition: Environment.C:1171
int QUESO_get_numeric_version()
Definition: Environment.C:77
int fullRank() const
Returns the process full rank.
Definition: Environment.C:241
MPI_Group RawType_MPI_Group
Definition: MpiComm.h:39
unsigned int numSubEnvironments() const
Access function to the number of sub-environments.
Definition: Environment.C:319
This class reads options one can pass to a QUESO environment through an input file.
const MpiComm & selfComm() const
Access function for MpiComm self-communicator.
Definition: Environment.C:279
FullEnvironment(RawType_MPI_Comm inputComm, const char *passedOptionsInputFileName, const char *prefix, const EnvOptionsValues *alternativeOptionsValues)
Default constructor.
Definition: Environment.C:1207
EnvironmentOptions * m_optionsObj
Definition: Environment.h:387
RawType_MPI_Group subGroup() const
Access function for sub-group.
Definition: Environment.C:257
void queso_terminate_handler()
Function for unhandled exceptions in Queso.
Definition: Environment.C:1490
int seed() const
Access to the RNG seed.
Definition: Environment.C:472
RawType_MPI_Group m_fullGroup
Definition: Environment.h:359
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:733
unsigned int displayVerbosity() const
Definition: Environment.C:436
const MpiComm & inter0Comm() const
Access function for MpiComm inter0-communicator.
Definition: Environment.C:295
void checkTheParallelEnvironment() const
This class provides a suite options one can pass to a QUESO environment.
Definition: Defines.h:105
EnvOptionsValues m_alternativeOptionsValues
Definition: Environment.h:386
This class sets up the environment underlying the use of the QUESO library by an executable.
Definition: Environment.h:396
unsigned int subId() const
Access function to the number of each sub-environment Id: m_subId.
Definition: Environment.C:329
BaseEnvironment & operator=(const BaseEnvironment &rhs)
Assignment operator. It should not be used be the user.
Definition: Environment.C:219
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:516
bool exceptionalCircumstance() const
Decides whether there is an exceptional circumstance.
Definition: Environment.C:1178
RawType_MPI_Group m_subGroup
Definition: Environment.h:368
void scanInputFileForMyOptions(const po::options_description &optionsDesc) const
This method scans the input file provided by the user to QUESO.
Definition: Environment.C:378

Generated on Thu Apr 23 2015 19:30:54 for queso-0.52.0 by  doxygen 1.8.5