queso-0.53.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 (RawType_MPI_Comm inputComm, const char *passedOptionsInputFileName, const char *prefix, EnvOptionsValues *alternativeOptionsValues)
 Default 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 ( RawType_MPI_Comm  inputComm,
const char *  passedOptionsInputFileName,
const char *  prefix,
EnvOptionsValues alternativeOptionsValues 
)

Default constructor.

It 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.

Definition at line 1107 of file Environment.C.

References QUESO::MpiComm::Barrier(), QUESO::CheckFilePath(), QUESO::MpiComm::Comm(), 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::BaseEnvironment::m_worldRank, QUESO::MpiComm::MyPID(), QUESO::MpiComm::NumProc(), 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(), RawValue_MPI_COMM_SELF, readOptionsInputFile(), and UQ_ENV_FILENAME_FOR_NO_OUTPUT_FILE.

1112  :
1113  BaseEnvironment(passedOptionsInputFileName,alternativeOptionsValues)
1114 {
1115 #ifdef QUESO_MEMORY_DEBUGGING
1116  std::cout << "Entering FullEnv" << std::endl;
1117 #endif
1118 
1120  // Initialize "full" communicator -- Not necessarily MPI_COMM_WORLD
1122  int mpiRC = MPI_Comm_rank(inputComm,&m_worldRank);
1123  queso_require_equal_to_msg(mpiRC, MPI_SUCCESS, "failed to get world fullRank()");
1124 
1125  m_fullComm = new MpiComm(*this,inputComm);
1128 
1129  mpiRC = MPI_Comm_group(m_fullComm->Comm(), &m_fullGroup);
1130  queso_require_equal_to_msg(mpiRC, MPI_SUCCESS, "failed MPI_Comm_group()");
1131 
1132  // saving old uncaught exception handler, invoking queso_terminate
1133  old_terminate_handler = std::set_terminate(queso_terminate_handler);
1134 
1135 #ifdef QUESO_MEMORY_DEBUGGING
1136  std::cout << "In FullEnv, finished dealing with MPI initially" << std::endl;
1137 #endif
1138 
1140  // Read options
1142  // If NULL, we create one
1143  if (m_optionsObj == NULL) {
1144  EnvOptionsValues * tempOptions = new EnvOptionsValues(this, prefix);
1145 
1146  // If there's an input file, we grab the options from there. Otherwise the
1147  // defaults are used
1148  if (m_optionsInputFileName != "") {
1149  m_allOptionsMap = new boost::program_options::variables_map();
1150  m_allOptionsDesc = new boost::program_options::options_description("Allowed options");
1151 
1153  }
1154 
1155  // We did this dance because scanOptionsValues is not a const method, but
1156  // m_optionsObj is a pointer to const
1157  m_optionsObj = tempOptions;
1158  }
1159 
1160  // If help option was supplied, print info
1161  if (m_optionsObj->m_help != "") {
1162  // We write to std::cout because subDisplayFile() isn't ready yet?
1163  std::cout << (*m_optionsObj) << std::endl;
1164  }
1165 
1167  fullComm().NumProc() % m_optionsObj->m_numSubEnvironments, 0,
1168  "total number of processors in environment must be multiple of the specified number of subEnvironments");
1169 
1170 #ifdef QUESO_MEMORY_DEBUGGING
1171  std::cout << "In FullEnv, finished scanning options" << std::endl;
1172 #endif
1173 
1174  // Only display these messages if the user wants them
1175  // NOTE: This got moved below the Read Options section
1176  // because we need the options to be read to know what
1177  // the verbosity level is.
1178  if (this->displayVerbosity() > 0) {
1180  // Display main initial messages
1181  // 'std::cout' is for: main trace messages + synchronized trace messages + error messages prior to 'exit()' or 'abort()'
1183  /*int iRC = 0;*/
1184  /*iRC = */gettimeofday(&m_timevalBegin, NULL);
1185 
1186  if (m_fullRank == 0) {
1187  QUESO_version_print(std::cout);
1188  }
1189 
1190  if (m_fullRank == 0) {
1191  std::cout << "Beginning run at " << ctime(&m_timevalBegin.tv_sec)
1192  << std::endl;
1193  }
1194  }
1195 
1197  // Deal with multiple subEnvironments: create the sub communicators, one for each subEnvironment
1199  unsigned int numRanksPerSubEnvironment = m_fullCommSize/m_optionsObj->m_numSubEnvironments;
1200 
1201  m_subId = m_fullRank/numRanksPerSubEnvironment;
1202  char tmpSubId[16];
1203  sprintf(tmpSubId,"%u",m_subId);
1204  m_subIdString = tmpSubId;
1205 
1207  m_optionsObj->m_subDisplayAllowedSet.insert((unsigned int) m_subId);
1208  }
1209 
1210  std::vector<int> fullRanksOfMySubEnvironment(numRanksPerSubEnvironment,0);
1211  for (unsigned int i = 0; i < numRanksPerSubEnvironment; ++i) {
1212  fullRanksOfMySubEnvironment[i] = m_subId * numRanksPerSubEnvironment + i;
1213  }
1214 
1215  mpiRC = MPI_Group_incl(m_fullGroup, (int) numRanksPerSubEnvironment, &fullRanksOfMySubEnvironment[0], &m_subGroup);
1216  queso_require_equal_to_msg(mpiRC, MPI_SUCCESS, "failed MPI_Group_incl() for a subEnvironment");
1217 
1218  RawType_MPI_Comm subRawComm;
1219  mpiRC = MPI_Comm_create(m_fullComm->Comm(), m_subGroup, &subRawComm);
1220  queso_require_equal_to_msg(mpiRC, MPI_SUCCESS, "failed MPI_Comm_group() for a subEnvironment");
1221  m_subComm = new MpiComm(*this,subRawComm);
1222  m_subRank = m_subComm->MyPID();
1224 
1226  // Deal with multiple subEnvironments: create the self communicator
1228  m_selfComm = new MpiComm(*this,RawValue_MPI_COMM_SELF);
1229 
1231  // Deal with multiple subEnvironments: create the inter0 communicator
1233  std::vector<int> fullRanksOfInter0(m_optionsObj->m_numSubEnvironments,0);
1234  for (unsigned int i = 0; i < m_optionsObj->m_numSubEnvironments; ++i) {
1235  fullRanksOfInter0[i] = i * numRanksPerSubEnvironment;
1236  }
1237  mpiRC = MPI_Group_incl(m_fullGroup, (int) m_optionsObj->m_numSubEnvironments, &fullRanksOfInter0[0], &m_inter0Group);
1238  queso_require_equal_to_msg(mpiRC, MPI_SUCCESS, "failed MPI_Group_incl() for inter0");
1239  RawType_MPI_Comm inter0RawComm;
1240  mpiRC = MPI_Comm_create(m_fullComm->Comm(), m_inter0Group, &inter0RawComm);
1241  queso_require_equal_to_msg(mpiRC, MPI_SUCCESS, "failed MPI_Comm_group() for inter0");
1242  if (m_fullRank%numRanksPerSubEnvironment == 0) {
1243  m_inter0Comm = new MpiComm(*this,inter0RawComm);
1246  }
1247 
1249  // This situation has been already taken care of above
1250  }
1252  if (m_inter0Rank >= 0) {
1253  m_optionsObj->m_subDisplayAllowedSet.insert((unsigned int) m_subId);
1254  }
1255  }
1256 
1257 
1259  // Open "screen" file
1261  bool openFile = false;
1262  if ((m_subRank == 0 ) &&
1265  openFile = true;
1266  }
1267 
1268  if (openFile && m_worldRank == 0) {
1270  // Verify parent directory exists (for cases when a user
1271  // specifies a relative path for the desired output file).
1273  int irtrn = CheckFilePath((m_optionsObj->m_subDisplayFileName+"_sub"+m_subIdString+".txt").c_str());
1274  queso_require_greater_equal_msg(irtrn, 0, "unable to verify output path");
1275  }
1276 
1278  // Ensure that rank 0 has created path, if necessary, before other tasks use it
1280  m_fullComm->Barrier();
1281 
1282  if (openFile) {
1284  // Always write over an eventual pre-existing file
1286  m_subDisplayFile = new std::ofstream((m_optionsObj->m_subDisplayFileName+"_sub"+m_subIdString+".txt").c_str(),
1287  std::ofstream::out | std::ofstream::trunc);
1288  queso_require_msg((m_subDisplayFile && m_subDisplayFile->is_open()), "failed to open sub screen file");
1289 
1291 
1292  *m_subDisplayFile << "Beginning run at " << ctime(&m_timevalBegin.tv_sec)
1293  << std::endl;
1294  }
1295 
1297  // Debug message related to subEnvironments
1299  if (this->displayVerbosity() >= 2) {
1300  for (int i = 0; i < m_fullCommSize; ++i) {
1301  if (i == m_fullRank) {
1302  //std::cout << "In FullEnvironment::commonConstructor()"
1303  std::cout << "MPI node of worldRank " << m_worldRank
1304  << " has fullRank " << m_fullRank
1305  << ", belongs to subEnvironment of id " << m_subId
1306  << ", and has subRank " << m_subRank
1307  << std::endl;
1308 
1309  std::cout << "MPI node of worldRank " << m_worldRank
1310  << " belongs to sub communicator with full ranks";
1311  for (unsigned int j = 0; j < fullRanksOfMySubEnvironment.size(); ++j) {
1312  std::cout << " " << fullRanksOfMySubEnvironment[j];
1313  }
1314  std::cout << "\n";
1315 
1316  if (m_inter0Comm) {
1317  std::cout << "MPI node of worldRank " << m_worldRank
1318  << " also belongs to inter0 communicator with full ranks";
1319  for (unsigned int j = 0; j < fullRanksOfInter0.size(); ++j) {
1320  std::cout << " " << fullRanksOfInter0[j];
1321  }
1322  std::cout << ", and has inter0Rank " << m_inter0Rank;
1323  }
1324  std::cout << "\n";
1325 
1326  std::cout << std::endl;
1327  }
1328  m_fullComm->Barrier();
1329  }
1330  //if (this->fullRank() == 0) std::cout << "Sleeping 3 seconds..."
1331  // << std::endl;
1332  //sleep(3);
1333  }
1334 
1336  // Deal with seed
1338  if (m_optionsObj->m_rngType == "gsl") {
1339  m_rngObject = new RngGsl(m_optionsObj->m_seed,m_worldRank);
1340  m_basicPdfs = new BasicPdfsGsl(m_worldRank);
1341  }
1342  else if (m_optionsObj->m_rngType == "boost") {
1343  m_rngObject = new RngBoost(m_optionsObj->m_seed,m_worldRank);
1344  m_basicPdfs = new BasicPdfsBoost(m_worldRank);
1345  }
1346  else {
1347  std::cerr << "In Environment::constructor()"
1348  << ": rngType = " << m_optionsObj->m_rngType
1349  << std::endl;
1350  queso_error_msg("the requested 'rngType' is not supported yet");
1351  }
1352 
1354  // Leave commonConstructor()
1356  m_fullComm->Barrier();
1357  m_fullEnvIsReady = true;
1358 
1359  if ((m_subDisplayFile) && (this->displayVerbosity() >= 5)) {
1360  *m_subDisplayFile << "Done with initializations at FullEnvironment::commonConstructor()"
1361  << std::endl;
1362  }
1363 
1364  return;
1365 }
MPI_Comm RawType_MPI_Comm
Definition: MpiComm.h:38
unsigned int displayVerbosity() const
Definition: Environment.C:396
BasicPdfsBase * m_basicPdfs
Definition: Environment.h:379
boost::program_options::variables_map * m_allOptionsMap
Definition: Environment.h:361
int MyPID() const
Return my process ID.
Definition: MpiComm.C:94
std::string m_optionsInputFileName
Definition: Environment.h:358
std::terminate_handler old_terminate_handler
Definition: Environment.C:126
void Barrier() const
Pause every process in *this communicator until all the processes reach this point.
Definition: MpiComm.C:122
int NumProc() const
Returns total number of processes.
Definition: MpiComm.C:103
int m_seed
Seed of the random number generator.
void readOptionsInputFile()
Checks the options input file and reads the options.
Definition: Environment.C:1401
Class for random number generation using Boost library.
#define queso_error_msg(msg)
Definition: asserts.h:47
const MpiComm & fullComm() const
Access function for MpiComm full communicator.
Definition: Environment.C:228
void QUESO_version_print(std::ostream &os)
Definition: Environment.C:49
EnvOptionsValues * m_optionsObj
Definition: Environment.h:383
std::string m_subDisplayFileName
Output filename for sub-screen writing.
Class for random number generation using GSL library.
#define queso_require_equal_to_msg(expr1, expr2, msg)
Definition: asserts.h:85
std::string m_subIdString
Definition: Environment.h:364
#define queso_require_msg(asserted, msg)
Definition: asserts.h:69
RawType_MPI_Group m_fullGroup
Definition: Environment.h:356
int CheckFilePath(const char *path)
RawType_MPI_Comm Comm() const
Extract MPI Communicator from a MpiComm object.
Definition: MpiComm.C:85
unsigned int m_subId
Definition: Environment.h:363
bool m_subDisplayAllowAll
Allows (or not) all sub-environments to write to output file.
std::set< unsigned int > m_subDisplayAllowedSet
Sub-environments that will write to output.
boost::program_options::options_description * m_allOptionsDesc
Definition: Environment.h:360
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
#define RawValue_MPI_COMM_SELF
Definition: MpiComm.h:43
std::string m_rngType
Type of the random number generator.
#define queso_require_greater_equal_msg(expr1, expr2, msg)
Definition: asserts.h:90
bool m_subDisplayAllowInter0
Allows (or not) all inter0 nodes to write to output file.
RawType_MPI_Group m_subGroup
Definition: Environment.h:365
BaseEnvironment(const char *passedOptionsInputFileName, EnvOptionsValues *alternativeOptionsValues)
Default constructor.
Definition: Environment.C:132
void queso_terminate_handler()
Function for unhandled exceptions in Queso.
Definition: Environment.C:1378
#define UQ_ENV_FILENAME_FOR_NO_OUTPUT_FILE
QUESO::FullEnvironment::~FullEnvironment ( )

Destructor.

Definition at line 1367 of file Environment.C.

1368 {
1369 }

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

1373 {
1374  os.flush(); // just to avoid icpc warnings
1375  return;
1376 }
void QUESO::FullEnvironment::readOptionsInputFile ( )
private

Checks the options input file and reads the options.

Definition at line 1401 of file Environment.C.

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

Referenced by FullEnvironment().

1402 {
1403  std::ifstream* ifs = new std::ifstream(m_optionsInputFileName.c_str());
1404  if (ifs->is_open()) {
1405  //ifs->close();
1406  delete ifs;
1407  }
1408  else {
1409  if (m_fullRank == 0) std::cout << "An invalid input file has been passed to the 'environment' class constructor!"
1410  << ": name of file is '" << m_optionsInputFileName.c_str() << "'"
1411  << std::endl;
1412 
1413  if (m_fullRank == 0) std::cout << "\nThis is a help message of the QUESO library."
1414  << "\nAn application using the QUESO library shall be executed by typing"
1415  << "\n '<eventual mpi commands and options> <Application> <InputFile>'"
1416  << "\nin the command line."
1417  << "\n"
1418  << std::endl;
1419  queso_error();
1420  }
1421 
1422  return;
1423 }
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 Thu Jun 11 2015 13:52:34 for queso-0.53.0 by  doxygen 1.8.5