queso-0.55.0
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 ()
 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...
 
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...
 

Private Member Functions

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
 
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 416 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 1385 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_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.

1389  :
1390  BaseEnvironment(passedOptionsInputFileName,alternativeOptionsValues)
1391 {
1392 #ifdef QUESO_MEMORY_DEBUGGING
1393  std::cout << "Entering FullEnv" << std::endl;
1394 #endif
1395 
1396  m_worldRank = 0;
1397 
1398  m_fullComm = new MpiComm(*this);
1399  m_fullRank = 0;
1400  m_fullCommSize = 1;
1401 
1402 #ifndef QUESO_HAS_MPI
1403  m_fullGroup = 0;
1404 #endif
1405 
1406  // saving old uncaught exception handler, invoking queso_terminate
1407  old_terminate_handler = std::set_terminate(queso_terminate_handler);
1408 
1409 #ifdef QUESO_MEMORY_DEBUGGING
1410  std::cout << "In FullEnv, finished dealing with MPI initially" << std::endl;
1411 #endif
1412 
1414  // Read options
1416  // If NULL, we create one
1417  if (m_optionsObj == NULL) {
1418  EnvOptionsValues * tempOptions = new EnvOptionsValues(this, prefix);
1419 
1420  // If there's an input file, we grab the options from there. Otherwise the
1421  // defaults are used
1422  if (m_optionsInputFileName != "") {
1423  m_allOptionsMap = new boost::program_options::variables_map();
1424  m_allOptionsDesc = new boost::program_options::options_description("Allowed options");
1425 
1427  }
1428 
1429  // We did this dance because scanOptionsValues is not a const method, but
1430  // m_optionsObj is a pointer to const
1431  m_optionsObj = tempOptions;
1432  }
1433 
1434  // If help option was supplied, print info
1435  if (m_optionsObj->m_help != "") {
1436  // We write to std::cout because subDisplayFile() isn't ready yet?
1437  std::cout << (*m_optionsObj) << std::endl;
1438  }
1439 
1441  fullComm().NumProc() % m_optionsObj->m_numSubEnvironments, 0,
1442  "total number of processors in environment must be multiple of the specified number of subEnvironments");
1443 
1444 #ifdef QUESO_MEMORY_DEBUGGING
1445  std::cout << "In FullEnv, finished scanning options" << std::endl;
1446 #endif
1447 
1448  // Only display these messages if the user wants them
1449  // NOTE: This got moved below the Read Options section
1450  // because we need the options to be read to know what
1451  // the verbosity level is.
1452  if (this->displayVerbosity() > 0) {
1454  // Display main initial messages
1455  // 'std::cout' is for: main trace messages + synchronized trace messages + error messages prior to 'exit()' or 'abort()'
1457  /*int iRC = 0;*/
1458  /*iRC = */gettimeofday(&m_timevalBegin, NULL);
1459 
1460  QUESO_version_print(std::cout);
1461 
1462  std::cout << "Beginning run at " << ctime(&m_timevalBegin.tv_sec)
1463  << std::endl;
1464  }
1465 
1466  m_subId = 0;
1467  char tmpSubId[16];
1468  sprintf(tmpSubId,"%u",m_subId);
1469  m_subIdString = tmpSubId;
1470 
1472  m_optionsObj->m_subDisplayAllowedSet.insert((unsigned int) m_subId);
1473  }
1474 
1475  int fullRanksOfMySubEnvironment = 1;
1476 
1477 #ifndef QUESO_HAS_MPI
1478  m_subGroup = 0;
1479 #endif
1480 
1481  m_subComm = new MpiComm(*this);
1482  m_subRank = 0;
1483  m_subCommSize = 1;
1484 
1486  // Deal with multiple subEnvironments: create the self communicator
1488  m_selfComm = new MpiComm(*this);
1489 
1491  // Deal with multiple subEnvironments: create the inter0 communicator
1493  int fullRanksOfInter0 = 0;
1494 #ifndef QUESO_HAS_MPI
1495  m_inter0Group = 0;
1496 #endif
1497  m_inter0Comm = new MpiComm(*this);
1498  m_inter0Rank = 0;
1499  m_inter0CommSize = 1;
1500 
1502  // This situation has been already taken care of above
1503  }
1505  if (m_inter0Rank >= 0) {
1506  m_optionsObj->m_subDisplayAllowedSet.insert((unsigned int) m_subId);
1507  }
1508  }
1509 
1510 
1512  // Open "screen" file
1514  bool openFile = false;
1515  if ((m_subRank == 0 ) &&
1518  openFile = true;
1519  }
1520 
1521  if (openFile && m_worldRank == 0) {
1523  // Verify parent directory exists (for cases when a user
1524  // specifies a relative path for the desired output file).
1526  int irtrn = CheckFilePath((m_optionsObj->m_subDisplayFileName+"_sub"+m_subIdString+".txt").c_str());
1527  queso_require_greater_equal_msg(irtrn, 0, "unable to verify output path");
1528  }
1529 
1531  // Ensure that rank 0 has created path, if necessary, before other tasks use it
1533  m_fullComm->Barrier();
1534 
1535  if (openFile) {
1537  // Always write over an eventual pre-existing file
1539  m_subDisplayFile = new std::ofstream((m_optionsObj->m_subDisplayFileName+"_sub"+m_subIdString+".txt").c_str(),
1540  std::ofstream::out | std::ofstream::trunc);
1541  queso_require_msg((m_subDisplayFile && m_subDisplayFile->is_open()), "failed to open sub screen file");
1542 
1544 
1545  *m_subDisplayFile << "Beginning run at " << ctime(&m_timevalBegin.tv_sec)
1546  << std::endl;
1547  }
1548 
1550  // Debug message related to subEnvironments
1552  if (this->displayVerbosity() >= 2) {
1553  for (int i = 0; i < m_fullCommSize; ++i) {
1554  if (i == m_fullRank) {
1555  //std::cout << "In FullEnvironment::commonConstructor()"
1556  std::cout << "MPI node of worldRank " << m_worldRank
1557  << " has fullRank " << m_fullRank
1558  << ", belongs to subEnvironment of id " << m_subId
1559  << ", and has subRank " << m_subRank
1560  << std::endl;
1561 
1562  std::cout << "MPI node of worldRank " << m_worldRank
1563  << " belongs to sub communicator with full ranks";
1564  std::cout << " " << fullRanksOfMySubEnvironment;
1565  std::cout << "\n";
1566 
1567  if (m_inter0Comm) {
1568  std::cout << "MPI node of worldRank " << m_worldRank
1569  << " also belongs to inter0 communicator with full ranks";
1570  std::cout << " " << fullRanksOfInter0;
1571  std::cout << ", and has inter0Rank " << m_inter0Rank;
1572  }
1573  std::cout << "\n";
1574 
1575  std::cout << std::endl;
1576  }
1577  m_fullComm->Barrier();
1578  }
1579  }
1580 
1582  // Deal with seed
1584  if (m_optionsObj->m_rngType == "gsl") {
1586  m_basicPdfs = new BasicPdfsGsl(m_worldRank);
1587  }
1588  else if (m_optionsObj->m_rngType == "boost") {
1590  m_basicPdfs = new BasicPdfsBoost(m_worldRank);
1591  }
1592  else {
1593  std::cerr << "In Environment::constructor()"
1594  << ": rngType = " << m_optionsObj->m_rngType
1595  << std::endl;
1596  queso_error_msg("the requested 'rngType' is not supported yet");
1597  }
1598 
1600  // Leave commonConstructor()
1602  m_fullComm->Barrier();
1603  m_fullEnvIsReady = true;
1604 
1605  if ((m_subDisplayFile) && (this->displayVerbosity() >= 5)) {
1606  *m_subDisplayFile << "Done with initializations at FullEnvironment::commonConstructor()"
1607  << std::endl;
1608  }
1609 
1610  return;
1611 }
unsigned int displayVerbosity() const
Definition: Environment.C:400
void readOptionsInputFile()
Checks the options input file and reads the options.
Definition: Environment.C:1652
bool m_subDisplayAllowAll
Allows (or not) all sub-environments to write to output file.
bool m_subDisplayAllowInter0
Allows (or not) all inter0 nodes to write to output file.
#define UQ_ENV_FILENAME_FOR_NO_OUTPUT_FILE
BasicPdfsBase * m_basicPdfs
Definition: Environment.h:379
#define queso_error_msg(msg)
Definition: asserts.h:47
boost::program_options::variables_map * m_allOptionsMap
Definition: Environment.h:361
std::string m_optionsInputFileName
Definition: Environment.h:358
const MpiComm & fullComm() const
Access function for MpiComm full communicator.
Definition: Environment.C:232
void queso_terminate_handler()
Function for unhandled exceptions in Queso.
Definition: Environment.C:1625
void QUESO_version_print(std::ostream &os)
Definition: Environment.C:49
EnvOptionsValues * m_optionsObj
Definition: Environment.h:383
#define queso_require_msg(asserted, msg)
Definition: asserts.h:69
Class for random number generation using Boost library.
#define queso_require_equal_to_msg(expr1, expr2, msg)
Definition: asserts.h:85
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:90
std::set< unsigned int > m_subDisplayAllowedSet
Sub-environments that will write to output.
std::terminate_handler old_terminate_handler
Definition: Environment.C:130
std::string m_subIdString
Definition: Environment.h:364
RawType_MPI_Group m_fullGroup
Definition: Environment.h:356
unsigned int m_subId
Definition: Environment.h:363
std::string m_rngType
Type of the random number generator.
boost::program_options::options_description * m_allOptionsDesc
Definition: Environment.h:360
int CheckFilePath(const char *path)
struct timeval m_timevalBegin
Definition: Environment.h:380
std::ofstream * m_subDisplayFile
Definition: Environment.h:377
RawType_MPI_Group m_inter0Group
Definition: Environment.h:372
Class for random number generation using GSL library.
std::string m_subDisplayFileName
Output filename for sub-screen writing.
int m_seed
Seed of the random number generator.
RawType_MPI_Group m_subGroup
Definition: Environment.h:365
BaseEnvironment(const char *passedOptionsInputFileName, EnvOptionsValues *alternativeOptionsValues)
Default constructor.
Definition: Environment.C:136
QUESO::FullEnvironment::~FullEnvironment ( )

Destructor.

Definition at line 1614 of file Environment.C.

1615 {
1616 }

Member Function Documentation

void QUESO::FullEnvironment::print ( std::ostream &  os) const
virtual

Sends the environment options to the stream.

Implements QUESO::BaseEnvironment.

Definition at line 1619 of file Environment.C.

1620 {
1621  os.flush(); // just to avoid icpc warnings
1622  return;
1623 }
void QUESO::FullEnvironment::readOptionsInputFile ( )
private

Checks the options input file and reads the options.

Definition at line 1652 of file Environment.C.

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

Referenced by FullEnvironment().

1653 {
1654  std::ifstream* ifs = new std::ifstream(m_optionsInputFileName.c_str());
1655  if (ifs->is_open()) {
1656  //ifs->close();
1657  delete ifs;
1658  }
1659  else {
1660  if (m_fullRank == 0) std::cout << "An invalid input file has been passed to the 'environment' class constructor!"
1661  << ": name of file is '" << m_optionsInputFileName.c_str() << "'"
1662  << std::endl;
1663 
1664  if (m_fullRank == 0) std::cout << "\nThis is a help message of the QUESO library."
1665  << "\nAn application using the QUESO library shall be executed by typing"
1666  << "\n '<eventual mpi commands and options> <Application> <InputFile>'"
1667  << "\nin the command line."
1668  << "\n"
1669  << std::endl;
1670  queso_error();
1671  }
1672 
1673  return;
1674 }
std::string m_optionsInputFileName
Definition: Environment.h:358
#define queso_error()
Definition: asserts.h:53

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

Generated on Fri Jun 17 2016 14:17:43 for queso-0.55.0 by  doxygen 1.8.5