25 #include <queso/Environment.h>
27 #ifndef QUESO_DISABLE_BOOST_PROGRAM_OPTIONS
28 #include <boost/program_options.hpp>
29 #endif // QUESO_DISABLE_BOOST_PROGRAM_OPTIONS
31 #include <queso/getpot.h>
33 #include <queso/config_queso.h>
34 #include <queso/EnvironmentOptions.h>
35 #include <queso/RngGsl.h>
36 #include <queso/RngBoost.h>
37 #include <queso/RngCXX11.h>
38 #include <queso/BasicPdfsGsl.h>
39 #include <queso/BasicPdfsBoost.h>
40 #include <queso/BasicPdfsCXX11.h>
41 #include <queso/Miscellaneous.h>
48 #include <queso/asserts.h>
59 os <<
"------------------------------------------------------------------------------------------" ;
60 os <<
"--------------------" << std::endl;
61 os <<
"QUESO Library: Version = " << QUESO_VERSION;
64 os << QUESO_BUILD_DEVSTATUS << std::endl << std::endl;
66 os <<
"Build Date = " << QUESO_BUILD_DATE << std::endl;
67 os <<
"Build Host = " << QUESO_BUILD_HOST << std::endl;
68 os <<
"Build User = " << QUESO_BUILD_USER << std::endl;
69 os <<
"Build Arch = " << QUESO_BUILD_ARCH << std::endl;
70 os <<
"Build Rev = " << QUESO_BUILD_VERSION << std::endl << std::endl;
72 os <<
"C++ Config = " << QUESO_CXX <<
" " << QUESO_CXXFLAGS << std::endl;
74 os <<
"Trilinos DIR = " << QUESO_TRILINOS_DIR << std::endl;
75 os <<
"GSL Libs = " << QUESO_GSL_DIR << std::endl;
76 os <<
"GRVY DIR = " << QUESO_GRVY_DIR << std::endl;
77 os <<
"GLPK DIR = " << QUESO_GLPK_DIR << std::endl;
78 os <<
"HDF5 DIR = " << QUESO_HDF5_DIR << std::endl;
79 os <<
"------------------------------------------------------------------------------------------" ;
80 os <<
"--------------------" << std::endl;
99 int major_version = 0;
100 int minor_version = 0;
101 int micro_version = 0;
103 #ifdef QUESO_MAJOR_VERSION
104 major_version = QUESO_MAJOR_VERSION;
107 #ifdef QUESO_MINOR_VERSION
108 minor_version = QUESO_MINOR_VERSION;
111 #ifdef QUESO_MICRO_VERSION
112 micro_version = QUESO_MICRO_VERSION;
115 return(major_version*10000 + minor_version*100 + micro_version);
122 #ifdef QUESO_HAS_HDF5
130 FilePtrSetStruct::~FilePtrSetStruct()
145 BaseEnvironment::BaseEnvironment(
146 const char* passedOptionsInputFileName,
149 m_fullEnvIsReady (false),
154 m_optionsInputFileName (
""),
155 m_optionsInputFileAccessState(true),
156 #ifndef QUESO_DISABLE_BOOST_PROGRAM_OPTIONS
160 m_input (new GetPot),
167 m_inter0CommSize (1),
171 m_exceptionalCircumstance (false),
179 if (alternativeOptionsValues != NULL) {
185 const std::string& passedOptionsInputFileName,
188 m_fullEnvIsReady (false),
193 m_optionsInputFileName (passedOptionsInputFileName),
194 m_optionsInputFileAccessState(true),
195 #ifndef QUESO_DISABLE_BOOST_PROGRAM_OPTIONS
199 m_input (new GetPot),
206 m_inter0CommSize (1),
210 m_exceptionalCircumstance (false),
216 if (alternativeOptionsValues != NULL) {
229 struct timeval timevalNow;
231 gettimeofday(&timevalNow, NULL);
236 <<
"Total run time = " << timevalNow.tv_sec -
m_timevalBegin.tv_sec
242 std::cout <<
"Ending run at " << ctime(&timevalNow.tv_sec)
243 <<
"Total run time = " << timevalNow.tv_sec -
m_timevalBegin.tv_sec
276 queso_require_msg(
m_fullComm,
"m_fullComm variable is NULL");
295 queso_require_msg(
m_subComm,
"m_subComm variable is NULL");
302 queso_require_msg(
m_selfComm,
"m_selfComm variable is NULL");
315 queso_require_msg(
m_inter0Comm,
"m_inter0Comm variable is NULL");
337 queso_require_msg(
m_optionsObj,
"m_optionsObj variable is NULL");
372 #ifndef QUESO_DISABLE_BOOST_PROGRAM_OPTIONS
373 #ifdef UQ_USES_COMMAND_LINE_OPTIONS
374 const boost::program_options::options_description&
382 #endif // QUESO_DISABLE_BOOST_PROGRAM_OPTIONS
384 #ifndef QUESO_DISABLE_BOOST_PROGRAM_OPTIONS
385 boost::program_options::variables_map&
390 queso_require_msg(
m_allOptionsMap,
"m_allOptionsMap variable is NULL");
393 #endif // QUESO_DISABLE_BOOST_PROGRAM_OPTIONS
395 #ifndef QUESO_DISABLE_BOOST_PROGRAM_OPTIONS
401 #ifdef UQ_USES_COMMAND_LINE_OPTIONS
413 #ifdef QUESO_MEMORY_DEBUGGING
414 std::cout <<
"Entering BaseEnv::scanInputFileForMyOptions()" << std::endl;
425 std::string(
"m_optionsInputFileName is 'nothing'"));
428 #ifdef QUESO_MEMORY_DEBUGGING
429 std::cout <<
"in BaseEnv::scanInputFileForMyOptions(), before store(a)" << std::endl;
432 queso_require_msg(
m_allOptionsMap,
"m_allOptionsMap variable is NULL");
434 #ifdef QUESO_MEMORY_DEBUGGING
435 std::cout <<
"in BaseEnv::scanInputFileForMyOptions(), after store(a)" << std::endl;
441 #ifdef QUESO_MEMORY_DEBUGGING
442 std::cout <<
"Leaving BaseEnv::scanInputFileForMyOptions()" << std::endl;
447 #endif // QUESO_DISABLE_BOOST_PROGRAM_OPTIONS
452 queso_require_msg(
m_optionsObj,
"m_optionsObj variable is NULL");
459 queso_require_msg(
m_optionsObj,
"m_optionsObj variable is NULL");
466 queso_require_msg(
m_optionsObj,
"m_optionsObj variable is NULL");
517 return m_timevalBegin;
522 const std::string& baseFileName,
523 const std::string& inputFileType,
524 const std::set<unsigned int>& allowedSubEnvIds,
528 std::string fileType(inputFileType);
529 #ifdef QUESO_HAS_HDF5
532 if (fileType == UQ_FILE_EXTENSION_FOR_HDF_FORMAT) {
534 *this->
subDisplayFile() <<
"WARNING in BaseEnvironment::openOutputFile()"
535 <<
": file format '" << UQ_FILE_EXTENSION_FOR_HDF_FORMAT
536 <<
"' has been requested, but this QUESO library has not been built with 'hdf5'"
537 <<
". Code will therefore process the file format '" << UQ_FILE_EXTENSION_FOR_HDF_FORMAT
542 std::cerr <<
"WARNING in BaseEnvironment::openOutputFile()"
543 <<
": file format '" << UQ_FILE_EXTENSION_FOR_HDF_FORMAT
544 <<
"' has been requested, but this QUESO library has not been built with 'hdf5'"
545 <<
". Code will therefore process the file format '" << UQ_FILE_EXTENSION_FOR_HDF_FORMAT
549 fileType = UQ_FILE_EXTENSION_FOR_MATLAB_FORMAT;
553 bool returnValue =
true;
555 if ((baseFileName == UQ_ENV_FILENAME_FOR_NO_OUTPUT_FILE) ||
556 (allowedSubEnvIds.find(this->subId()) == allowedSubEnvIds.end() )) {
559 <<
", subId = " << this->
subId()
560 <<
": no output file opened with base name '" << baseFileName <<
"." << fileType
562 <<
", writeOver = " << writeOver
573 <<
", subId = " << this->
subId()
574 <<
": opening output file with base name '" << baseFileName <<
"." << fileType
576 <<
", writeOver = " << writeOver
582 std::cout <<
"In BaseEnvironment::openOutputFile()"
583 <<
": opening output file with base name '" << baseFileName <<
"." << fileType
585 <<
", writeOver = " << writeOver
596 <<
", subId = " << this->
subId()
597 <<
", trying to open output file with base name '" << baseFileName <<
"." << fileType
599 <<
", writeOver = " << writeOver
600 <<
": calling CheckFilePath()..."
606 <<
", subId = " << this->
subId()
607 <<
", trying to open output file with base name '" << baseFileName <<
"." << fileType
609 <<
", writeOver = " << writeOver
610 <<
": returned from CheckFilePath() with irtrn = " << irtrn
613 queso_require_greater_equal_msg(irtrn, 0,
"unable to verify output path");
619 if ((fileType == UQ_FILE_EXTENSION_FOR_MATLAB_FORMAT) ||
620 (fileType == UQ_FILE_EXTENSION_FOR_TXT_FORMAT)) {
621 filePtrSet.
ofsVar =
new std::ofstream((baseFileName+
"_sub"+this->
subIdString()+
"."+fileType).c_str(),
622 std::ofstream::out | std::ofstream::trunc);
624 else if (fileType == UQ_FILE_EXTENSION_FOR_HDF_FORMAT) {
625 queso_error_msg(
"hdf file type not supported yet");
628 queso_error_msg(
"invalid file type");
632 <<
": just opened output file with base name '" << baseFileName <<
"." << fileType
634 <<
", writeOver = " << writeOver
635 <<
", options 'out|trunc'"
636 <<
", osfvar = " << filePtrSet.
ofsVar
644 if ((fileType == UQ_FILE_EXTENSION_FOR_MATLAB_FORMAT) ||
645 (fileType == UQ_FILE_EXTENSION_FOR_TXT_FORMAT)) {
647 filePtrSet.
ofsVar =
new std::ofstream((baseFileName+
"_sub"+this->
subIdString()+
"."+fileType).c_str(),
649 std::cout <<
"filePtrSet.ofsVar(1) = " << filePtrSet.
ofsVar << std::endl;
650 if (filePtrSet.
ofsVar) std::cout <<
"filePtrSet.ofsVar(1)->is_open() = " << filePtrSet.
ofsVar->is_open() << std::endl;
654 filePtrSet.
ofsVar =
new std::ofstream((baseFileName+
"_sub"+this->
subIdString()+
"."+fileType).c_str(),
655 std::ofstream::out | std::ofstream::app);
657 #ifdef QUESO_HAS_HDF5
658 else if (fileType == UQ_FILE_EXTENSION_FOR_HDF_FORMAT) {
659 std::string fullFileName =
660 baseFileName+
"_sub"+this->
subIdString()+
"."+fileType;
663 filePtrSet.
h5Var = H5Fcreate(fullFileName.c_str(),
668 queso_require_greater_equal_msg(
670 "error opening file `" << fullFileName <<
"`");
674 queso_error_msg(
"invalid file type");
678 <<
": just opened output file with base name '" << baseFileName <<
"." << fileType
680 <<
", writeOver = " << writeOver
681 <<
", options 'out|in|app'"
682 <<
", osfvar = " << filePtrSet.
ofsVar
686 if (fileType == UQ_FILE_EXTENSION_FOR_MATLAB_FORMAT) {
689 if ((filePtrSet.
ofsVar == NULL ) ||
690 (filePtrSet.
ofsVar->is_open() ==
false)) {
693 filePtrSet.
ofsVar =
new std::ofstream((baseFileName+
"_sub"+this->
subIdString()+
"."+fileType).c_str(),
694 std::ofstream::out | std::ofstream::trunc);
697 <<
": just opened output file with base name '" << baseFileName <<
"." << fileType
699 <<
", writeOver = " << writeOver
700 <<
", options 'out|trunc'"
701 <<
", osfvar = " << filePtrSet.
ofsVar
709 if ((fileType == UQ_FILE_EXTENSION_FOR_MATLAB_FORMAT) ||
710 (fileType == UQ_FILE_EXTENSION_FOR_TXT_FORMAT)) {
713 "failed to open output file");
727 const std::string& baseFileName,
728 const std::string& inputFileType,
732 std::string fileType(inputFileType);
733 #ifdef QUESO_HAS_HDF5
736 if (fileType == UQ_FILE_EXTENSION_FOR_HDF_FORMAT) {
738 *this->
subDisplayFile() <<
"WARNING in BaseEnvironment::openUnifiedOutputFile()"
739 <<
": file format '" << UQ_FILE_EXTENSION_FOR_HDF_FORMAT
740 <<
"' has been requested, but this QUESO library has not been built with 'hdf5'"
741 <<
". Code will therefore process the file format '" << UQ_FILE_EXTENSION_FOR_HDF_FORMAT
746 std::cerr <<
"WARNING in BaseEnvironment::openUnifiedOutputFile()"
747 <<
": file format '" << UQ_FILE_EXTENSION_FOR_HDF_FORMAT
748 <<
"' has been requested, but this QUESO library has not been built with 'hdf5'"
749 <<
". Code will therefore process the file format '" << UQ_FILE_EXTENSION_FOR_HDF_FORMAT
753 fileType = UQ_FILE_EXTENSION_FOR_MATLAB_FORMAT;
757 bool returnValue =
true;
759 if (baseFileName ==
".") {
761 *this->
subDisplayFile() <<
"In BaseEnvironment::openUnifiedOutputFile()"
762 <<
": no unified output file opened with base name '" << baseFileName <<
"." << fileType
764 <<
", writeOver = " << writeOver
774 *this->
subDisplayFile() <<
"In BaseEnvironment::openUnifiedOutputFile()"
775 <<
": opening unified output file with base name '" << baseFileName <<
"." << fileType
777 <<
", writeOver = " << writeOver
785 std::cout <<
"In BaseEnvironment::openUnifiedOutputFile()"
786 <<
": opening output file with base name '" << baseFileName <<
"." << fileType
788 <<
", writeOver = " << writeOver
796 int irtrn =
CheckFilePath((baseFileName+
"."+fileType).c_str());
797 queso_require_greater_equal_msg(irtrn, 0,
"unable to verify output path");
803 if ((fileType == UQ_FILE_EXTENSION_FOR_MATLAB_FORMAT) ||
804 (fileType == UQ_FILE_EXTENSION_FOR_TXT_FORMAT)) {
805 filePtrSet.
ofsVar =
new std::ofstream((baseFileName+
"."+fileType).c_str(),
806 std::ofstream::out | std::ofstream::trunc);
808 #ifdef QUESO_HAS_HDF5
809 else if (fileType == UQ_FILE_EXTENSION_FOR_HDF_FORMAT) {
810 filePtrSet.
h5Var = H5Fcreate((baseFileName+
"."+fileType).c_str(),
817 queso_error_msg(
"invalid file type");
820 *this->
subDisplayFile() <<
"In BaseEnvironment::openUnifiedOutputFile()"
821 <<
": just opened output file with base name '" << baseFileName <<
"." << fileType
823 <<
", writeOver = " << writeOver
824 <<
", options 'out|trunc'"
825 <<
", osfvar = " << filePtrSet.
ofsVar
834 if ((fileType == UQ_FILE_EXTENSION_FOR_MATLAB_FORMAT) ||
835 (fileType == UQ_FILE_EXTENSION_FOR_TXT_FORMAT)) {
836 filePtrSet.
ofsVar =
new std::ofstream((baseFileName+
"."+fileType).c_str(),
837 std::ofstream::out | std::ofstream::app);
839 #ifdef QUESO_HAS_HDF5
840 else if (fileType == UQ_FILE_EXTENSION_FOR_HDF_FORMAT) {
841 filePtrSet.
h5Var = H5Fcreate((baseFileName+
"."+fileType).c_str(),
852 queso_error_msg(
"invalid file type");
855 *this->
subDisplayFile() <<
"In BaseEnvironment::openUnifiedOutputFile()"
856 <<
": just opened output file with base name '" << baseFileName <<
"." << fileType
858 <<
", writeOver = " << writeOver
859 <<
", options 'out|in|app'"
860 <<
", osfvar = " << filePtrSet.
ofsVar
863 if ((filePtrSet.
ofsVar == NULL ) ||
864 (filePtrSet.
ofsVar->is_open() ==
false)) {
866 std::cout <<
"Retrying 2..." << std::endl;
869 filePtrSet.
ofsVar =
new std::ofstream((baseFileName+
"."+fileType).c_str(),
870 std::ofstream::out | std::ofstream::trunc);
872 *this->
subDisplayFile() <<
"In BaseEnvironment::openUnifiedOutputFile()"
873 <<
": just opened output file with base name '" << baseFileName <<
"." << fileType
875 <<
", writeOver = " << writeOver
876 <<
", options 'out|trunc'"
877 <<
", osfvar = " << filePtrSet.
ofsVar
882 if (filePtrSet.
ofsVar == NULL) {
883 std::cerr <<
"In BaseEnvironment::openUnifiedOutputFile()"
884 <<
": failed to open unified output file with base name '" << baseFileName <<
"." << fileType
888 queso_require_msg((filePtrSet.
ofsVar && filePtrSet.
ofsVar->is_open()),
"failed to open output file");
897 const std::string& baseFileName,
898 const std::string& inputFileType,
899 const std::set<unsigned int>& allowedSubEnvIds,
902 std::string fileType(inputFileType);
903 #ifdef QUESO_HAS_HDF5
906 if (fileType == UQ_FILE_EXTENSION_FOR_HDF_FORMAT) {
908 *this->
subDisplayFile() <<
"WARNING in BaseEnvironment::openInputFile()"
909 <<
": file format '" << UQ_FILE_EXTENSION_FOR_HDF_FORMAT
910 <<
"' has been requested, but this QUESO library has not been built with 'hdf5'"
911 <<
". Code will therefore process the file format '" << UQ_FILE_EXTENSION_FOR_HDF_FORMAT
916 std::cerr <<
"WARNING in BaseEnvironment::openInputFile()"
917 <<
": file format '" << UQ_FILE_EXTENSION_FOR_HDF_FORMAT
918 <<
"' has been requested, but this QUESO library has not been built with 'hdf5'"
919 <<
". Code will therefore process the file format '" << UQ_FILE_EXTENSION_FOR_HDF_FORMAT
923 fileType = UQ_FILE_EXTENSION_FOR_MATLAB_FORMAT;
927 bool returnValue =
true;
929 if ((baseFileName == UQ_ENV_FILENAME_FOR_NO_INPUT_FILE) ||
930 (allowedSubEnvIds.find(this->subId()) == allowedSubEnvIds.end() )) {
933 <<
": no input file opened with base name '" << baseFileName <<
"." << fileType
945 <<
": opening input file with base name '" << baseFileName <<
"." << fileType
955 int irtrn =
CheckFilePath((baseFileName+
"."+fileType).c_str());
956 queso_require_greater_equal_msg(irtrn, 0,
"unable to verify input path");
958 if ((fileType == UQ_FILE_EXTENSION_FOR_MATLAB_FORMAT) ||
959 (fileType == UQ_FILE_EXTENSION_FOR_TXT_FORMAT)) {
960 filePtrSet.
ifsVar =
new std::ifstream((baseFileName+
"."+fileType).c_str(),
962 if ((filePtrSet.
ifsVar == NULL) || (filePtrSet.
ifsVar->is_open() ==
false)) {
963 std::cerr <<
"In BaseEnvironment::openInputFile()"
964 <<
": failed to open input file with base name '" << baseFileName <<
"." << fileType
968 queso_require_msg(!((filePtrSet.
ifsVar == NULL) || (filePtrSet.
ifsVar->is_open() ==
false)),
"file with fileName could not be found");
970 #ifdef QUESO_HAS_HDF5
971 else if (fileType == UQ_FILE_EXTENSION_FOR_HDF_FORMAT) {
972 filePtrSet.
h5Var = H5Fopen((baseFileName+
"."+fileType).c_str(),
978 queso_error_msg(
"invalid file type");
992 const std::string& baseFileName,
993 const std::string& inputFileType,
996 std::string fileType(inputFileType);
997 #ifdef QUESO_HAS_HDF5
1000 if (fileType == UQ_FILE_EXTENSION_FOR_HDF_FORMAT) {
1002 *this->
subDisplayFile() <<
"WARNING in BaseEnvironment::openUnifiedInputFile()"
1003 <<
": file format '" << UQ_FILE_EXTENSION_FOR_HDF_FORMAT
1004 <<
"' has been requested, but this QUESO library has not been built with 'hdf5'"
1005 <<
". Code will therefore process the file format '" << UQ_FILE_EXTENSION_FOR_HDF_FORMAT
1010 std::cerr <<
"WARNING in BaseEnvironment::openUnifiedInputFile()"
1011 <<
": file format '" << UQ_FILE_EXTENSION_FOR_HDF_FORMAT
1012 <<
"' has been requested, but this QUESO library has not been built with 'hdf5'"
1013 <<
". Code will therefore process the file format '" << UQ_FILE_EXTENSION_FOR_HDF_FORMAT
1017 fileType = UQ_FILE_EXTENSION_FOR_MATLAB_FORMAT;
1021 bool returnValue =
true;
1022 filePtrSet.
ifsVar = NULL;
1023 if (baseFileName == UQ_ENV_FILENAME_FOR_NO_INPUT_FILE) {
1025 *this->
subDisplayFile() <<
"In BaseEnvironment::openUnifiedInputFile()"
1026 <<
": no input file opened with base name '" << baseFileName <<
"." << fileType
1030 returnValue =
false;
1037 *this->
subDisplayFile() <<
"In BaseEnvironment::openUnifiedInputFile()"
1038 <<
": opening input file with base name '" << baseFileName <<
"." << fileType
1048 int irtrn =
CheckFilePath((baseFileName+
"."+fileType).c_str());
1049 queso_require_greater_equal_msg(irtrn, 0,
"unable to verify input path");
1051 if ((fileType == UQ_FILE_EXTENSION_FOR_MATLAB_FORMAT) ||
1052 (fileType == UQ_FILE_EXTENSION_FOR_TXT_FORMAT)) {
1053 filePtrSet.
ifsVar =
new std::ifstream((baseFileName+
"."+fileType).c_str(),
1055 if ((filePtrSet.
ifsVar == NULL) || (filePtrSet.
ifsVar->is_open() ==
false)) {
1056 std::cerr <<
"In BaseEnvironment::openUnifiedInputFile()"
1057 <<
": failed to open input file with base name '" << baseFileName <<
"." << fileType
1061 queso_require_msg(!((filePtrSet.
ifsVar == NULL) || (filePtrSet.
ifsVar->is_open() ==
false)),
"file with fileName could not be found");
1063 #ifdef QUESO_HAS_HDF5
1064 else if (fileType == UQ_FILE_EXTENSION_FOR_HDF_FORMAT) {
1065 filePtrSet.
h5Var = H5Fopen((baseFileName+
"."+fileType).c_str(),
1071 queso_error_msg(
"invalid file type");
1086 const std::string& inputFileType)
const
1088 std::string fileType(inputFileType);
1089 #ifdef QUESO_HAS_HDF5
1092 if (fileType == UQ_FILE_EXTENSION_FOR_HDF_FORMAT) {
1094 *this->
subDisplayFile() <<
"WARNING in BaseEnvironment::closeFile()"
1095 <<
": file format '" << UQ_FILE_EXTENSION_FOR_HDF_FORMAT
1096 <<
"' has been requested, but this QUESO library has not been built with 'hdf5'"
1097 <<
". Code will therefore process the file format '" << UQ_FILE_EXTENSION_FOR_HDF_FORMAT
1102 std::cerr <<
"WARNING in BaseEnvironment::closeFile()"
1103 <<
": file format '" << UQ_FILE_EXTENSION_FOR_HDF_FORMAT
1104 <<
"' has been requested, but this QUESO library has not been built with 'hdf5'"
1105 <<
". Code will therefore process the file format '" << UQ_FILE_EXTENSION_FOR_HDF_FORMAT
1109 fileType = UQ_FILE_EXTENSION_FOR_MATLAB_FORMAT;
1113 if ((fileType == UQ_FILE_EXTENSION_FOR_MATLAB_FORMAT) ||
1114 (fileType == UQ_FILE_EXTENSION_FOR_TXT_FORMAT)) {
1116 delete filePtrSet.
ofsVar;
1117 filePtrSet.
ofsVar = NULL;
1120 delete filePtrSet.
ifsVar;
1121 filePtrSet.
ifsVar = NULL;
1123 #ifdef QUESO_HAS_HDF5
1124 else if (fileType == UQ_FILE_EXTENSION_FOR_HDF_FORMAT) {
1125 H5Fclose(filePtrSet.
h5Var);
1129 queso_error_msg(
"invalid file type");
1178 #ifdef QUESO_HAS_MPI
1181 const char* passedOptionsInputFileName,
1192 const std::string& passedOptionsInputFileName,
1193 const std::string& prefix,
1198 this->
construct(inputComm, prefix.c_str());
1205 #ifdef QUESO_MEMORY_DEBUGGING
1206 std::cout <<
"Entering FullEnv" << std::endl;
1212 int mpiRC = MPI_Comm_rank(inputComm,&
m_worldRank);
1226 #ifdef QUESO_MEMORY_DEBUGGING
1227 std::cout <<
"In FullEnv, finished dealing with MPI initially" << std::endl;
1238 #ifndef QUESO_DISABLE_BOOST_PROGRAM_OPTIONS
1240 m_allOptionsDesc.reset(
new boost::program_options::options_description(
"Allowed options"));
1241 #endif // QUESO_DISABLE_BOOST_PROGRAM_OPTIONS
1254 std::cout << (*m_optionsObj) << std::endl;
1259 "total number of processors in environment must be multiple of the specified number of subEnvironments");
1261 #ifdef QUESO_MEMORY_DEBUGGING
1262 std::cout <<
"In FullEnv, finished scanning options" << std::endl;
1282 std::cout <<
"Beginning run at " << ctime(&
m_timevalBegin.tv_sec)
1294 sprintf(tmpSubId,
"%u",
m_subId);
1301 std::vector<int> fullRanksOfMySubEnvironment(numRanksPerSubEnvironment,0);
1302 for (
unsigned int i = 0; i < numRanksPerSubEnvironment; ++i) {
1303 fullRanksOfMySubEnvironment[i] =
m_subId * numRanksPerSubEnvironment + i;
1306 mpiRC = MPI_Group_incl(
m_fullGroup, (
int) numRanksPerSubEnvironment, &fullRanksOfMySubEnvironment[0], &
m_subGroup);
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;
1333 if (
m_fullRank%numRanksPerSubEnvironment == 0) {
1352 bool openFile =
false;
1354 (
m_optionsObj->m_subDisplayFileName != UQ_ENV_FILENAME_FOR_NO_OUTPUT_FILE ) &&
1365 queso_require_greater_equal_msg(irtrn, 0,
"unable to verify output path");
1378 std::ofstream::out | std::ofstream::trunc));
1394 std::cout <<
"MPI node of worldRank " <<
m_worldRank
1396 <<
", belongs to subEnvironment of id " <<
m_subId
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];
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];
1417 std::cout << std::endl;
1438 #ifdef QUESO_HAVE_CXX11
1442 queso_error_msg(
"C++11 RNGs requested, but QUESO wasn't compiled with C++11 support");
1446 std::cerr <<
"In Environment::constructor()"
1449 queso_error_msg(
"the requested 'rngType' is not supported yet");
1459 *
m_subDisplayFile <<
"Done with initializations at FullEnvironment::commonConstructor()"
1465 #endif // QUESO_HAS_MPI
1468 const char* passedOptionsInputFileName,
1478 const std::string& passedOptionsInputFileName,
1479 const std::string& prefix,
1490 #ifdef QUESO_MEMORY_DEBUGGING
1491 std::cout <<
"Entering FullEnv" << std::endl;
1500 #ifndef QUESO_HAS_MPI
1507 #ifdef QUESO_MEMORY_DEBUGGING
1508 std::cout <<
"In FullEnv, finished dealing with MPI initially" << std::endl;
1519 #ifndef QUESO_DISABLE_BOOST_PROGRAM_OPTIONS
1521 m_allOptionsDesc.reset(
new boost::program_options::options_description(
"Allowed options"));
1522 #endif // QUESO_DISABLE_BOOST_PROGRAM_OPTIONS
1535 std::cout << (*m_optionsObj) << std::endl;
1540 "total number of processors in environment must be multiple of the specified number of subEnvironments");
1542 #ifdef QUESO_MEMORY_DEBUGGING
1543 std::cout <<
"In FullEnv, finished scanning options" << std::endl;
1560 std::cout <<
"Beginning run at " << ctime(&
m_timevalBegin.tv_sec)
1566 sprintf(tmpSubId,
"%u",
m_subId);
1573 int fullRanksOfMySubEnvironment = 1;
1575 #ifndef QUESO_HAS_MPI
1591 int fullRanksOfInter0 = 0;
1592 #ifndef QUESO_HAS_MPI
1612 bool openFile =
false;
1614 (
m_optionsObj->m_subDisplayFileName != UQ_ENV_FILENAME_FOR_NO_OUTPUT_FILE ) &&
1625 queso_require_greater_equal_msg(irtrn, 0,
"unable to verify output path");
1638 std::ofstream::out | std::ofstream::trunc));
1654 std::cout <<
"MPI node of worldRank " <<
m_worldRank
1656 <<
", belongs to subEnvironment of id " <<
m_subId
1660 std::cout <<
"MPI node of worldRank " <<
m_worldRank
1661 <<
" belongs to sub communicator with full ranks";
1662 std::cout <<
" " << fullRanksOfMySubEnvironment;
1666 std::cout <<
"MPI node of worldRank " << m_worldRank
1667 <<
" also belongs to inter0 communicator with full ranks";
1668 std::cout <<
" " << fullRanksOfInter0;
1673 std::cout << std::endl;
1691 #ifdef QUESO_HAVE_CXX11
1695 queso_error_msg(
"C++11 RNGs requested, but QUESO wasn't compiled with C++11 support");
1699 std::cerr <<
"In Environment::constructor()"
1702 queso_error_msg(
"the requested 'rngType' is not supported yet");
1712 *
m_subDisplayFile <<
"Done with initializations at FullEnvironment::commonConstructor()"
1733 #ifdef QUESO_HAS_MPI
1734 int mpi_initialized;
1735 MPI_Initialized (&mpi_initialized);
1737 if (mpi_initialized)
1740 MPI_Abort(MPI_COMM_WORLD, 1);
1761 if (ifs->is_open()) {
1766 if (
m_fullRank == 0) std::cout <<
"An invalid input file has been passed to the 'environment' class constructor!"
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."
ScopedPtr< GetPot >::Type m_input
MPI_Comm RawType_MPI_Comm
unsigned int subId() const
Access function to the number of each sub-environment Id: m_subId.
bool m_optionsInputFileAccessState
const boost::program_options::options_description & allOptionsDesc() const
std::string platformName() const
Access to the platform name.
ScopedPtr< MpiComm >::Type m_fullComm
This (virtual) class sets up the environment underlying the use of the QUESO library by an executable...
ScopedPtr< EnvOptionsValues >::Type m_optionsObj
void construct(RawType_MPI_Comm inputComm, const char *prefix)
Named constructor backend for multiple constructor overloads.
TODO: Base class for basic PDFs (via either GSL or Boost).
boost::program_options::variables_map & allOptionsMap() const
TODO: Base class for basic PDFs using Gsl library.
void closeFile(FilePtrSetStruct &filePtrSet, const std::string &fileType) const
Closes the file.
const GetPot & input() const
The GetPot input file parser.
MonteCarloSGOptions::MonteCarloSGOptions(const BaseEnvironment &env, const char *prefix queso_require_not_equal_to_msg)(m_env.optionsInputFileName(), std::string(""), std::string("this constructor is incompatible with the absence of an options input file"))
const MpiComm & inter0Comm() const
Access function for MpiComm communicator for processes with subRank() 0.
int subRank() const
Returns the rank of the MPI process in the sub-communicator subComm()
std::string optionsInputFileName() const
Access to the attribute m_optionsInputFileName, which stores the name of the input file passed by the...
bool m_exceptionalCircumstance
const MpiComm & selfComm() const
Access function for MpiComm self-communicator.
const RngBase * rngObject() const
Access to the RNG object.
Class for random number generation (base class for either GSL or Boost RNG).
bool exceptionalCircumstance() const
Decides whether there is an exceptional circumstance.
FilePtrSetStruct()
Struct constructor.
unsigned int checkingLevel() const
Access function to private attribute m_checkingLevel.
void resetIdentifyingString(const std::string &newString)
Reset private attribute m_identifyingString with the value newString.
RawType_MPI_Group m_fullGroup
std::string subDisplayFileName() const
Access function for m_subDisplayFileName (displays filename on stream).
RawType_MPI_Group m_subGroup
ScopedPtr< RngBase >::Type m_rngObject
int worldRank() const
Returns the same thing as fullRank()
void setExceptionalCircumstance(bool value) const
Set an exceptional circumstance.
int CheckFilePath(const char *path)
int fullRank() const
Returns the rank of the MPI process in QUESO's full communicator.
bool openInputFile(const std::string &fileName, const std::string &fileType, const std::set< unsigned int > &allowedSubEnvIds, FilePtrSetStruct &filePtrSet) const
Opens an input file.
ScopedPtr< boost::program_options::variables_map >::Type m_allOptionsMap
BaseEnvironment(const char *passedOptionsInputFileName, EnvOptionsValues *alternativeOptionsValues)
Default constructor.
RawType_MPI_Group subGroup() const
Access function for sub-group.
bool openUnifiedInputFile(const std::string &fileName, const std::string &fileType, FilePtrSetStruct &filePtrSet) const
Opens the unified input file.
ScopedPtr< boost::program_options::options_description >::Type m_allOptionsDesc
unsigned int syncVerbosity() const
Access function to private attribute m_syncVerbosity.
const MpiComm & subComm() const
Access function for each sub-environment's communicator.
void queso_terminate_handler()
Function for unhandled exceptions in Queso.
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.
const BasicPdfsBase * basicPdfs() const
Access to Basic PDFs.
Base class for basic PDFs using C++ math functions.
void scanInputFileForMyOptions(const boost::program_options::options_description &optionsDesc) const
This method scans the input file provided by the user to QUESO.
std::string m_subIdString
std::ifstream * ifsVar
Provides a stream interface to read data from files.
MPI_Group RawType_MPI_Group
void readOptionsInputFile()
Checks the options input file and reads the options.
std::string m_optionsInputFileName
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"))
void QUESO_version_print(std::ostream &os)
std::string identifyingString() const
Access function to private attribute m_identifyingString: identifying string.
This class provides a suite options one can pass to a QUESO environment.
ScopedPtr< MpiComm >::Type m_selfComm
The QUESO MPI Communicator Class.
void resetSeed(int newSeedOption)
Reset RNG seed.
void print(std::ostream &os) const
Sends the environment options to the stream.
ScopedPtr< MpiComm >::Type m_inter0Comm
unsigned int displayVerbosity() 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.
FullEnvironment(RawType_MPI_Comm inputComm, const char *passedOptionsInputFileName, const char *prefix, EnvOptionsValues *alternativeOptionsValues)
Parallel constructor.
std::ofstream * ofsVar
Provides a stream interface to write data to files.
std::terminate_handler old_terminate_handler
int QUESO_get_numeric_version()
virtual ~BaseEnvironment()
Destructor.
~FullEnvironment()
Destructor.
const MpiComm & fullComm() const
Access function for the communicator that was passed to QUESO's environment.
Struct for handling data input and output from files.
EmptyEnvironment()
Default constructor. Does nothing.
unsigned int numSubEnvironments() const
Access function to the number of sub-environments.
struct timeval m_timevalBegin
int inter0Rank() const
Returns the process inter0 rank.
~EmptyEnvironment()
Destructor.
void print(std::ostream &os) const
ScopedPtr< MpiComm >::Type m_subComm
void setOptionsInputFileAccessState(bool newState) const
bool fullEnvIsReady() const
Returns whether the full environment class is ready (constructor has successfully been called)...
RawType_MPI_Group m_inter0Group
TODO: Base class for basic PDFs using Boost library.
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...
ScopedPtr< BasicPdfsBase >::Type m_basicPdfs
std::ofstream * subDisplayFile() const
Access function for m_subDisplayFile (displays file on stream).
int seed() const
Access to the RNG seed.
ScopedPtr< std::ofstream >::Type m_subDisplayFile