25 #include <boost/program_options.hpp>
27 #include <queso/queso.h>
28 #include <queso/Environment.h>
29 #include <queso/EnvironmentOptions.h>
30 #include <queso/RngGsl.h>
31 #include <queso/RngBoost.h>
32 #include <queso/BasicPdfsGsl.h>
33 #include <queso/BasicPdfsBoost.h>
34 #include <queso/Miscellaneous.h>
41 #include <queso/asserts.h>
52 os <<
"------------------------------------------------------------------------------------------" ;
53 os <<
"--------------------" << std::endl;
72 os <<
"------------------------------------------------------------------------------------------" ;
73 os <<
"--------------------" << std::endl;
92 int major_version = 0;
93 int minor_version = 0;
94 int micro_version = 0;
96 #ifdef QUESO_MAJOR_VERSION
100 #ifdef QUESO_MINOR_VERSION
104 #ifdef QUESO_MICRO_VERSION
108 return(major_version*10000 + minor_version*100 + micro_version);
133 const char* passedOptionsInputFileName,
136 m_fullEnvIsReady (false),
141 m_optionsInputFileName (
""),
142 m_optionsInputFileAccessState(true),
143 m_allOptionsDesc (NULL),
144 m_allOptionsMap (NULL),
151 m_inter0CommSize (1),
152 m_subDisplayFile (NULL),
155 m_exceptionalCircumstance (false),
156 m_optionsObj (alternativeOptionsValues)
168 struct timeval timevalNow;
170 gettimeofday(&timevalNow, NULL);
176 <<
"Total run time = " << timevalNow.tv_sec -
m_timevalBegin.tv_sec
182 std::cout <<
"Ending run at " << ctime(&timevalNow.tv_sec)
183 <<
"Total run time = " << timevalNow.tv_sec -
m_timevalBegin.tv_sec
325 #ifdef UQ_USES_COMMAND_LINE_OPTIONS
326 const boost::program_options::options_description&
327 BaseEnvironment::allOptionsDesc()
const
335 boost::program_options::variables_map&
349 #ifdef UQ_USES_COMMAND_LINE_OPTIONS
361 #ifdef QUESO_MEMORY_DEBUGGING
362 std::cout <<
"Entering BaseEnv::scanInputFileForMyOptions()" << std::endl;
375 #ifdef QUESO_MEMORY_DEBUGGING
376 std::cout <<
"in BaseEnv::scanInputFileForMyOptions(), before store(a)" << std::endl;
381 #ifdef QUESO_MEMORY_DEBUGGING
382 std::cout <<
"in BaseEnv::scanInputFileForMyOptions(), after store(a)" << std::endl;
388 #ifdef QUESO_MEMORY_DEBUGGING
389 std::cout <<
"Leaving BaseEnv::scanInputFileForMyOptions()" << std::endl;
463 return m_timevalBegin;
468 const std::string& baseFileName,
469 const std::string& inputFileType,
470 const std::set<unsigned int>& allowedSubEnvIds,
474 std::string fileType(inputFileType);
475 #ifdef QUESO_HAS_HDF5
480 *this->
subDisplayFile() <<
"WARNING in BaseEnvironment::openOutputFile()"
482 <<
"' has been requested, but this QUESO library has not been built with 'hdf5'"
488 std::cerr <<
"WARNING in BaseEnvironment::openOutputFile()"
490 <<
"' has been requested, but this QUESO library has not been built with 'hdf5'"
499 bool returnValue =
true;
502 (allowedSubEnvIds.find(this->subId()) == allowedSubEnvIds.end() )) {
505 <<
", subId = " << this->
subId()
506 <<
": no output file opened with base name '" << baseFileName <<
"." << fileType
508 <<
", writeOver = " << writeOver
519 <<
", subId = " << this->
subId()
520 <<
": opening output file with base name '" << baseFileName <<
"." << fileType
522 <<
", writeOver = " << writeOver
528 std::cout <<
"In BaseEnvironment::openOutputFile()"
529 <<
": opening output file with base name '" << baseFileName <<
"." << fileType
531 <<
", writeOver = " << writeOver
542 <<
", subId = " << this->
subId()
543 <<
", trying to open output file with base name '" << baseFileName <<
"." << fileType
545 <<
", writeOver = " << writeOver
546 <<
": calling CheckFilePath()..."
552 <<
", subId = " << this->
subId()
553 <<
", trying to open output file with base name '" << baseFileName <<
"." << fileType
555 <<
", writeOver = " << writeOver
556 <<
": returned from CheckFilePath() with irtrn = " << irtrn
566 filePtrSet.
ofsVar =
new std::ofstream((baseFileName+
"_sub"+this->
subIdString()+
"."+fileType).c_str(),
567 std::ofstream::out | std::ofstream::trunc);
577 <<
": just opened output file with base name '" << baseFileName <<
"." << fileType
579 <<
", writeOver = " << writeOver
580 <<
", options 'out|trunc'"
581 <<
", osfvar = " << filePtrSet.
ofsVar
591 filePtrSet.
ofsVar =
new std::ofstream((baseFileName+
"_sub"+this->
subIdString()+
"."+fileType).c_str(),
593 std::cout <<
"filePtrSet.ofsVar(1) = " << filePtrSet.
ofsVar << std::endl;
594 if (filePtrSet.
ofsVar) std::cout <<
"filePtrSet.ofsVar(1)->is_open() = " << filePtrSet.
ofsVar->is_open() << std::endl;
598 filePtrSet.
ofsVar =
new std::ofstream((baseFileName+
"_sub"+this->
subIdString()+
"."+fileType).c_str(),
599 std::ofstream::out | std::ofstream::app);
609 <<
": just opened output file with base name '" << baseFileName <<
"." << fileType
611 <<
", writeOver = " << writeOver
612 <<
", options 'out|in|app'"
613 <<
", osfvar = " << filePtrSet.
ofsVar
620 if ((filePtrSet.
ofsVar == NULL ) ||
621 (filePtrSet.
ofsVar->is_open() ==
false)) {
624 filePtrSet.
ofsVar =
new std::ofstream((baseFileName+
"_sub"+this->
subIdString()+
"."+fileType).c_str(),
625 std::ofstream::out | std::ofstream::trunc);
628 <<
": just opened output file with base name '" << baseFileName <<
"." << fileType
630 <<
", writeOver = " << writeOver
631 <<
", options 'out|trunc'"
632 <<
", osfvar = " << filePtrSet.
ofsVar
638 if (filePtrSet.
ofsVar != NULL) {
641 <<
", subId = " << this->
subId()
642 <<
": succeeded on opening output file with base name '" << baseFileName <<
"." << fileType
644 <<
", writeOver = " << writeOver
649 std::cerr <<
"In BaseEnvironment::openOutputFile()"
650 <<
": failed to open output file with base name '" << baseFileName <<
"." << fileType
667 const std::string& baseFileName,
668 const std::string& inputFileType,
672 std::string fileType(inputFileType);
673 #ifdef QUESO_HAS_HDF5
678 *this->
subDisplayFile() <<
"WARNING in BaseEnvironment::openUnifiedOutputFile()"
680 <<
"' has been requested, but this QUESO library has not been built with 'hdf5'"
686 std::cerr <<
"WARNING in BaseEnvironment::openUnifiedOutputFile()"
688 <<
"' has been requested, but this QUESO library has not been built with 'hdf5'"
697 bool returnValue =
true;
699 if (baseFileName ==
".") {
701 *this->
subDisplayFile() <<
"In BaseEnvironment::openUnifiedOutputFile()"
702 <<
": no unified output file opened with base name '" << baseFileName <<
"." << fileType
704 <<
", writeOver = " << writeOver
714 *this->
subDisplayFile() <<
"In BaseEnvironment::openUnifiedOutputFile()"
715 <<
": opening unified output file with base name '" << baseFileName <<
"." << fileType
717 <<
", writeOver = " << writeOver
725 std::cout <<
"In BaseEnvironment::openUnifiedOutputFile()"
726 <<
": opening output file with base name '" << baseFileName <<
"." << fileType
728 <<
", writeOver = " << writeOver
736 int irtrn =
CheckFilePath((baseFileName+
"."+fileType).c_str());
744 filePtrSet.
ofsVar =
new std::ofstream((baseFileName+
"."+fileType).c_str(),
745 std::ofstream::out | std::ofstream::trunc);
747 #ifdef QUESO_HAS_HDF5
749 filePtrSet.h5Var = H5Fcreate((baseFileName+
"."+fileType).c_str(),
759 *this->
subDisplayFile() <<
"In BaseEnvironment::openUnifiedOutputFile()"
760 <<
": just opened output file with base name '" << baseFileName <<
"." << fileType
762 <<
", writeOver = " << writeOver
763 <<
", options 'out|trunc'"
764 <<
", osfvar = " << filePtrSet.
ofsVar
774 filePtrSet.
ofsVar =
new std::ofstream((baseFileName+
"."+fileType).c_str(),
775 std::ofstream::out | std::ofstream::app);
777 #ifdef QUESO_HAS_HDF5
779 filePtrSet.h5Var = H5Fcreate((baseFileName+
"."+fileType).c_str(),
793 *this->
subDisplayFile() <<
"In BaseEnvironment::openUnifiedOutputFile()"
794 <<
": just opened output file with base name '" << baseFileName <<
"." << fileType
796 <<
", writeOver = " << writeOver
797 <<
", options 'out|in|app'"
798 <<
", osfvar = " << filePtrSet.
ofsVar
801 if ((filePtrSet.
ofsVar == NULL ) ||
802 (filePtrSet.
ofsVar->is_open() ==
false)) {
804 std::cout <<
"Retrying 2..." << std::endl;
807 filePtrSet.
ofsVar =
new std::ofstream((baseFileName+
"."+fileType).c_str(),
808 std::ofstream::out | std::ofstream::trunc);
810 *this->
subDisplayFile() <<
"In BaseEnvironment::openUnifiedOutputFile()"
811 <<
": just opened output file with base name '" << baseFileName <<
"." << fileType
813 <<
", writeOver = " << writeOver
814 <<
", options 'out|trunc'"
815 <<
", osfvar = " << filePtrSet.
ofsVar
820 if (filePtrSet.
ofsVar == NULL) {
821 std::cerr <<
"In BaseEnvironment::openUnifiedOutputFile()"
822 <<
": failed to open unified output file with base name '" << baseFileName <<
"." << fileType
835 const std::string& baseFileName,
836 const std::string& inputFileType,
837 const std::set<unsigned int>& allowedSubEnvIds,
840 std::string fileType(inputFileType);
841 #ifdef QUESO_HAS_HDF5
846 *this->
subDisplayFile() <<
"WARNING in BaseEnvironment::openInputFile()"
848 <<
"' has been requested, but this QUESO library has not been built with 'hdf5'"
854 std::cerr <<
"WARNING in BaseEnvironment::openInputFile()"
856 <<
"' has been requested, but this QUESO library has not been built with 'hdf5'"
865 bool returnValue =
true;
868 (allowedSubEnvIds.find(this->subId()) == allowedSubEnvIds.end() )) {
871 <<
": no input file opened with base name '" << baseFileName <<
"." << fileType
883 <<
": opening input file with base name '" << baseFileName <<
"." << fileType
893 int irtrn =
CheckFilePath((baseFileName+
"."+fileType).c_str());
897 filePtrSet.
ifsVar =
new std::ifstream((baseFileName+
"."+fileType).c_str(),
899 if ((filePtrSet.
ifsVar == NULL) || (filePtrSet.
ifsVar->is_open() ==
false)) {
900 std::cerr <<
"In BaseEnvironment::openInputFile()"
901 <<
": failed to open input file with base name '" << baseFileName <<
"." << fileType
907 #ifdef QUESO_HAS_HDF5
909 filePtrSet.h5Var = H5Fopen((baseFileName+
"."+fileType).c_str(),
929 const std::string& baseFileName,
930 const std::string& inputFileType,
933 std::string fileType(inputFileType);
934 #ifdef QUESO_HAS_HDF5
939 *this->
subDisplayFile() <<
"WARNING in BaseEnvironment::openUnifiedInputFile()"
941 <<
"' has been requested, but this QUESO library has not been built with 'hdf5'"
947 std::cerr <<
"WARNING in BaseEnvironment::openUnifiedInputFile()"
949 <<
"' has been requested, but this QUESO library has not been built with 'hdf5'"
958 bool returnValue =
true;
962 *this->
subDisplayFile() <<
"In BaseEnvironment::openUnifiedInputFile()"
963 <<
": no input file opened with base name '" << baseFileName <<
"." << fileType
974 *this->
subDisplayFile() <<
"In BaseEnvironment::openUnifiedInputFile()"
975 <<
": opening input file with base name '" << baseFileName <<
"." << fileType
985 int irtrn =
CheckFilePath((baseFileName+
"."+fileType).c_str());
989 filePtrSet.
ifsVar =
new std::ifstream((baseFileName+
"."+fileType).c_str(),
991 if ((filePtrSet.
ifsVar == NULL) || (filePtrSet.
ifsVar->is_open() ==
false)) {
992 std::cerr <<
"In BaseEnvironment::openUnifiedInputFile()"
993 <<
": failed to open input file with base name '" << baseFileName <<
"." << fileType
999 #ifdef QUESO_HAS_HDF5
1001 filePtrSet.h5Var = H5Fopen((baseFileName+
"."+fileType).c_str(),
1022 const std::string& inputFileType)
const
1024 std::string fileType(inputFileType);
1025 #ifdef QUESO_HAS_HDF5
1030 *this->
subDisplayFile() <<
"WARNING in BaseEnvironment::closeFile()"
1032 <<
"' has been requested, but this QUESO library has not been built with 'hdf5'"
1038 std::cerr <<
"WARNING in BaseEnvironment::closeFile()"
1040 <<
"' has been requested, but this QUESO library has not been built with 'hdf5'"
1051 delete filePtrSet.
ofsVar;
1052 filePtrSet.
ofsVar = NULL;
1055 delete filePtrSet.
ifsVar;
1056 filePtrSet.
ifsVar = NULL;
1058 #ifdef QUESO_HAS_HDF5
1060 H5Fclose(filePtrSet.h5Var);
1109 const char* passedOptionsInputFileName,
1115 #ifdef QUESO_MEMORY_DEBUGGING
1116 std::cout <<
"Entering FullEnv" << std::endl;
1122 int mpiRC = MPI_Comm_rank(inputComm,&
m_worldRank);
1135 #ifdef QUESO_MEMORY_DEBUGGING
1136 std::cout <<
"In FullEnv, finished dealing with MPI initially" << std::endl;
1150 m_allOptionsDesc =
new boost::program_options::options_description(
"Allowed options");
1163 std::cout << (*m_optionsObj) << std::endl;
1168 "total number of processors in environment must be multiple of the specified number of subEnvironments");
1170 #ifdef QUESO_MEMORY_DEBUGGING
1171 std::cout <<
"In FullEnv, finished scanning options" << std::endl;
1191 std::cout <<
"Beginning run at " << ctime(&
m_timevalBegin.tv_sec)
1203 sprintf(tmpSubId,
"%u",
m_subId);
1210 std::vector<int> fullRanksOfMySubEnvironment(numRanksPerSubEnvironment,0);
1211 for (
unsigned int i = 0; i < numRanksPerSubEnvironment; ++i) {
1212 fullRanksOfMySubEnvironment[i] =
m_subId * numRanksPerSubEnvironment + i;
1215 mpiRC = MPI_Group_incl(
m_fullGroup, (
int) numRanksPerSubEnvironment, &fullRanksOfMySubEnvironment[0], &
m_subGroup);
1235 fullRanksOfInter0[i] = i * numRanksPerSubEnvironment;
1242 if (
m_fullRank%numRanksPerSubEnvironment == 0) {
1261 bool openFile =
false;
1287 std::ofstream::out | std::ofstream::trunc);
1303 std::cout <<
"MPI node of worldRank " <<
m_worldRank
1305 <<
", belongs to subEnvironment of id " <<
m_subId
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];
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];
1326 std::cout << std::endl;
1347 std::cerr <<
"In Environment::constructor()"
1360 *
m_subDisplayFile <<
"Done with initializations at FullEnvironment::commonConstructor()"
1380 int mpi_initialized;
1381 MPI_Initialized (&mpi_initialized);
1383 if (mpi_initialized)
1386 MPI_Abort(MPI_COMM_WORLD, 1);
1404 if (ifs->is_open()) {
1409 if (
m_fullRank == 0) std::cout <<
"An invalid input file has been passed to the 'environment' class constructor!"
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."
#define QUESO_TRILINOS_DIR
MPI_Comm RawType_MPI_Comm
unsigned int displayVerbosity() const
const MpiComm & subComm() const
Access function for MpiComm sub communicator.
#define QUESO_MAJOR_VERSION
void print(std::ostream &os) const
Sends the environment options to the stream.
BasicPdfsBase * m_basicPdfs
int subRank() const
Access function for sub-rank.
bool m_exceptionalCircumstance
boost::program_options::variables_map * m_allOptionsMap
void setOptionsInputFileAccessState(bool newState) const
bool exceptionalCircumstance() const
Decides whether there is an exceptional circumstance.
int MyPID() const
Return my process ID.
void scanInputFileForMyOptions(const boost::program_options::options_description &optionsDesc) const
This method scans the input file provided by the user to QUESO.
int seed() const
Access to the RNG seed.
#define UQ_FILE_EXTENSION_FOR_HDF_FORMAT
std::string m_optionsInputFileName
FilePtrSetStruct()
Struct constructor.
#define QUESO_BUILD_VERSION
std::terminate_handler old_terminate_handler
void Barrier() const
Pause every process in *this communicator until all the processes reach this point.
int NumProc() const
Returns total number of processes.
~FilePtrSetStruct()
Destructor.
TODO: Base class for basic PDFs using Boost library.
std::ofstream * ofsVar
Provides a stream interface to write data to files.
int fullRank() const
Returns the process full rank.
unsigned int m_checkingLevel
Checking level.
#define queso_require_not_equal_to_msg(expr1, expr2, msg)
Struct for handling data input and output from files.
EmptyEnvironment()
Default constructor. Does nothing.
std::string identifyingString() const
Access function to private attribute m_identifyingString: identifying string.
int m_seed
Seed of the random number generator.
void readOptionsInputFile()
Checks the options input file and reads the options.
RawType_MPI_Group subGroup() const
Access function for sub-group.
#define queso_error_msg(msg)
const MpiComm & fullComm() const
Access function for MpiComm full communicator.
This class provides a suite options one can pass to a QUESO environment.
int seed() const
Sets the seed.
void QUESO_version_print(std::ostream &os)
unsigned int m_syncVerbosity
Synchronized verbosity.
unsigned int syncVerbosity() const
Access function to private attribute m_syncVerbosity.
#define QUESO_LIB_VERSION
EnvOptionsValues * m_optionsObj
unsigned int numSubEnvironments() const
Access function to the number of sub-environments.
unsigned int m_displayVerbosity
Verbosity.
boost::program_options::variables_map & allOptionsMap() const
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.
std::string m_subDisplayFileName
Output filename for sub-screen writing.
int inter0Rank() const
Returns the process inter0 rank.
int QUESO_get_numeric_version()
#define QUESO_MICRO_VERSION
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.
unsigned int m_numSubEnvironments
The QUESO MPI Communicator Class.
virtual ~BaseEnvironment()
Destructor.
FullEnvironment(RawType_MPI_Comm inputComm, const char *passedOptionsInputFileName, const char *prefix, EnvOptionsValues *alternativeOptionsValues)
Default constructor.
void closeFile(FilePtrSetStruct &filePtrSet, const std::string &fileType) const
Closes the file.
#define queso_require_equal_to_msg(expr1, expr2, msg)
std::string m_subIdString
~FullEnvironment()
Destructor.
std::string optionsInputFileName() const
Access to the attribute m_optionsInputFileName, which stores the name of the input file passed by the...
const MpiComm & selfComm() const
Access function for MpiComm self-communicator.
bool fullEnvIsReady() const
Returns whether the full environment class is ready (constructor has successfully been called)...
#define queso_require_msg(asserted, msg)
Class for random number generation (base class for either GSL or Boost RNG).
std::ofstream * subDisplayFile() const
Access function for m_subDisplayFile (displays file on stream).
RawType_MPI_Group m_fullGroup
~EmptyEnvironment()
Destructor.
int CheckFilePath(const char *path)
RawType_MPI_Comm Comm() const
Extract MPI Communicator from a MpiComm object.
This (virtual) class sets up the environment underlying the use of the QUESO library by an executable...
void setExceptionalCircumstance(bool value) const
Set an exceptional circumstance.
bool m_subDisplayAllowAll
Allows (or not) all sub-environments to write to output file.
#define UQ_FILE_EXTENSION_FOR_MATLAB_FORMAT
std::set< unsigned int > m_subDisplayAllowedSet
Sub-environments that will write to output.
boost::program_options::options_description * m_allOptionsDesc
unsigned int subId() const
Access function to the number of each sub-environment Id: m_subId.
void resetSeed(int newSeedOption)
Reset RNG seed.
TODO: Base class for basic PDFs (via either GSL or Boost).
virtual void resetSeed(int newSeed)
Resets the seed with value newSeed.
bool m_optionsInputFileAccessState
std::string platformName() const
Access to the platform name.
#define QUESO_MINOR_VERSION
const MpiComm & inter0Comm() const
Access function for MpiComm inter0-communicator.
#define queso_deprecated()
struct timeval m_timevalBegin
std::ofstream * m_subDisplayFile
const BasicPdfsBase * basicPdfs() const
Access to Basic PDFs.
RawType_MPI_Group m_inter0Group
#define RawValue_MPI_COMM_SELF
const RngBase * rngObject() const
Access to the RNG object.
std::string m_rngType
Type of the random number generator.
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...
#define queso_require_greater_equal_msg(expr1, expr2, msg)
std::ifstream * ifsVar
Provides a stream interface to read data from files.
unsigned int checkingLevel() const
Access function to private attribute m_checkingLevel.
std::string m_platformName
Platform name.
std::string subDisplayFileName() const
Access function for m_subDisplayFileName (displays filename on stream).
std::string m_identifyingString
Identifying string.
int worldRank() const
Returns the process world rank.
bool m_subDisplayAllowInter0
Allows (or not) all inter0 nodes to write to output file.
TODO: Base class for basic PDFs using Gsl library.
#define QUESO_LIB_RELEASE
#define UQ_ENV_FILENAME_FOR_NO_INPUT_FILE
void resetIdentifyingString(const std::string &newString)
Reset private attribute m_identifyingString with the value newString.
RawType_MPI_Group m_subGroup
BaseEnvironment(const char *passedOptionsInputFileName, EnvOptionsValues *alternativeOptionsValues)
Default constructor.
void queso_terminate_handler()
Function for unhandled exceptions in Queso.
bool openUnifiedInputFile(const std::string &fileName, const std::string &fileType, FilePtrSetStruct &filePtrSet) const
Opens the unified input file.
void print(std::ostream &os) const
#define UQ_ENV_FILENAME_FOR_NO_OUTPUT_FILE
bool openInputFile(const std::string &fileName, const std::string &fileType, const std::set< unsigned int > &allowedSubEnvIds, FilePtrSetStruct &filePtrSet) const
Opens an input file.
MPI_Group RawType_MPI_Group