queso-0.57.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
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:
QUESO::BaseEnvironment

Public Member Functions

Constructor/Destructor methods
 FullEnvironment (RawType_MPI_Comm inputComm, const char *passedOptionsInputFileName, const char *prefix, EnvOptionsValues *alternativeOptionsValues)
 Parallel constructor. More...
 
 FullEnvironment (RawType_MPI_Comm inputComm, const std::string &passedOptionsInputFileName, const std::string &prefix, EnvOptionsValues *alternativeOptionsValues)
 
 FullEnvironment (const char *passedOptionsInputFileName, const char *prefix, EnvOptionsValues *alternativeOptionsValues)
 Serial 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 same thing as fullRank() More...
 
int fullRank () const
 Returns the rank of the MPI process in QUESO's full communicator. More...
 
const MpiCommfullComm () const
 Access function for the communicator that was passed to QUESO's environment. More...
 
RawType_MPI_Group subGroup () const
 Access function for sub-group. More...
 
int subRank () const
 Returns the rank of the MPI process in the sub-communicator subComm() More...
 
const MpiCommsubComm () const
 Access function for each sub-environment's 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 communicator for processes with subRank() 0. 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
 
const
boost::program_options::options_description & 
allOptionsDesc () 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 GetPot & input () const
 The GetPot input file parser. More...
 

Private Member Functions

void construct (RawType_MPI_Comm inputComm, const char *prefix)
 Named constructor backend for multiple constructor overloads. More...
 
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
 
ScopedPtr< MpiComm >::Type m_fullComm
 
int m_fullRank
 
int m_fullCommSize
 
RawType_MPI_Group m_fullGroup
 
std::string m_optionsInputFileName
 
bool m_optionsInputFileAccessState
 
ScopedPtr
< boost::program_options::options_description >
::Type 
m_allOptionsDesc
 
ScopedPtr
< boost::program_options::variables_map >
::Type 
m_allOptionsMap
 
ScopedPtr< GetPot >::Type m_input
 
unsigned int m_subId
 
std::string m_subIdString
 
RawType_MPI_Group m_subGroup
 
ScopedPtr< MpiComm >::Type m_subComm
 
int m_subRank
 
int m_subCommSize
 
ScopedPtr< MpiComm >::Type m_selfComm
 
RawType_MPI_Group m_inter0Group
 
ScopedPtr< MpiComm >::Type m_inter0Comm
 
int m_inter0Rank
 
int m_inter0CommSize
 
ScopedPtr< std::ofstream >::Type m_subDisplayFile
 
ScopedPtr< RngBase >::Type m_rngObject
 
ScopedPtr< BasicPdfsBase >::Type m_basicPdfs
 
struct timeval m_timevalBegin
 
bool m_exceptionalCircumstance
 
ScopedPtr< EnvOptionsValues >::Type m_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 508 of file Environment.h.

Constructor & Destructor Documentation

QUESO::FullEnvironment::FullEnvironment ( RawType_MPI_Comm  inputComm,
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.

Definition at line 1179 of file Environment.C.

References construct().

1184  :
1185  BaseEnvironment(passedOptionsInputFileName,alternativeOptionsValues)
1186 {
1187  this->construct(inputComm, prefix);
1188 }
void construct(RawType_MPI_Comm inputComm, const char *prefix)
Named constructor backend for multiple constructor overloads.
Definition: Environment.C:1202
BaseEnvironment(const char *passedOptionsInputFileName, EnvOptionsValues *alternativeOptionsValues)
Default constructor.
Definition: Environment.C:145
QUESO::FullEnvironment::FullEnvironment ( RawType_MPI_Comm  inputComm,
const std::string &  passedOptionsInputFileName,
const std::string &  prefix,
EnvOptionsValues alternativeOptionsValues 
)

Definition at line 1190 of file Environment.C.

References construct().

1195  :
1196  BaseEnvironment(passedOptionsInputFileName,alternativeOptionsValues)
1197 {
1198  this->construct(inputComm, prefix.c_str());
1199 }
void construct(RawType_MPI_Comm inputComm, const char *prefix)
Named constructor backend for multiple constructor overloads.
Definition: Environment.C:1202
BaseEnvironment(const char *passedOptionsInputFileName, EnvOptionsValues *alternativeOptionsValues)
Default constructor.
Definition: Environment.C:145
QUESO::FullEnvironment::FullEnvironment ( const char *  passedOptionsInputFileName,
const char *  prefix,
EnvOptionsValues alternativeOptionsValues 
)

Serial constructor.

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

Definition at line 1467 of file Environment.C.

References construct().

1471  :
1472  BaseEnvironment(passedOptionsInputFileName,alternativeOptionsValues)
1473 {
1474  this->construct(prefix);
1475 }
void construct(RawType_MPI_Comm inputComm, const char *prefix)
Named constructor backend for multiple constructor overloads.
Definition: Environment.C:1202
BaseEnvironment(const char *passedOptionsInputFileName, EnvOptionsValues *alternativeOptionsValues)
Default constructor.
Definition: Environment.C:145
QUESO::FullEnvironment::FullEnvironment ( const std::string &  passedOptionsInputFileName,
const std::string &  prefix,
EnvOptionsValues alternativeOptionsValues 
)

Definition at line 1477 of file Environment.C.

References construct().

1481  :
1482  BaseEnvironment(passedOptionsInputFileName,alternativeOptionsValues)
1483 {
1484  this->construct(prefix.c_str());
1485 }
void construct(RawType_MPI_Comm inputComm, const char *prefix)
Named constructor backend for multiple constructor overloads.
Definition: Environment.C:1202
BaseEnvironment(const char *passedOptionsInputFileName, EnvOptionsValues *alternativeOptionsValues)
Default constructor.
Definition: Environment.C:145
QUESO::FullEnvironment::~FullEnvironment ( )

Destructor.

Definition at line 1720 of file Environment.C.

1721 {
1722 }

Member Function Documentation

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

Named constructor backend for multiple constructor overloads.

Definition at line 1202 of file Environment.C.

References 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::BaseEnvironment::m_input, QUESO::BaseEnvironment::m_inter0Comm, QUESO::BaseEnvironment::m_inter0CommSize, QUESO::BaseEnvironment::m_inter0Group, QUESO::BaseEnvironment::m_inter0Rank, QUESO::BaseEnvironment::m_optionsInputFileName, QUESO::BaseEnvironment::m_optionsObj, QUESO::BaseEnvironment::m_rngObject, QUESO::BaseEnvironment::m_selfComm, QUESO::BaseEnvironment::m_subComm, QUESO::BaseEnvironment::m_subCommSize, QUESO::BaseEnvironment::m_subDisplayFile, 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::old_terminate_handler, QUESO::queso_require_equal_to_msg, QUESO::queso_terminate_handler(), QUESO::QUESO_version_print(), and readOptionsInputFile().

Referenced by FullEnvironment().

1204 {
1205 #ifdef QUESO_MEMORY_DEBUGGING
1206  std::cout << "Entering FullEnv" << std::endl;
1207 #endif
1208 
1210  // Initialize "full" communicator -- Not necessarily MPI_COMM_WORLD
1212  int mpiRC = MPI_Comm_rank(inputComm,&m_worldRank);
1213  queso_require_equal_to_msg(mpiRC, MPI_SUCCESS, "failed to get world fullRank()");
1214 
1215  m_fullComm.reset(new MpiComm(*this,inputComm));
1216 
1217  m_fullRank = m_fullComm->MyPID();
1218  m_fullCommSize = m_fullComm->NumProc();
1219 
1220  mpiRC = MPI_Comm_group(m_fullComm->Comm(), &m_fullGroup);
1221  queso_require_equal_to_msg(mpiRC, MPI_SUCCESS, "failed MPI_Comm_group()");
1222 
1223  // saving old uncaught exception handler, invoking queso_terminate
1224  old_terminate_handler = std::set_terminate(queso_terminate_handler);
1225 
1226 #ifdef QUESO_MEMORY_DEBUGGING
1227  std::cout << "In FullEnv, finished dealing with MPI initially" << std::endl;
1228 #endif
1229 
1231  // Read options
1233  // If NULL, we create one
1234  if (m_optionsObj == NULL) {
1235  // If there's an input file, we grab the options from there. Otherwise the
1236  // defaults are used
1237  if (m_optionsInputFileName != "") {
1238 #ifndef QUESO_DISABLE_BOOST_PROGRAM_OPTIONS
1239  m_allOptionsMap.reset(new boost::program_options::variables_map());
1240  m_allOptionsDesc.reset(new boost::program_options::options_description("Allowed options"));
1241 #endif // QUESO_DISABLE_BOOST_PROGRAM_OPTIONS
1242 
1244 
1245  m_input->parse_input_file(m_optionsInputFileName);
1246  }
1247 
1248  m_optionsObj.reset(new EnvOptionsValues(this, prefix));
1249  }
1250 
1251  // If help option was supplied, print info
1252  if (m_optionsObj->m_help != "") {
1253  // We write to std::cout because subDisplayFile() isn't ready yet?
1254  std::cout << (*m_optionsObj) << std::endl;
1255  }
1256 
1258  fullComm().NumProc() % m_optionsObj->m_numSubEnvironments, 0,
1259  "total number of processors in environment must be multiple of the specified number of subEnvironments");
1260 
1261 #ifdef QUESO_MEMORY_DEBUGGING
1262  std::cout << "In FullEnv, finished scanning options" << std::endl;
1263 #endif
1264 
1265  // Only display these messages if the user wants them
1266  // NOTE: This got moved below the Read Options section
1267  // because we need the options to be read to know what
1268  // the verbosity level is.
1269  if (this->displayVerbosity() > 0) {
1271  // Display main initial messages
1272  // 'std::cout' is for: main trace messages + synchronized trace messages + error messages prior to 'exit()' or 'abort()'
1274  /*int iRC = 0;*/
1275  /*iRC = */gettimeofday(&m_timevalBegin, NULL);
1276 
1277  if (m_fullRank == 0) {
1278  QUESO_version_print(std::cout);
1279  }
1280 
1281  if (m_fullRank == 0) {
1282  std::cout << "Beginning run at " << ctime(&m_timevalBegin.tv_sec)
1283  << std::endl;
1284  }
1285  }
1286 
1288  // Deal with multiple subEnvironments: create the sub communicators, one for each subEnvironment
1290  unsigned int numRanksPerSubEnvironment = m_fullCommSize/m_optionsObj->m_numSubEnvironments;
1291 
1292  m_subId = m_fullRank/numRanksPerSubEnvironment;
1293  char tmpSubId[16];
1294  sprintf(tmpSubId,"%u",m_subId);
1295  m_subIdString = tmpSubId;
1296 
1297  if (m_optionsObj->m_subDisplayAllowAll) {
1298  m_optionsObj->m_subDisplayAllowedSet.insert((unsigned int) m_subId);
1299  }
1300 
1301  std::vector<int> fullRanksOfMySubEnvironment(numRanksPerSubEnvironment,0);
1302  for (unsigned int i = 0; i < numRanksPerSubEnvironment; ++i) {
1303  fullRanksOfMySubEnvironment[i] = m_subId * numRanksPerSubEnvironment + i;
1304  }
1305 
1306  mpiRC = MPI_Group_incl(m_fullGroup, (int) numRanksPerSubEnvironment, &fullRanksOfMySubEnvironment[0], &m_subGroup);
1307  queso_require_equal_to_msg(mpiRC, MPI_SUCCESS, "failed MPI_Group_incl() for a subEnvironment");
1308 
1309  RawType_MPI_Comm subRawComm;
1310  mpiRC = MPI_Comm_create(m_fullComm->Comm(), m_subGroup, &subRawComm);
1311  queso_require_equal_to_msg(mpiRC, MPI_SUCCESS, "failed MPI_Comm_group() for a subEnvironment");
1312  m_subComm.reset(new MpiComm(*this,subRawComm));
1313  m_subRank = m_subComm->MyPID();
1314  m_subCommSize = m_subComm->NumProc();
1315 
1317  // Deal with multiple subEnvironments: create the self communicator
1319  m_selfComm.reset(new MpiComm(*this,RawValue_MPI_COMM_SELF));
1320 
1322  // Deal with multiple subEnvironments: create the inter0 communicator
1324  std::vector<int> fullRanksOfInter0(m_optionsObj->m_numSubEnvironments,0);
1325  for (unsigned int i = 0; i < m_optionsObj->m_numSubEnvironments; ++i) {
1326  fullRanksOfInter0[i] = i * numRanksPerSubEnvironment;
1327  }
1328  mpiRC = MPI_Group_incl(m_fullGroup, (int) m_optionsObj->m_numSubEnvironments, &fullRanksOfInter0[0], &m_inter0Group);
1329  queso_require_equal_to_msg(mpiRC, MPI_SUCCESS, "failed MPI_Group_incl() for inter0");
1330  RawType_MPI_Comm inter0RawComm;
1331  mpiRC = MPI_Comm_create(m_fullComm->Comm(), m_inter0Group, &inter0RawComm);
1332  queso_require_equal_to_msg(mpiRC, MPI_SUCCESS, "failed MPI_Comm_group() for inter0");
1333  if (m_fullRank%numRanksPerSubEnvironment == 0) {
1334  m_inter0Comm.reset(new MpiComm(*this,inter0RawComm));
1335  m_inter0Rank = m_inter0Comm->MyPID();
1336  m_inter0CommSize = m_inter0Comm->NumProc();
1337  }
1338 
1339  if (m_optionsObj->m_subDisplayAllowAll) {
1340  // This situation has been already taken care of above
1341  }
1342  else if (m_optionsObj->m_subDisplayAllowInter0) {
1343  if (m_inter0Rank >= 0) {
1344  m_optionsObj->m_subDisplayAllowedSet.insert((unsigned int) m_subId);
1345  }
1346  }
1347 
1348 
1350  // Open "screen" file
1352  bool openFile = false;
1353  if ((m_subRank == 0 ) &&
1354  (m_optionsObj->m_subDisplayFileName != UQ_ENV_FILENAME_FOR_NO_OUTPUT_FILE ) &&
1355  (m_optionsObj->m_subDisplayAllowedSet.find(m_subId) != m_optionsObj->m_subDisplayAllowedSet.end())) {
1356  openFile = true;
1357  }
1358 
1359  if (openFile && m_worldRank == 0) {
1361  // Verify parent directory exists (for cases when a user
1362  // specifies a relative path for the desired output file).
1364  int irtrn = CheckFilePath((m_optionsObj->m_subDisplayFileName+"_sub"+m_subIdString+".txt").c_str());
1365  queso_require_greater_equal_msg(irtrn, 0, "unable to verify output path");
1366  }
1367 
1369  // Ensure that rank 0 has created path, if necessary, before other tasks use it
1371  m_fullComm->Barrier();
1372 
1373  if (openFile) {
1375  // Always write over an eventual pre-existing file
1377  m_subDisplayFile.reset(new std::ofstream((m_optionsObj->m_subDisplayFileName+"_sub"+m_subIdString+".txt").c_str(),
1378  std::ofstream::out | std::ofstream::trunc));
1379  queso_require_msg((m_subDisplayFile && m_subDisplayFile->is_open()), "failed to open sub screen file");
1380 
1382 
1383  *m_subDisplayFile << "Beginning run at " << ctime(&m_timevalBegin.tv_sec)
1384  << std::endl;
1385  }
1386 
1388  // Debug message related to subEnvironments
1390  if (this->displayVerbosity() >= 2) {
1391  for (int i = 0; i < m_fullCommSize; ++i) {
1392  if (i == m_fullRank) {
1393  //std::cout << "In FullEnvironment::commonConstructor()"
1394  std::cout << "MPI node of worldRank " << m_worldRank
1395  << " has fullRank " << m_fullRank
1396  << ", belongs to subEnvironment of id " << m_subId
1397  << ", and has subRank " << m_subRank
1398  << std::endl;
1399 
1400  std::cout << "MPI node of worldRank " << m_worldRank
1401  << " belongs to sub communicator with full ranks";
1402  for (unsigned int j = 0; j < fullRanksOfMySubEnvironment.size(); ++j) {
1403  std::cout << " " << fullRanksOfMySubEnvironment[j];
1404  }
1405  std::cout << "\n";
1406 
1407  if (m_inter0Comm) {
1408  std::cout << "MPI node of worldRank " << m_worldRank
1409  << " also belongs to inter0 communicator with full ranks";
1410  for (unsigned int j = 0; j < fullRanksOfInter0.size(); ++j) {
1411  std::cout << " " << fullRanksOfInter0[j];
1412  }
1413  std::cout << ", and has inter0Rank " << m_inter0Rank;
1414  }
1415  std::cout << "\n";
1416 
1417  std::cout << std::endl;
1418  }
1419  m_fullComm->Barrier();
1420  }
1421  //if (this->fullRank() == 0) std::cout << "Sleeping 3 seconds..."
1422  // << std::endl;
1423  //sleep(3);
1424  }
1425 
1427  // Deal with seed
1429  if (m_optionsObj->m_rngType == "gsl") {
1430  m_rngObject.reset(new RngGsl(m_optionsObj->m_seed,m_worldRank));
1431  m_basicPdfs.reset(new BasicPdfsGsl(m_worldRank));
1432  }
1433  else if (m_optionsObj->m_rngType == "boost") {
1434  m_rngObject.reset(new RngBoost(m_optionsObj->m_seed,m_worldRank));
1435  m_basicPdfs.reset(new BasicPdfsBoost(m_worldRank));
1436  }
1437  else if (m_optionsObj->m_rngType == "cxx11") {
1438 #ifdef QUESO_HAVE_CXX11
1439  m_rngObject.reset(new RngCXX11(m_optionsObj->m_seed, m_worldRank));
1440  m_basicPdfs.reset(new BasicPdfsCXX11(m_worldRank));
1441 #else
1442  queso_error_msg("C++11 RNGs requested, but QUESO wasn't compiled with C++11 support");
1443 #endif
1444  }
1445  else {
1446  std::cerr << "In Environment::constructor()"
1447  << ": rngType = " << m_optionsObj->m_rngType
1448  << std::endl;
1449  queso_error_msg("the requested 'rngType' is not supported yet");
1450  }
1451 
1453  // Leave commonConstructor()
1455  m_fullComm->Barrier();
1456  m_fullEnvIsReady = true;
1457 
1458  if ((m_subDisplayFile) && (this->displayVerbosity() >= 5)) {
1459  *m_subDisplayFile << "Done with initializations at FullEnvironment::commonConstructor()"
1460  << std::endl;
1461  }
1462 
1463  return;
1464 }
ScopedPtr< GetPot >::Type m_input
Definition: Environment.h:453
MPI_Comm RawType_MPI_Comm
Definition: MpiComm.h:41
ScopedPtr< MpiComm >::Type m_fullComm
Definition: Environment.h:442
ScopedPtr< EnvOptionsValues >::Type m_optionsObj
Definition: Environment.h:475
Class for random number generation using Boost library.
RawType_MPI_Group m_fullGroup
Definition: Environment.h:445
Class for random number generation using GSL library.
RawType_MPI_Group m_subGroup
Definition: Environment.h:457
ScopedPtr< RngBase >::Type m_rngObject
Definition: Environment.h:470
int CheckFilePath(const char *path)
ScopedPtr< boost::program_options::variables_map >::Type m_allOptionsMap
Definition: Environment.h:451
ScopedPtr< boost::program_options::options_description >::Type m_allOptionsDesc
Definition: Environment.h:450
void queso_terminate_handler()
Function for unhandled exceptions in Queso.
Definition: Environment.C:1731
std::string m_subIdString
Definition: Environment.h:456
void readOptionsInputFile()
Checks the options input file and reads the options.
Definition: Environment.C:1758
std::string m_optionsInputFileName
Definition: Environment.h:447
MonteCarloSGOptions::MonteCarloSGOptions(const BaseEnvironment &env, const char *prefix, const McOptionsValues &alternativeOptionsValues queso_require_equal_to_msg)(m_env.optionsInputFileName(), std::string(""), std::string("this constructor is incompatible with the existence of an options input file"))
Class for random number generation using std::random from C++11.
void QUESO_version_print(std::ostream &os)
Definition: Environment.C:56
unsigned int m_subId
Definition: Environment.h:455
ScopedPtr< MpiComm >::Type m_selfComm
Definition: Environment.h:462
ScopedPtr< MpiComm >::Type m_inter0Comm
Definition: Environment.h:465
unsigned int displayVerbosity() const
Definition: Environment.C:450
std::terminate_handler old_terminate_handler
Definition: Environment.C:139
const MpiComm & fullComm() const
Access function for the communicator that was passed to QUESO&#39;s environment.
Definition: Environment.C:274
struct timeval m_timevalBegin
Definition: Environment.h:472
ScopedPtr< MpiComm >::Type m_subComm
Definition: Environment.h:458
RawType_MPI_Group m_inter0Group
Definition: Environment.h:464
ScopedPtr< BasicPdfsBase >::Type m_basicPdfs
Definition: Environment.h:471
ScopedPtr< std::ofstream >::Type m_subDisplayFile
Definition: Environment.h:469
void QUESO::FullEnvironment::construct ( const char *  prefix)
private

Named constructor backend for multiple constructor overloads.

Definition at line 1488 of file Environment.C.

References 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::BaseEnvironment::m_input, QUESO::BaseEnvironment::m_inter0Comm, QUESO::BaseEnvironment::m_inter0CommSize, QUESO::BaseEnvironment::m_inter0Group, QUESO::BaseEnvironment::m_inter0Rank, QUESO::BaseEnvironment::m_optionsInputFileName, QUESO::BaseEnvironment::m_optionsObj, QUESO::BaseEnvironment::m_rngObject, QUESO::BaseEnvironment::m_selfComm, QUESO::BaseEnvironment::m_subComm, QUESO::BaseEnvironment::m_subCommSize, QUESO::BaseEnvironment::m_subDisplayFile, 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::old_terminate_handler, QUESO::queso_require_equal_to_msg, QUESO::queso_terminate_handler(), QUESO::QUESO_version_print(), and readOptionsInputFile().

1489 {
1490 #ifdef QUESO_MEMORY_DEBUGGING
1491  std::cout << "Entering FullEnv" << std::endl;
1492 #endif
1493 
1494  m_worldRank = 0;
1495 
1496  m_fullComm.reset(new MpiComm(*this));
1497  m_fullRank = 0;
1498  m_fullCommSize = 1;
1499 
1500 #ifndef QUESO_HAS_MPI
1501  m_fullGroup = 0;
1502 #endif
1503 
1504  // saving old uncaught exception handler, invoking queso_terminate
1505  old_terminate_handler = std::set_terminate(queso_terminate_handler);
1506 
1507 #ifdef QUESO_MEMORY_DEBUGGING
1508  std::cout << "In FullEnv, finished dealing with MPI initially" << std::endl;
1509 #endif
1510 
1512  // Read options
1514  // If NULL, we create one
1515  if (m_optionsObj == NULL) {
1516  // If there's an input file, we grab the options from there. Otherwise the
1517  // defaults are used
1518  if (m_optionsInputFileName != "") {
1519 #ifndef QUESO_DISABLE_BOOST_PROGRAM_OPTIONS
1520  m_allOptionsMap.reset(new boost::program_options::variables_map());
1521  m_allOptionsDesc.reset(new boost::program_options::options_description("Allowed options"));
1522 #endif // QUESO_DISABLE_BOOST_PROGRAM_OPTIONS
1523 
1525 
1526  m_input->parse_input_file(m_optionsInputFileName);
1527  }
1528 
1529  m_optionsObj.reset(new EnvOptionsValues(this, prefix));
1530  }
1531 
1532  // If help option was supplied, print info
1533  if (m_optionsObj->m_help != "") {
1534  // We write to std::cout because subDisplayFile() isn't ready yet?
1535  std::cout << (*m_optionsObj) << std::endl;
1536  }
1537 
1539  fullComm().NumProc() % m_optionsObj->m_numSubEnvironments, 0,
1540  "total number of processors in environment must be multiple of the specified number of subEnvironments");
1541 
1542 #ifdef QUESO_MEMORY_DEBUGGING
1543  std::cout << "In FullEnv, finished scanning options" << std::endl;
1544 #endif
1545 
1546  // Only display these messages if the user wants them
1547  // NOTE: This got moved below the Read Options section
1548  // because we need the options to be read to know what
1549  // the verbosity level is.
1550  if (this->displayVerbosity() > 0) {
1552  // Display main initial messages
1553  // 'std::cout' is for: main trace messages + synchronized trace messages + error messages prior to 'exit()' or 'abort()'
1555  /*int iRC = 0;*/
1556  /*iRC = */gettimeofday(&m_timevalBegin, NULL);
1557 
1558  QUESO_version_print(std::cout);
1559 
1560  std::cout << "Beginning run at " << ctime(&m_timevalBegin.tv_sec)
1561  << std::endl;
1562  }
1563 
1564  m_subId = 0;
1565  char tmpSubId[16];
1566  sprintf(tmpSubId,"%u",m_subId);
1567  m_subIdString = tmpSubId;
1568 
1569  if (m_optionsObj->m_subDisplayAllowAll) {
1570  m_optionsObj->m_subDisplayAllowedSet.insert((unsigned int) m_subId);
1571  }
1572 
1573  int fullRanksOfMySubEnvironment = 1;
1574 
1575 #ifndef QUESO_HAS_MPI
1576  m_subGroup = 0;
1577 #endif
1578 
1579  m_subComm.reset(new MpiComm(*this));
1580  m_subRank = 0;
1581  m_subCommSize = 1;
1582 
1584  // Deal with multiple subEnvironments: create the self communicator
1586  m_selfComm.reset(new MpiComm(*this));
1587 
1589  // Deal with multiple subEnvironments: create the inter0 communicator
1591  int fullRanksOfInter0 = 0;
1592 #ifndef QUESO_HAS_MPI
1593  m_inter0Group = 0;
1594 #endif
1595  m_inter0Comm.reset(new MpiComm(*this));
1596  m_inter0Rank = 0;
1597  m_inter0CommSize = 1;
1598 
1599  if (m_optionsObj->m_subDisplayAllowAll) {
1600  // This situation has been already taken care of above
1601  }
1602  else if (m_optionsObj->m_subDisplayAllowInter0) {
1603  if (m_inter0Rank >= 0) {
1604  m_optionsObj->m_subDisplayAllowedSet.insert((unsigned int) m_subId);
1605  }
1606  }
1607 
1608 
1610  // Open "screen" file
1612  bool openFile = false;
1613  if ((m_subRank == 0 ) &&
1614  (m_optionsObj->m_subDisplayFileName != UQ_ENV_FILENAME_FOR_NO_OUTPUT_FILE ) &&
1615  (m_optionsObj->m_subDisplayAllowedSet.find(m_subId) != m_optionsObj->m_subDisplayAllowedSet.end())) {
1616  openFile = true;
1617  }
1618 
1619  if (openFile && m_worldRank == 0) {
1621  // Verify parent directory exists (for cases when a user
1622  // specifies a relative path for the desired output file).
1624  int irtrn = CheckFilePath((m_optionsObj->m_subDisplayFileName+"_sub"+m_subIdString+".txt").c_str());
1625  queso_require_greater_equal_msg(irtrn, 0, "unable to verify output path");
1626  }
1627 
1629  // Ensure that rank 0 has created path, if necessary, before other tasks use it
1631  m_fullComm->Barrier();
1632 
1633  if (openFile) {
1635  // Always write over an eventual pre-existing file
1637  m_subDisplayFile.reset(new std::ofstream((m_optionsObj->m_subDisplayFileName+"_sub"+m_subIdString+".txt").c_str(),
1638  std::ofstream::out | std::ofstream::trunc));
1639  queso_require_msg((m_subDisplayFile && m_subDisplayFile->is_open()), "failed to open sub screen file");
1640 
1642 
1643  *m_subDisplayFile << "Beginning run at " << ctime(&m_timevalBegin.tv_sec)
1644  << std::endl;
1645  }
1646 
1648  // Debug message related to subEnvironments
1650  if (this->displayVerbosity() >= 2) {
1651  for (int i = 0; i < m_fullCommSize; ++i) {
1652  if (i == m_fullRank) {
1653  //std::cout << "In FullEnvironment::commonConstructor()"
1654  std::cout << "MPI node of worldRank " << m_worldRank
1655  << " has fullRank " << m_fullRank
1656  << ", belongs to subEnvironment of id " << m_subId
1657  << ", and has subRank " << m_subRank
1658  << std::endl;
1659 
1660  std::cout << "MPI node of worldRank " << m_worldRank
1661  << " belongs to sub communicator with full ranks";
1662  std::cout << " " << fullRanksOfMySubEnvironment;
1663  std::cout << "\n";
1664 
1665  if (m_inter0Comm) {
1666  std::cout << "MPI node of worldRank " << m_worldRank
1667  << " also belongs to inter0 communicator with full ranks";
1668  std::cout << " " << fullRanksOfInter0;
1669  std::cout << ", and has inter0Rank " << m_inter0Rank;
1670  }
1671  std::cout << "\n";
1672 
1673  std::cout << std::endl;
1674  }
1675  m_fullComm->Barrier();
1676  }
1677  }
1678 
1680  // Deal with seed
1682  if (m_optionsObj->m_rngType == "gsl") {
1683  m_rngObject.reset(new RngGsl(m_optionsObj->m_seed,m_worldRank));
1684  m_basicPdfs.reset(new BasicPdfsGsl(m_worldRank));
1685  }
1686  else if (m_optionsObj->m_rngType == "boost") {
1687  m_rngObject.reset(new RngBoost(m_optionsObj->m_seed,m_worldRank));
1688  m_basicPdfs.reset(new BasicPdfsBoost(m_worldRank));
1689  }
1690  else if (m_optionsObj->m_rngType == "cxx11") {
1691 #ifdef QUESO_HAVE_CXX11
1692  m_rngObject.reset(new RngCXX11(m_optionsObj->m_seed, m_worldRank));
1693  m_basicPdfs.reset(new BasicPdfsCXX11(m_worldRank));
1694 #else
1695  queso_error_msg("C++11 RNGs requested, but QUESO wasn't compiled with C++11 support");
1696 #endif
1697  }
1698  else {
1699  std::cerr << "In Environment::constructor()"
1700  << ": rngType = " << m_optionsObj->m_rngType
1701  << std::endl;
1702  queso_error_msg("the requested 'rngType' is not supported yet");
1703  }
1704 
1706  // Leave commonConstructor()
1708  m_fullComm->Barrier();
1709  m_fullEnvIsReady = true;
1710 
1711  if ((m_subDisplayFile) && (this->displayVerbosity() >= 5)) {
1712  *m_subDisplayFile << "Done with initializations at FullEnvironment::commonConstructor()"
1713  << std::endl;
1714  }
1715 
1716  return;
1717 }
ScopedPtr< GetPot >::Type m_input
Definition: Environment.h:453
ScopedPtr< MpiComm >::Type m_fullComm
Definition: Environment.h:442
ScopedPtr< EnvOptionsValues >::Type m_optionsObj
Definition: Environment.h:475
Class for random number generation using Boost library.
RawType_MPI_Group m_fullGroup
Definition: Environment.h:445
Class for random number generation using GSL library.
RawType_MPI_Group m_subGroup
Definition: Environment.h:457
ScopedPtr< RngBase >::Type m_rngObject
Definition: Environment.h:470
int CheckFilePath(const char *path)
ScopedPtr< boost::program_options::variables_map >::Type m_allOptionsMap
Definition: Environment.h:451
ScopedPtr< boost::program_options::options_description >::Type m_allOptionsDesc
Definition: Environment.h:450
void queso_terminate_handler()
Function for unhandled exceptions in Queso.
Definition: Environment.C:1731
std::string m_subIdString
Definition: Environment.h:456
void readOptionsInputFile()
Checks the options input file and reads the options.
Definition: Environment.C:1758
std::string m_optionsInputFileName
Definition: Environment.h:447
MonteCarloSGOptions::MonteCarloSGOptions(const BaseEnvironment &env, const char *prefix, const McOptionsValues &alternativeOptionsValues queso_require_equal_to_msg)(m_env.optionsInputFileName(), std::string(""), std::string("this constructor is incompatible with the existence of an options input file"))
Class for random number generation using std::random from C++11.
void QUESO_version_print(std::ostream &os)
Definition: Environment.C:56
unsigned int m_subId
Definition: Environment.h:455
ScopedPtr< MpiComm >::Type m_selfComm
Definition: Environment.h:462
ScopedPtr< MpiComm >::Type m_inter0Comm
Definition: Environment.h:465
unsigned int displayVerbosity() const
Definition: Environment.C:450
std::terminate_handler old_terminate_handler
Definition: Environment.C:139
const MpiComm & fullComm() const
Access function for the communicator that was passed to QUESO&#39;s environment.
Definition: Environment.C:274
struct timeval m_timevalBegin
Definition: Environment.h:472
ScopedPtr< MpiComm >::Type m_subComm
Definition: Environment.h:458
RawType_MPI_Group m_inter0Group
Definition: Environment.h:464
ScopedPtr< BasicPdfsBase >::Type m_basicPdfs
Definition: Environment.h:471
ScopedPtr< std::ofstream >::Type m_subDisplayFile
Definition: Environment.h:469
void QUESO::FullEnvironment::print ( std::ostream &  os) const
virtual

Sends the environment options to the stream.

Implements QUESO::BaseEnvironment.

Definition at line 1725 of file Environment.C.

1726 {
1727  os.flush(); // just to avoid icpc warnings
1728  return;
1729 }
void QUESO::FullEnvironment::readOptionsInputFile ( )
private

Checks the options input file and reads the options.

Definition at line 1758 of file Environment.C.

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

Referenced by construct().

1759 {
1760  std::ifstream* ifs = new std::ifstream(m_optionsInputFileName.c_str());
1761  if (ifs->is_open()) {
1762  //ifs->close();
1763  delete ifs;
1764  }
1765  else {
1766  if (m_fullRank == 0) std::cout << "An invalid input file has been passed to the 'environment' class constructor!"
1767  << ": name of file is '" << m_optionsInputFileName.c_str() << "'"
1768  << std::endl;
1769 
1770  if (m_fullRank == 0) std::cout << "\nThis is a help message of the QUESO library."
1771  << "\nAn application using the QUESO library shall be executed by typing"
1772  << "\n '<eventual mpi commands and options> <Application> <InputFile>'"
1773  << "\nin the command line."
1774  << "\n"
1775  << std::endl;
1776  queso_error();
1777  }
1778 
1779  return;
1780 }
std::string m_optionsInputFileName
Definition: Environment.h:447

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

Generated on Tue Jun 5 2018 19:49:06 for queso-0.57.1 by  doxygen 1.8.5