queso-0.57.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
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-2017 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 #include <queso/ScopedPtr.h>
33 
34 #ifdef QUESO_HAS_HDF5
35 #include <hdf5.h>
36 #endif
37 #include <iostream>
38 #include <fstream>
39 
40 
41 #ifndef QUESO_DISABLE_BOOST_PROGRAM_OPTIONS
42 // Forward declarations
43 namespace boost {
44  namespace program_options {
45  class options_description;
46  class variables_map;
47  }
48 }
49 #endif // QUESO_DISABLE_BOOST_PROGRAM_OPTIONS
50 
51 namespace QUESO {
52 
53 // Forward declarations
54 class GetPot;
55 class EnvironmentOptions;
56 class EnvOptionsValues;
57 class BasicPdfsBase;
58 class RngBase;
59 
60 
68 
76 struct FilePtrSetStruct {
78 
81 
84 
86  std::ofstream* ofsVar;
87 
89  std::ifstream* ifsVar;
90 #ifdef QUESO_HAS_HDF5
91  hid_t h5Var;
92 #endif
93 };
94 
95 //------------------------------------------------------------------------
96 // Library versioning routines: we include them in a QUESO namespace
97 // here so that multiple classes can use them as required (and so we
98 // can have a standalone versioning binary which does not require a full
99 // QUESO MPI environment.
100 //------------------------------------------------------------------------
101 
102  void QUESO_version_print (std::ostream &os);
104 
105 //*****************************************************
106 // Base class
107 //*****************************************************
199 public:
201 
202  BaseEnvironment(const char* passedOptionsInputFileName, EnvOptionsValues* alternativeOptionsValues);
204 
205  BaseEnvironment(const std::string & passedOptionsInputFileName,
206  EnvOptionsValues* alternativeOptionsValues);
207 
209 
212  virtual ~BaseEnvironment();
214 
216 
217  bool fullEnvIsReady() const;
219 
221 
226  int worldRank () const;
227 
229 
235  int fullRank () const;
236 
238 
244  const MpiComm& fullComm () const;
245 
247  RawType_MPI_Group subGroup () const;
248 
250 
268  int subRank () const;
269 
271 
297  const MpiComm& subComm () const;
298 
300 
303  const MpiComm& selfComm () const;
304 
306  int inter0Rank () const;
307 
309  /*
310  * This communicator contains all the processes that have subRank() equal to
311  * 0.
312  *
313  * Their corresponding fullRank() values will be 0, M, 2M, ..., N-M,
314  * where M is the number of sub-environments the user asked for and N is the
315  * size of fullComm().
316  */
317  const MpiComm& inter0Comm () const;
318 
320  std::ofstream* subDisplayFile() const;
321 
323  std::string subDisplayFileName () const;
324 
326  unsigned int numSubEnvironments () const;
327 
329  unsigned int subId () const;
330 
332  const std::string& subIdString () const;
333 
334  //TODO Not implemented?
335  void checkTheParallelEnvironment () const;
336 
338  std::string optionsInputFileName () const;
339 
340  void setOptionsInputFileAccessState(bool newState) const; // Yes, 'const'
341 
342 
343 #ifndef QUESO_DISABLE_BOOST_PROGRAM_OPTIONS
344 #ifdef UQ_USES_COMMAND_LINE_OPTIONS
345  const boost::program_options::options_description& allOptionsDesc () const;
346 #endif
347 #endif // QUESO_DISABLE_BOOST_PROGRAM_OPTIONS
348 
349 #ifndef QUESO_DISABLE_BOOST_PROGRAM_OPTIONS
350  boost::program_options::variables_map& allOptionsMap () const;
353 #endif // QUESO_DISABLE_BOOST_PROGRAM_OPTIONS
354 
355 
356 #ifndef QUESO_DISABLE_BOOST_PROGRAM_OPTIONS
357 
360  void scanInputFileForMyOptions(const boost::program_options::options_description& optionsDesc) const;
361 #endif // QUESO_DISABLE_BOOST_PROGRAM_OPTIONS
362 
365  unsigned int displayVerbosity () const;
366 
368  unsigned int syncVerbosity () const;
369 
371  unsigned int checkingLevel () const;
372 
374  const RngBase* rngObject () const;
375 
377  void resetSeed (int newSeedOption);
378 
380  int seed () const;
381 
383  const BasicPdfsBase* basicPdfs() const;
384 
386  std::string platformName () const;
387 
389  std::string identifyingString () const;
390 
392  void resetIdentifyingString(const std::string& newString);
393 
395  bool isThereInputFile () const;
396 
398  struct timeval timevalBegin () const;
400 
402 
403 
405  bool openOutputFile(const std::string& fileName, const std::string& fileType,
406  const std::set<unsigned int>& allowedSubEnvIds, bool writeOver,
407  FilePtrSetStruct& filePtrSet) const;
408 
410  bool openUnifiedOutputFile (const std::string& fileName, const std::string& fileType,
411  bool writeOver, FilePtrSetStruct& filePtrSet) const;
412 
414  bool openInputFile (const std::string& fileName, const std::string& fileType,
415  const std::set<unsigned int>& allowedSubEnvIds,
416  FilePtrSetStruct& filePtrSet) const;
417 
419  bool openUnifiedInputFile (const std::string& fileName, const std::string& fileType,
420  FilePtrSetStruct& filePtrSet) const;
421 
423  void closeFile (FilePtrSetStruct& filePtrSet, const std::string& fileType) const;
424 
426  void setExceptionalCircumstance (bool value) const;
427 
429  bool exceptionalCircumstance () const;
430 
432  const GetPot & input() const;
433 
434 
435  virtual void print (std::ostream& os) const = 0;
436 
438 protected:
441 
446 
448  mutable bool m_optionsInputFileAccessState; // Yes, 'mutable'
449 #ifndef QUESO_DISABLE_BOOST_PROGRAM_OPTIONS
452 #endif // QUESO_DISABLE_BOOST_PROGRAM_OPTIONS
454 
455  unsigned int m_subId;
456  std::string m_subIdString;
461 
463 
468 
472  struct timeval m_timevalBegin;
474 
476 };
477 
478 //*****************************************************
479 // Empty Environment
480 //*****************************************************
485 public:
487 
488 
491 
495 
496 void print(std::ostream& os) const;
497 };
498 
499 //*****************************************************
500 // Full Environment
501 //*****************************************************
509 public:
511 
512 
518 #ifdef QUESO_HAS_MPI
519  FullEnvironment(RawType_MPI_Comm inputComm, const char* passedOptionsInputFileName, const char* prefix, EnvOptionsValues* alternativeOptionsValues);
520 
522  const std::string& passedOptionsInputFileName,
523  const std::string& prefix,
524  EnvOptionsValues* alternativeOptionsValues);
525 #endif
526 
528 
532  FullEnvironment(const char* passedOptionsInputFileName, const char* prefix, EnvOptionsValues* alternativeOptionsValues);
533 
534  FullEnvironment(const std::string& passedOptionsInputFileName,
535  const std::string& prefix,
536  EnvOptionsValues* alternativeOptionsValues);
537 
541 
543 
544  void print (std::ostream& os) const;
547 
548 private:
549 #ifdef QUESO_HAS_MPI
550  void construct(RawType_MPI_Comm inputComm,
552  const char *prefix);
553 #endif
554 
556  void construct(const char *prefix);
557 
559  void readOptionsInputFile();
560  //void queso_terminate_handler();
561 
562 };
563 
564 std::ostream& operator<<(std::ostream& os, const BaseEnvironment& obj);
565 
566 } // End namespace QUESO
567 
568 #endif // UQ_ENVIRONMENT_H
ScopedPtr< GetPot >::Type m_input
Definition: Environment.h:453
MPI_Comm RawType_MPI_Comm
Definition: MpiComm.h:41
unsigned int subId() const
Access function to the number of each sub-environment Id: m_subId.
Definition: Environment.C:342
std::unique_ptr< T > Type
Definition: ScopedPtr.h:76
const boost::program_options::options_description & allOptionsDesc() const
Definition: Environment.C:375
std::string platformName() const
Access to the platform name.
Definition: Environment.C:496
bool isThereInputFile() const
//TODO Not implemented? it is called in examples/validationCycle/tests_old/results_5_25/uqTgaEx4.h.
ScopedPtr< MpiComm >::Type m_fullComm
Definition: Environment.h:442
This (virtual) class sets up the environment underlying the use of the QUESO library by an executable...
Definition: Environment.h:198
ScopedPtr< EnvOptionsValues >::Type m_optionsObj
Definition: Environment.h:475
void construct(RawType_MPI_Comm inputComm, const char *prefix)
Named constructor backend for multiple constructor overloads.
Definition: Environment.C:1202
TODO: Base class for basic PDFs (via either GSL or Boost).
Definition: BasicPdfsBase.h:44
boost::program_options::variables_map & allOptionsMap() const
Definition: Environment.C:386
std::ostream & operator<<(std::ostream &os, const SequenceStatisticalOptions &obj)
void closeFile(FilePtrSetStruct &filePtrSet, const std::string &fileType) const
Closes the file.
Definition: Environment.C:1084
const GetPot & input() const
The GetPot input file parser.
Definition: Environment.C:1149
const MpiComm & inter0Comm() const
Access function for MpiComm communicator for processes with subRank() 0.
Definition: Environment.C:313
int subRank() const
Returns the rank of the MPI process in the sub-communicator subComm()
Definition: Environment.C:287
~FilePtrSetStruct()
Destructor.
std::string optionsInputFileName() const
Access to the attribute m_optionsInputFileName, which stores the name of the input file passed by the...
Definition: Environment.C:354
const MpiComm & selfComm() const
Access function for MpiComm self-communicator.
Definition: Environment.C:300
This class sets up the full environment underlying the use of the QUESO library by an executable...
Definition: Environment.h:508
const RngBase * rngObject() const
Access to the RNG object.
Definition: Environment.C:471
Class for random number generation (base class for either GSL or Boost RNG).
Definition: RngBase.h:45
bool exceptionalCircumstance() const
Decides whether there is an exceptional circumstance.
Definition: Environment.C:1143
This class sets up the environment underlying the use of the QUESO library by an executable.
Definition: Environment.h:484
FilePtrSetStruct()
Struct constructor.
Definition: Environment.C:130
unsigned int checkingLevel() const
Access function to private attribute m_checkingLevel.
Definition: Environment.C:464
void resetIdentifyingString(const std::string &newString)
Reset private attribute m_identifyingString with the value newString.
Definition: Environment.C:508
RawType_MPI_Group m_fullGroup
Definition: Environment.h:445
std::string subDisplayFileName() const
Access function for m_subDisplayFileName (displays filename on stream).
Definition: Environment.C:327
RawType_MPI_Group m_subGroup
Definition: Environment.h:457
ScopedPtr< RngBase >::Type m_rngObject
Definition: Environment.h:470
int worldRank() const
Returns the same thing as fullRank()
Definition: Environment.C:262
void setExceptionalCircumstance(bool value) const
Set an exceptional circumstance.
Definition: Environment.C:1136
void checkTheParallelEnvironment() const
int fullRank() const
Returns the rank of the MPI process in QUESO&#39;s full communicator.
Definition: Environment.C:268
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:896
ScopedPtr< boost::program_options::variables_map >::Type m_allOptionsMap
Definition: Environment.h:451
BaseEnvironment(const char *passedOptionsInputFileName, EnvOptionsValues *alternativeOptionsValues)
Default constructor.
Definition: Environment.C:145
RawType_MPI_Group subGroup() const
Access function for sub-group.
Definition: Environment.C:281
bool openUnifiedInputFile(const std::string &fileName, const std::string &fileType, FilePtrSetStruct &filePtrSet) const
Opens the unified input file.
Definition: Environment.C:991
ScopedPtr< boost::program_options::options_description >::Type m_allOptionsDesc
Definition: Environment.h:450
unsigned int syncVerbosity() const
Access function to private attribute m_syncVerbosity.
Definition: Environment.C:457
const MpiComm & subComm() const
Access function for each sub-environment&#39;s communicator.
Definition: Environment.C:293
void queso_terminate_handler()
Function for unhandled exceptions in Queso.
Definition: Environment.C:1731
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:726
const BasicPdfsBase * basicPdfs() const
Access to Basic PDFs.
Definition: Environment.C:490
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:397
std::string m_subIdString
Definition: Environment.h:456
std::ifstream * ifsVar
Provides a stream interface to read data from files.
Definition: Environment.h:89
MPI_Group RawType_MPI_Group
Definition: MpiComm.h:42
void readOptionsInputFile()
Checks the options input file and reads the options.
Definition: Environment.C:1758
std::string m_optionsInputFileName
Definition: Environment.h:447
void QUESO_version_print(std::ostream &os)
Definition: Environment.C:56
std::string identifyingString() const
Access function to private attribute m_identifyingString: identifying string.
Definition: Environment.C:502
unsigned int m_subId
Definition: Environment.h:455
This class provides a suite options one can pass to a QUESO environment.
ScopedPtr< MpiComm >::Type m_selfComm
Definition: Environment.h:462
The QUESO MPI Communicator Class.
Definition: MpiComm.h:203
void resetSeed(int newSeedOption)
Reset RNG seed.
Definition: Environment.C:483
void print(std::ostream &os) const
Sends the environment options to the stream.
Definition: Environment.C:1725
ScopedPtr< MpiComm >::Type m_inter0Comm
Definition: Environment.h:465
unsigned int displayVerbosity() const
Definition: Environment.C:450
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:348
FullEnvironment(RawType_MPI_Comm inputComm, const char *passedOptionsInputFileName, const char *prefix, EnvOptionsValues *alternativeOptionsValues)
Parallel constructor.
Definition: Environment.C:1179
std::ofstream * ofsVar
Provides a stream interface to write data to files.
Definition: Environment.h:86
virtual void print(std::ostream &os) const =0
int QUESO_get_numeric_version()
Definition: Environment.C:86
virtual ~BaseEnvironment()
Destructor.
Definition: Environment.C:222
~FullEnvironment()
Destructor.
Definition: Environment.C:1720
const MpiComm & fullComm() const
Access function for the communicator that was passed to QUESO&#39;s environment.
Definition: Environment.C:274
Struct for handling data input and output from files.
Definition: Environment.h:77
EmptyEnvironment()
Default constructor. Does nothing.
Definition: Environment.C:1158
unsigned int numSubEnvironments() const
Access function to the number of sub-environments.
Definition: Environment.C:335
struct timeval m_timevalBegin
Definition: Environment.h:472
int inter0Rank() const
Returns the process inter0 rank.
Definition: Environment.C:307
~EmptyEnvironment()
Destructor.
Definition: Environment.C:1164
void print(std::ostream &os) const
Definition: Environment.C:1169
ScopedPtr< MpiComm >::Type m_subComm
Definition: Environment.h:458
void setOptionsInputFileAccessState(bool newState) const
Definition: Environment.C:365
bool fullEnvIsReady() const
Returns whether the full environment class is ready (constructor has successfully been called)...
Definition: Environment.C:256
RawType_MPI_Group m_inter0Group
Definition: Environment.h:464
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:521
ScopedPtr< BasicPdfsBase >::Type m_basicPdfs
Definition: Environment.h:471
std::ofstream * subDisplayFile() const
Access function for m_subDisplayFile (displays file on stream).
Definition: Environment.C:320
int seed() const
Access to the RNG seed.
Definition: Environment.C:477
ScopedPtr< std::ofstream >::Type m_subDisplayFile
Definition: Environment.h:469

Generated on Tue Jun 5 2018 19:48:54 for queso-0.57.1 by  doxygen 1.8.5