queso-0.54.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 1377 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.

1381  :
1382  BaseEnvironment(passedOptionsInputFileName,alternativeOptionsValues)
1383 {
1384 #ifdef QUESO_MEMORY_DEBUGGING
1385  std::cout << "Entering FullEnv" << std::endl;
1386 #endif
1387 
1388  m_worldRank = 0;
1389 
1390  m_fullComm = new MpiComm(*this);
1391  m_fullRank = 0;
1392  m_fullCommSize = 1;
1393 
1394 #ifndef QUESO_HAS_MPI
1395  m_fullGroup = 0;
1396 #endif
1397 
1398  // saving old uncaught exception handler, invoking queso_terminate
1399  old_terminate_handler = std::set_terminate(queso_terminate_handler);
1400 
1401 #ifdef QUESO_MEMORY_DEBUGGING
1402  std::cout << "In FullEnv, finished dealing with MPI initially" << std::endl;
1403 #endif
1404 
1406  // Read options
1408  // If NULL, we create one
1409  if (m_optionsObj == NULL) {
1410  EnvOptionsValues * tempOptions = new EnvOptionsValues(this, prefix);
1411 
1412  // If there's an input file, we grab the options from there. Otherwise the
1413  // defaults are used
1414  if (m_optionsInputFileName != "") {
1415  m_allOptionsMap = new boost::program_options::variables_map();
1416  m_allOptionsDesc = new boost::program_options::options_description("Allowed options");
1417 
1419  }
1420 
1421  // We did this dance because scanOptionsValues is not a const method, but
1422  // m_optionsObj is a pointer to const
1423  m_optionsObj = tempOptions;
1424  }
1425 
1426  // If help option was supplied, print info
1427  if (m_optionsObj->m_help != "") {
1428  // We write to std::cout because subDisplayFile() isn't ready yet?
1429  std::cout << (*m_optionsObj) << std::endl;
1430  }
1431 
1433  fullComm().NumProc() % m_optionsObj->m_numSubEnvironments, 0,
1434  "total number of processors in environment must be multiple of the specified number of subEnvironments");
1435 
1436 #ifdef QUESO_MEMORY_DEBUGGING
1437  std::cout << "In FullEnv, finished scanning options" << std::endl;
1438 #endif
1439 
1440  // Only display these messages if the user wants them
1441  // NOTE: This got moved below the Read Options section
1442  // because we need the options to be read to know what
1443  // the verbosity level is.
1444  if (this->displayVerbosity() > 0) {
1446  // Display main initial messages
1447  // 'std::cout' is for: main trace messages + synchronized trace messages + error messages prior to 'exit()' or 'abort()'
1449  /*int iRC = 0;*/
1450  /*iRC = */gettimeofday(&m_timevalBegin, NULL);
1451 
1452  QUESO_version_print(std::cout);
1453 
1454  std::cout << "Beginning run at " << ctime(&m_timevalBegin.tv_sec)
1455  << std::endl;
1456  }
1457 
1458  m_subId = 0;
1459  char tmpSubId[16];
1460  sprintf(tmpSubId,"%u",m_subId);
1461  m_subIdString = tmpSubId;
1462 
1464  m_optionsObj->m_subDisplayAllowedSet.insert((unsigned int) m_subId);
1465  }
1466 
1467  int fullRanksOfMySubEnvironment = 1;
1468 
1469 #ifndef QUESO_HAS_MPI
1470  m_subGroup = 0;
1471 #endif
1472 
1473  m_subComm = new MpiComm(*this);
1474  m_subRank = 0;
1475  m_subCommSize = 1;
1476 
1478  // Deal with multiple subEnvironments: create the self communicator
1480  m_selfComm = new MpiComm(*this);
1481 
1483  // Deal with multiple subEnvironments: create the inter0 communicator
1485  int fullRanksOfInter0 = 0;
1486 #ifndef QUESO_HAS_MPI
1487  m_inter0Group = 0;
1488 #endif
1489  m_inter0Comm = new MpiComm(*this);
1490  m_inter0Rank = 0;
1491  m_inter0CommSize = 1;
1492 
1494  // This situation has been already taken care of above
1495  }
1497  if (m_inter0Rank >= 0) {
1498  m_optionsObj->m_subDisplayAllowedSet.insert((unsigned int) m_subId);
1499  }
1500  }
1501 
1502 
1504  // Open "screen" file
1506  bool openFile = false;
1507  if ((m_subRank == 0 ) &&
1510  openFile = true;
1511  }
1512 
1513  if (openFile && m_worldRank == 0) {
1515  // Verify parent directory exists (for cases when a user
1516  // specifies a relative path for the desired output file).
1518  int irtrn = CheckFilePath((m_optionsObj->m_subDisplayFileName+"_sub"+m_subIdString+".txt").c_str());
1519  queso_require_greater_equal_msg(irtrn, 0, "unable to verify output path");
1520  }
1521 
1523  // Ensure that rank 0 has created path, if necessary, before other tasks use it
1525  m_fullComm->Barrier();
1526 
1527  if (openFile) {
1529  // Always write over an eventual pre-existing file
1531  m_subDisplayFile = new std::ofstream((m_optionsObj->m_subDisplayFileName+"_sub"+m_subIdString+".txt").c_str(),
1532  std::ofstream::out | std::ofstream::trunc);
1533  queso_require_msg((m_subDisplayFile && m_subDisplayFile->is_open()), "failed to open sub screen file");
1534 
1536 
1537  *m_subDisplayFile << "Beginning run at " << ctime(&m_timevalBegin.tv_sec)
1538  << std::endl;
1539  }
1540 
1542  // Debug message related to subEnvironments
1544  if (this->displayVerbosity() >= 2) {
1545  for (int i = 0; i < m_fullCommSize; ++i) {
1546  if (i == m_fullRank) {
1547  //std::cout << "In FullEnvironment::commonConstructor()"
1548  std::cout << "MPI node of worldRank " << m_worldRank
1549  << " has fullRank " << m_fullRank
1550  << ", belongs to subEnvironment of id " << m_subId
1551  << ", and has subRank " << m_subRank
1552  << std::endl;
1553 
1554  std::cout << "MPI node of worldRank " << m_worldRank
1555  << " belongs to sub communicator with full ranks";
1556  std::cout << " " << fullRanksOfMySubEnvironment;
1557  std::cout << "\n";
1558 
1559  if (m_inter0Comm) {
1560  std::cout << "MPI node of worldRank " << m_worldRank
1561  << " also belongs to inter0 communicator with full ranks";
1562  std::cout << " " << fullRanksOfInter0;
1563  std::cout << ", and has inter0Rank " << m_inter0Rank;
1564  }
1565  std::cout << "\n";
1566 
1567  std::cout << std::endl;
1568  }
1569  m_fullComm->Barrier();
1570  }
1571  }
1572 
1574  // Deal with seed
1576  if (m_optionsObj->m_rngType == "gsl") {
1578  m_basicPdfs = new BasicPdfsGsl(m_worldRank);
1579  }
1580  else if (m_optionsObj->m_rngType == "boost") {
1582  m_basicPdfs = new BasicPdfsBoost(m_worldRank);
1583  }
1584  else {
1585  std::cerr << "In Environment::constructor()"
1586  << ": rngType = " << m_optionsObj->m_rngType
1587  << std::endl;
1588  queso_error_msg("the requested 'rngType' is not supported yet");
1589  }
1590 
1592  // Leave commonConstructor()
1594  m_fullComm->Barrier();
1595  m_fullEnvIsReady = true;
1596 
1597  if ((m_subDisplayFile) && (this->displayVerbosity() >= 5)) {
1598  *m_subDisplayFile << "Done with initializations at FullEnvironment::commonConstructor()"
1599  << std::endl;
1600  }
1601 
1602  return;
1603 }
unsigned int displayVerbosity() const
Definition: Environment.C:396
void readOptionsInputFile()
Checks the options input file and reads the options.
Definition: Environment.C:1644
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:228
void queso_terminate_handler()
Function for unhandled exceptions in Queso.
Definition: Environment.C:1617
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:126
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:132
QUESO::FullEnvironment::~FullEnvironment ( )

Destructor.

Definition at line 1606 of file Environment.C.

1607 {
1608 }

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 1611 of file Environment.C.

1612 {
1613  os.flush(); // just to avoid icpc warnings
1614  return;
1615 }
void QUESO::FullEnvironment::readOptionsInputFile ( )
private

Checks the options input file and reads the options.

Definition at line 1644 of file Environment.C.

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

Referenced by FullEnvironment().

1645 {
1646  std::ifstream* ifs = new std::ifstream(m_optionsInputFileName.c_str());
1647  if (ifs->is_open()) {
1648  //ifs->close();
1649  delete ifs;
1650  }
1651  else {
1652  if (m_fullRank == 0) std::cout << "An invalid input file has been passed to the 'environment' class constructor!"
1653  << ": name of file is '" << m_optionsInputFileName.c_str() << "'"
1654  << std::endl;
1655 
1656  if (m_fullRank == 0) std::cout << "\nThis is a help message of the QUESO library."
1657  << "\nAn application using the QUESO library shall be executed by typing"
1658  << "\n '<eventual mpi commands and options> <Application> <InputFile>'"
1659  << "\nin the command line."
1660  << "\n"
1661  << std::endl;
1662  queso_error();
1663  }
1664 
1665  return;
1666 }
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:10:52 for queso-0.54.0 by  doxygen 1.8.5