queso-0.56.1
Private Member Functions | List of all members
QUESO::FullEnvironment Class Reference

This class sets up the full environment underlying the use of the QUESO library by an executable. More...

#include <Environment.h>

Inheritance diagram for QUESO::FullEnvironment:
Inheritance graph
[legend]
Collaboration diagram for QUESO::FullEnvironment:
Collaboration graph
[legend]

Public Member Functions

Constructor/Destructor methods
 FullEnvironment (const char *passedOptionsInputFileName, const char *prefix, EnvOptionsValues *alternativeOptionsValues)
 Parallel constructor. More...
 
 FullEnvironment (const std::string &passedOptionsInputFileName, const std::string &prefix, EnvOptionsValues *alternativeOptionsValues)
 
 ~FullEnvironment ()
 Destructor. More...
 
I/O methods
void print (std::ostream &os) const
 Sends the environment options to the stream. More...
 
- Public Member Functions inherited from QUESO::BaseEnvironment
 BaseEnvironment (const char *passedOptionsInputFileName, EnvOptionsValues *alternativeOptionsValues)
 Default constructor. More...
 
 BaseEnvironment (const std::string &passedOptionsInputFileName, EnvOptionsValues *alternativeOptionsValues)
 
virtual ~BaseEnvironment ()
 Destructor. More...
 
bool fullEnvIsReady () const
 Returns whether the full environment class is ready (constructor has successfully been called). More...
 
int worldRank () const
 Returns the process world rank. More...
 
int fullRank () const
 Returns the process full rank. More...
 
const MpiCommfullComm () const
 Access function for MpiComm full communicator. More...
 
RawType_MPI_Group subGroup () const
 Access function for sub-group. More...
 
int subRank () const
 Access function for sub-rank. More...
 
const MpiCommsubComm () const
 Access function for MpiComm sub communicator. More...
 
const MpiCommselfComm () const
 Access function for MpiComm self-communicator. More...
 
int inter0Rank () const
 Returns the process inter0 rank. More...
 
const MpiComminter0Comm () const
 Access function for MpiComm inter0-communicator. More...
 
std::ofstream * subDisplayFile () const
 Access function for m_subDisplayFile (displays file on stream). More...
 
std::string subDisplayFileName () const
 Access function for m_subDisplayFileName (displays filename on stream). More...
 
unsigned int numSubEnvironments () const
 Access function to the number of sub-environments. More...
 
unsigned int subId () const
 Access function to the number of each sub-environment Id: m_subId. More...
 
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. More...
 
void checkTheParallelEnvironment () const
 
std::string optionsInputFileName () const
 Access to the attribute m_optionsInputFileName, which stores the name of the input file passed by the user to QUESO. More...
 
void setOptionsInputFileAccessState (bool newState) const
 
boost::program_options::variables_map & allOptionsMap () const
 
void scanInputFileForMyOptions (const boost::program_options::options_description &optionsDesc) const
 This method scans the input file provided by the user to QUESO. More...
 
unsigned int displayVerbosity () const
 
unsigned int syncVerbosity () const
 Access function to private attribute m_syncVerbosity. More...
 
unsigned int checkingLevel () const
 Access function to private attribute m_checkingLevel. More...
 
const RngBaserngObject () const
 Access to the RNG object. More...
 
void resetSeed (int newSeedOption)
 Reset RNG seed. More...
 
int seed () const
 Access to the RNG seed. More...
 
const BasicPdfsBasebasicPdfs () const
 Access to Basic PDFs. More...
 
std::string platformName () const
 Access to the platform name. More...
 
std::string identifyingString () const
 Access function to private attribute m_identifyingString: identifying string. More...
 
void resetIdentifyingString (const std::string &newString)
 Reset private attribute m_identifyingString with the value newString. More...
 
bool isThereInputFile () const
 //TODO Not implemented? it is called in examples/validationCycle/tests_old/results_5_25/uqTgaEx4.h. More...
 
struct timeval timevalBegin () const
 Used to save the time when the combo `QUESO+user's application' started to run. More...
 
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. More...
 
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. More...
 
bool openInputFile (const std::string &fileName, const std::string &fileType, const std::set< unsigned int > &allowedSubEnvIds, FilePtrSetStruct &filePtrSet) const
 Opens an input file. More...
 
bool openUnifiedInputFile (const std::string &fileName, const std::string &fileType, FilePtrSetStruct &filePtrSet) const
 Opens the unified input file. More...
 
void closeFile (FilePtrSetStruct &filePtrSet, const std::string &fileType) const
 Closes the file. More...
 
void setExceptionalCircumstance (bool value) const
 Set an exceptional circumstance. More...
 
bool exceptionalCircumstance () const
 Decides whether there is an exceptional circumstance. More...
 
const GetPotinput () const
 The GetPot input file parser. More...
 

Private Member Functions

void construct (const char *prefix)
 Named constructor backend for multiple constructor overloads. More...
 
void readOptionsInputFile ()
 Checks the options input file and reads the options. More...
 

Additional Inherited Members

- Protected Attributes inherited from QUESO::BaseEnvironment
bool m_fullEnvIsReady
 
int m_worldRank
 
MpiCommm_fullComm
 
int m_fullRank
 
int m_fullCommSize
 
RawType_MPI_Group m_fullGroup
 
std::string m_optionsInputFileName
 
bool m_optionsInputFileAccessState
 
boost::program_options::options_description * m_allOptionsDesc
 
boost::program_options::variables_map * m_allOptionsMap
 
ScopedPtr< GetPot >::Type m_input
 
unsigned int m_subId
 
std::string m_subIdString
 
RawType_MPI_Group m_subGroup
 
MpiCommm_subComm
 
int m_subRank
 
int m_subCommSize
 
MpiCommm_selfComm
 
RawType_MPI_Group m_inter0Group
 
MpiCommm_inter0Comm
 
int m_inter0Rank
 
int m_inter0CommSize
 
std::ofstream * m_subDisplayFile
 
RngBasem_rngObject
 
BasicPdfsBasem_basicPdfs
 
struct timeval m_timevalBegin
 
bool m_exceptionalCircumstance
 
EnvOptionsValuesm_optionsObj
 

Detailed Description

This class sets up the full environment underlying the use of the QUESO library by an executable.

This is the class that is actually used during a QUESO+application run.

Definition at line 435 of file Environment.h.

Constructor & Destructor Documentation

QUESO::FullEnvironment::FullEnvironment ( const char *  passedOptionsInputFileName,
const char *  prefix,
EnvOptionsValues alternativeOptionsValues 
)

Parallel constructor.

Initializes the full communicator, reads the options, deals with multiple sub-environments, e.g. dealing with sub/self/inter0-communicators, handles path for output files.Serial constructor.

No communicator is passed. Output path handling is exactly as in the parallel ctor.

Definition at line 1462 of file Environment.C.

References construct().

1466  :
1467  BaseEnvironment(passedOptionsInputFileName,alternativeOptionsValues)
1468 {
1469  this->construct(prefix);
1470 }
BaseEnvironment(const char *passedOptionsInputFileName, EnvOptionsValues *alternativeOptionsValues)
Default constructor.
Definition: Environment.C:141
void construct(const char *prefix)
Named constructor backend for multiple constructor overloads.
Definition: Environment.C:1483
QUESO::FullEnvironment::FullEnvironment ( const std::string &  passedOptionsInputFileName,
const std::string &  prefix,
EnvOptionsValues alternativeOptionsValues 
)

Definition at line 1472 of file Environment.C.

References construct().

1476  :
1477  BaseEnvironment(passedOptionsInputFileName,alternativeOptionsValues)
1478 {
1479  this->construct(prefix.c_str());
1480 }
BaseEnvironment(const char *passedOptionsInputFileName, EnvOptionsValues *alternativeOptionsValues)
Default constructor.
Definition: Environment.C:141
void construct(const char *prefix)
Named constructor backend for multiple constructor overloads.
Definition: Environment.C:1483
QUESO::FullEnvironment::~FullEnvironment ( )

Destructor.

Definition at line 1711 of file Environment.C.

1712 {
1713 }

Member Function Documentation

void QUESO::FullEnvironment::construct ( const char *  prefix)
private

Named constructor backend for multiple constructor overloads.

Definition at line 1483 of file Environment.C.

References QUESO::MpiComm::Barrier(), QUESO::CheckFilePath(), QUESO::BaseEnvironment::displayVerbosity(), QUESO::BaseEnvironment::fullComm(), QUESO::BaseEnvironment::m_allOptionsDesc, QUESO::BaseEnvironment::m_allOptionsMap, QUESO::BaseEnvironment::m_basicPdfs, QUESO::BaseEnvironment::m_fullComm, QUESO::BaseEnvironment::m_fullCommSize, QUESO::BaseEnvironment::m_fullEnvIsReady, QUESO::BaseEnvironment::m_fullGroup, QUESO::BaseEnvironment::m_fullRank, QUESO::EnvOptionsValues::m_help, QUESO::BaseEnvironment::m_input, QUESO::BaseEnvironment::m_inter0Comm, QUESO::BaseEnvironment::m_inter0CommSize, QUESO::BaseEnvironment::m_inter0Group, QUESO::BaseEnvironment::m_inter0Rank, QUESO::EnvOptionsValues::m_numSubEnvironments, QUESO::BaseEnvironment::m_optionsInputFileName, QUESO::BaseEnvironment::m_optionsObj, QUESO::BaseEnvironment::m_rngObject, QUESO::EnvOptionsValues::m_rngType, QUESO::EnvOptionsValues::m_seed, QUESO::BaseEnvironment::m_selfComm, QUESO::BaseEnvironment::m_subComm, QUESO::BaseEnvironment::m_subCommSize, QUESO::EnvOptionsValues::m_subDisplayAllowAll, QUESO::EnvOptionsValues::m_subDisplayAllowedSet, QUESO::EnvOptionsValues::m_subDisplayAllowInter0, QUESO::BaseEnvironment::m_subDisplayFile, QUESO::EnvOptionsValues::m_subDisplayFileName, QUESO::BaseEnvironment::m_subGroup, QUESO::BaseEnvironment::m_subId, QUESO::BaseEnvironment::m_subIdString, QUESO::BaseEnvironment::m_subRank, QUESO::BaseEnvironment::m_timevalBegin, QUESO::old_terminate_handler, queso_error_msg, queso_require_equal_to_msg, queso_require_greater_equal_msg, queso_require_msg, QUESO::queso_terminate_handler(), QUESO::QUESO_version_print(), readOptionsInputFile(), and UQ_ENV_FILENAME_FOR_NO_OUTPUT_FILE.

Referenced by FullEnvironment().

1484 {
1485 #ifdef QUESO_MEMORY_DEBUGGING
1486  std::cout << "Entering FullEnv" << std::endl;
1487 #endif
1488 
1489  m_worldRank = 0;
1490 
1491  m_fullComm = new MpiComm(*this);
1492  m_fullRank = 0;
1493  m_fullCommSize = 1;
1494 
1495 #ifndef QUESO_HAS_MPI
1496  m_fullGroup = 0;
1497 #endif
1498 
1499  // saving old uncaught exception handler, invoking queso_terminate
1500  old_terminate_handler = std::set_terminate(queso_terminate_handler);
1501 
1502 #ifdef QUESO_MEMORY_DEBUGGING
1503  std::cout << "In FullEnv, finished dealing with MPI initially" << std::endl;
1504 #endif
1505 
1507  // Read options
1509  // If NULL, we create one
1510  if (m_optionsObj == NULL) {
1511  // If there's an input file, we grab the options from there. Otherwise the
1512  // defaults are used
1513  if (m_optionsInputFileName != "") {
1514 #ifndef DISABLE_BOOST_PROGRAM_OPTIONS
1515  m_allOptionsMap = new boost::program_options::variables_map();
1516  m_allOptionsDesc = new boost::program_options::options_description("Allowed options");
1517 #endif // DISABLE_BOOST_PROGRAM_OPTIONS
1518 
1520 
1521  m_input->parse_input_file(m_optionsInputFileName);
1522  }
1523 
1524  EnvOptionsValues * tempOptions = new EnvOptionsValues(this, prefix);
1525 
1526  // We did this dance because scanOptionsValues is not a const method, but
1527  // m_optionsObj is a pointer to const
1528  m_optionsObj = tempOptions;
1529  }
1530 
1531  // If help option was supplied, print info
1532  if (m_optionsObj->m_help != "") {
1533  // We write to std::cout because subDisplayFile() isn't ready yet?
1534  std::cout << (*m_optionsObj) << std::endl;
1535  }
1536 
1538  fullComm().NumProc() % m_optionsObj->m_numSubEnvironments, 0,
1539  "total number of processors in environment must be multiple of the specified number of subEnvironments");
1540 
1541 #ifdef QUESO_MEMORY_DEBUGGING
1542  std::cout << "In FullEnv, finished scanning options" << std::endl;
1543 #endif
1544 
1545  // Only display these messages if the user wants them
1546  // NOTE: This got moved below the Read Options section
1547  // because we need the options to be read to know what
1548  // the verbosity level is.
1549  if (this->displayVerbosity() > 0) {
1551  // Display main initial messages
1552  // 'std::cout' is for: main trace messages + synchronized trace messages + error messages prior to 'exit()' or 'abort()'
1554  /*int iRC = 0;*/
1555  /*iRC = */gettimeofday(&m_timevalBegin, NULL);
1556 
1557  QUESO_version_print(std::cout);
1558 
1559  std::cout << "Beginning run at " << ctime(&m_timevalBegin.tv_sec)
1560  << std::endl;
1561  }
1562 
1563  m_subId = 0;
1564  char tmpSubId[16];
1565  sprintf(tmpSubId,"%u",m_subId);
1566  m_subIdString = tmpSubId;
1567 
1569  m_optionsObj->m_subDisplayAllowedSet.insert((unsigned int) m_subId);
1570  }
1571 
1572  int fullRanksOfMySubEnvironment = 1;
1573 
1574 #ifndef QUESO_HAS_MPI
1575  m_subGroup = 0;
1576 #endif
1577 
1578  m_subComm = new MpiComm(*this);
1579  m_subRank = 0;
1580  m_subCommSize = 1;
1581 
1583  // Deal with multiple subEnvironments: create the self communicator
1585  m_selfComm = new MpiComm(*this);
1586 
1588  // Deal with multiple subEnvironments: create the inter0 communicator
1590  int fullRanksOfInter0 = 0;
1591 #ifndef QUESO_HAS_MPI
1592  m_inter0Group = 0;
1593 #endif
1594  m_inter0Comm = new MpiComm(*this);
1595  m_inter0Rank = 0;
1596  m_inter0CommSize = 1;
1597 
1599  // This situation has been already taken care of above
1600  }
1602  if (m_inter0Rank >= 0) {
1603  m_optionsObj->m_subDisplayAllowedSet.insert((unsigned int) m_subId);
1604  }
1605  }
1606 
1607 
1609  // Open "screen" file
1611  bool openFile = false;
1612  if ((m_subRank == 0 ) &&
1615  openFile = true;
1616  }
1617 
1618  if (openFile && m_worldRank == 0) {
1620  // Verify parent directory exists (for cases when a user
1621  // specifies a relative path for the desired output file).
1623  int irtrn = CheckFilePath((m_optionsObj->m_subDisplayFileName+"_sub"+m_subIdString+".txt").c_str());
1624  queso_require_greater_equal_msg(irtrn, 0, "unable to verify output path");
1625  }
1626 
1628  // Ensure that rank 0 has created path, if necessary, before other tasks use it
1630  m_fullComm->Barrier();
1631 
1632  if (openFile) {
1634  // Always write over an eventual pre-existing file
1636  m_subDisplayFile = new std::ofstream((m_optionsObj->m_subDisplayFileName+"_sub"+m_subIdString+".txt").c_str(),
1637  std::ofstream::out | std::ofstream::trunc);
1638  queso_require_msg((m_subDisplayFile && m_subDisplayFile->is_open()), "failed to open sub screen file");
1639 
1641 
1642  *m_subDisplayFile << "Beginning run at " << ctime(&m_timevalBegin.tv_sec)
1643  << std::endl;
1644  }
1645 
1647  // Debug message related to subEnvironments
1649  if (this->displayVerbosity() >= 2) {
1650  for (int i = 0; i < m_fullCommSize; ++i) {
1651  if (i == m_fullRank) {
1652  //std::cout << "In FullEnvironment::commonConstructor()"
1653  std::cout << "MPI node of worldRank " << m_worldRank
1654  << " has fullRank " << m_fullRank
1655  << ", belongs to subEnvironment of id " << m_subId
1656  << ", and has subRank " << m_subRank
1657  << std::endl;
1658 
1659  std::cout << "MPI node of worldRank " << m_worldRank
1660  << " belongs to sub communicator with full ranks";
1661  std::cout << " " << fullRanksOfMySubEnvironment;
1662  std::cout << "\n";
1663 
1664  if (m_inter0Comm) {
1665  std::cout << "MPI node of worldRank " << m_worldRank
1666  << " also belongs to inter0 communicator with full ranks";
1667  std::cout << " " << fullRanksOfInter0;
1668  std::cout << ", and has inter0Rank " << m_inter0Rank;
1669  }
1670  std::cout << "\n";
1671 
1672  std::cout << std::endl;
1673  }
1674  m_fullComm->Barrier();
1675  }
1676  }
1677 
1679  // Deal with seed
1681  if (m_optionsObj->m_rngType == "gsl") {
1683  m_basicPdfs = new BasicPdfsGsl(m_worldRank);
1684  }
1685  else if (m_optionsObj->m_rngType == "boost") {
1687  m_basicPdfs = new BasicPdfsBoost(m_worldRank);
1688  }
1689  else {
1690  std::cerr << "In Environment::constructor()"
1691  << ": rngType = " << m_optionsObj->m_rngType
1692  << std::endl;
1693  queso_error_msg("the requested 'rngType' is not supported yet");
1694  }
1695 
1697  // Leave commonConstructor()
1699  m_fullComm->Barrier();
1700  m_fullEnvIsReady = true;
1701 
1702  if ((m_subDisplayFile) && (this->displayVerbosity() >= 5)) {
1703  *m_subDisplayFile << "Done with initializations at FullEnvironment::commonConstructor()"
1704  << std::endl;
1705  }
1706 
1707  return;
1708 }
std::string m_optionsInputFileName
Definition: Environment.h:374
EnvOptionsValues * m_optionsObj
Definition: Environment.h:402
struct timeval m_timevalBegin
Definition: Environment.h:399
void Barrier() const
Pause every process in *this communicator until all the processes reach this point.
Definition: MpiComm.C:164
#define queso_require_greater_equal_msg(expr1, expr2, msg)
Definition: asserts.h:78
bool m_subDisplayAllowAll
Allows (or not) all sub-environments to write to output file.
boost::program_options::variables_map * m_allOptionsMap
Definition: Environment.h:378
RawType_MPI_Group m_subGroup
Definition: Environment.h:384
std::ofstream * m_subDisplayFile
Definition: Environment.h:396
int CheckFilePath(const char *path)
Class for random number generation using Boost library.
#define queso_require_equal_to_msg(expr1, expr2, msg)
Definition: asserts.h:73
std::string m_subIdString
Definition: Environment.h:383
Class for random number generation using GSL library.
boost::program_options::options_description * m_allOptionsDesc
Definition: Environment.h:377
std::terminate_handler old_terminate_handler
Definition: Environment.C:135
unsigned int m_subId
Definition: Environment.h:382
std::string m_subDisplayFileName
Output filename for sub-screen writing.
std::set< unsigned int > m_subDisplayAllowedSet
Sub-environments that will write to output.
void readOptionsInputFile()
Checks the options input file and reads the options.
Definition: Environment.C:1749
void queso_terminate_handler()
Function for unhandled exceptions in Queso.
Definition: Environment.C:1722
void QUESO_version_print(std::ostream &os)
Definition: Environment.C:54
std::string m_rngType
Type of the random number generator.
ScopedPtr< GetPot >::Type m_input
Definition: Environment.h:380
unsigned int displayVerbosity() const
Definition: Environment.C:449
RawType_MPI_Group m_fullGroup
Definition: Environment.h:372
#define queso_require_msg(asserted, msg)
Definition: asserts.h:69
const MpiComm & fullComm() const
Access function for MpiComm full communicator.
Definition: Environment.C:274
int m_seed
Seed of the random number generator.
RawType_MPI_Group m_inter0Group
Definition: Environment.h:391
#define queso_error_msg(msg)
Definition: asserts.h:47
#define UQ_ENV_FILENAME_FOR_NO_OUTPUT_FILE
BasicPdfsBase * m_basicPdfs
Definition: Environment.h:398
bool m_subDisplayAllowInter0
Allows (or not) all inter0 nodes to write to output file.
void QUESO::FullEnvironment::print ( std::ostream &  os) const
virtual

Sends the environment options to the stream.

Implements QUESO::BaseEnvironment.

Definition at line 1716 of file Environment.C.

1717 {
1718  os.flush(); // just to avoid icpc warnings
1719  return;
1720 }
void QUESO::FullEnvironment::readOptionsInputFile ( )
private

Checks the options input file and reads the options.

Definition at line 1749 of file Environment.C.

References QUESO::BaseEnvironment::m_fullRank, QUESO::BaseEnvironment::m_optionsInputFileName, and queso_error.

Referenced by construct().

1750 {
1751  std::ifstream* ifs = new std::ifstream(m_optionsInputFileName.c_str());
1752  if (ifs->is_open()) {
1753  //ifs->close();
1754  delete ifs;
1755  }
1756  else {
1757  if (m_fullRank == 0) std::cout << "An invalid input file has been passed to the 'environment' class constructor!"
1758  << ": name of file is '" << m_optionsInputFileName.c_str() << "'"
1759  << std::endl;
1760 
1761  if (m_fullRank == 0) std::cout << "\nThis is a help message of the QUESO library."
1762  << "\nAn application using the QUESO library shall be executed by typing"
1763  << "\n '<eventual mpi commands and options> <Application> <InputFile>'"
1764  << "\nin the command line."
1765  << "\n"
1766  << std::endl;
1767  queso_error();
1768  }
1769 
1770  return;
1771 }
std::string m_optionsInputFileName
Definition: Environment.h:374
#define queso_error()
Definition: asserts.h:53

The documentation for this class was generated from the following files:

Generated on Thu Dec 15 2016 13:23:13 for queso-0.56.1 by  doxygen 1.8.5