queso-0.57.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
Environment.C
Go to the documentation of this file.
1 //-----------------------------------------------------------------------bl-
2 //--------------------------------------------------------------------------
3 //
4 // QUESO - a library to support the Quantification of Uncertainty
5 // for Estimation, Simulation and Optimization
6 //
7 // Copyright (C) 2008-2017 The PECOS Development Team
8 //
9 // This library is free software; you can redistribute it and/or
10 // modify it under the terms of the Version 2.1 GNU Lesser General
11 // Public License as published by the Free Software Foundation.
12 //
13 // This library is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 // Lesser General Public License for more details.
17 //
18 // You should have received a copy of the GNU Lesser General Public
19 // License along with this library; if not, write to the Free Software
20 // Foundation, Inc. 51 Franklin Street, Fifth Floor,
21 // Boston, MA 02110-1301 USA
22 //
23 //-----------------------------------------------------------------------el-
24 
25 #include <queso/Environment.h>
26 
27 #ifndef QUESO_DISABLE_BOOST_PROGRAM_OPTIONS
28 #include <boost/program_options.hpp>
29 #endif // QUESO_DISABLE_BOOST_PROGRAM_OPTIONS
30 
31 #include <queso/getpot.h>
32 
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>
42 #include <sys/time.h>
43 #ifdef HAVE_GRVY
44 #include <grvy.h>
45 #endif
46 
47 // queso error handling
48 #include <queso/asserts.h>
49 
50 //-----------------------------
51 // Library versioning routines
52 //-----------------------------
53 
54 namespace QUESO {
55 
56  void QUESO_version_print(std::ostream &os)
57  {
58  {
59  os << "------------------------------------------------------------------------------------------" ;
60  os << "--------------------" << std::endl;
61  os << "QUESO Library: Version = " << QUESO_VERSION;
62  os << " (" << QUESO_get_numeric_version() << ")" << std::endl << std::endl;
63 
64  os << QUESO_BUILD_DEVSTATUS << std::endl << std::endl;
65 
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;
71 
72  os << "C++ Config = " << QUESO_CXX << " " << QUESO_CXXFLAGS << std::endl;
73  os << 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;
81  }
82 
83  return;
84  }
85 
87  {
88  // Note: return format follows the versioning convention xx.yy.z where
89  //
90  // xx = major version number
91  // yy = minor version number
92  // zz = micro version number
93  //
94  // For example:
95  // v. 0.23 -> 002300 = 2300
96  // v. 0.23.1 -> 002301 = 2301
97  // v. 10.23.2 -> 102302
98 
99  int major_version = 0;
100  int minor_version = 0;
101  int micro_version = 0;
102 
103 #ifdef QUESO_MAJOR_VERSION
104  major_version = QUESO_MAJOR_VERSION;
105 #endif
106 
107 #ifdef QUESO_MINOR_VERSION
108  minor_version = QUESO_MINOR_VERSION;
109 #endif
110 
111 #ifdef QUESO_MICRO_VERSION
112  micro_version = QUESO_MICRO_VERSION;
113 #endif
114 
115  return(major_version*10000 + minor_version*100 + micro_version);
116  }
117 
119  :
120  ofsVar(NULL),
121  ifsVar(NULL)
122 #ifdef QUESO_HAS_HDF5
123  , // lol
124  h5Var(-1)
125 #endif
126 {
127  queso_deprecated();
128 }
129 
130 FilePtrSetStruct::~FilePtrSetStruct()
131 {
132  queso_deprecated();
133 }
134 
135  //
136  // queso terminate handler will be invoked for unhandled exceptions
137  // needs to be invoked in FullEnvironment constructor
138  //
139  std::terminate_handler old_terminate_handler;
140 
141 //*****************************************************
142 // Base class
143 //*****************************************************
144 // Default constructor --------------------------------
145 BaseEnvironment::BaseEnvironment(
146  const char* passedOptionsInputFileName,
147  EnvOptionsValues* alternativeOptionsValues)
148  :
149  m_fullEnvIsReady (false),
150  m_worldRank (-1),
151  m_fullComm (),
152  m_fullRank (-1),
153  m_fullCommSize (1),
154  m_optionsInputFileName (""),
155  m_optionsInputFileAccessState(true),
156 #ifndef QUESO_DISABLE_BOOST_PROGRAM_OPTIONS
157  m_allOptionsDesc (),
158  m_allOptionsMap (),
159 #endif // QUESO_DISABLE_BOOST_PROGRAM_OPTIONS
160  m_input (new GetPot),
161  m_subComm (),
162  m_subRank (-1),
163  m_subCommSize (1),
164  m_selfComm (),
165  m_inter0Comm (),
166  m_inter0Rank (-1),
167  m_inter0CommSize (1),
168  m_subDisplayFile (),
169  m_rngObject (),
170  m_basicPdfs (),
171  m_exceptionalCircumstance (false),
172  m_optionsObj ()
173 {
174  if (passedOptionsInputFileName) m_optionsInputFileName = passedOptionsInputFileName;
175 
176  // If the user passed in an options object pointer, we really shouldn't let
177  // ScopedPtr delete their object, so we make a copy. That way, the dtor
178  // will kill this local copy and leave the user's object in tact.
179  if (alternativeOptionsValues != NULL) {
180  m_optionsObj.reset(new EnvOptionsValues(*alternativeOptionsValues));
181  }
182 }
183 
185  const std::string& passedOptionsInputFileName,
186  EnvOptionsValues* alternativeOptionsValues)
187  :
188  m_fullEnvIsReady (false),
189  m_worldRank (-1),
190  m_fullComm (),
191  m_fullRank (-1),
192  m_fullCommSize (1),
193  m_optionsInputFileName (passedOptionsInputFileName),
194  m_optionsInputFileAccessState(true),
195 #ifndef QUESO_DISABLE_BOOST_PROGRAM_OPTIONS
196  m_allOptionsDesc (),
197  m_allOptionsMap (),
198 #endif // QUESO_DISABLE_BOOST_PROGRAM_OPTIONS
199  m_input (new GetPot),
200  m_subComm (),
201  m_subRank (-1),
202  m_subCommSize (1),
203  m_selfComm (),
204  m_inter0Comm (),
205  m_inter0Rank (-1),
206  m_inter0CommSize (1),
207  m_subDisplayFile (),
208  m_rngObject (),
209  m_basicPdfs (),
210  m_exceptionalCircumstance (false),
211  m_optionsObj ()
212 {
213  // If the user passed in an options object pointer, we really shouldn't let
214  // ScopedPtr delete their object, so we make a copy. That way, the dtor
215  // will kill this local copy and leave the user's object in tact.
216  if (alternativeOptionsValues != NULL) {
217  m_optionsObj.reset(new EnvOptionsValues(*alternativeOptionsValues));
218  }
219 }
220 
221 // Destructor -------------------------------------------
223 {
224  //if (m_subDisplayFile) {
225  // *m_subDisplayFile << "Entering BaseEnvironment::destructor()"
226  // << std::endl;
227  //}
228 
229  struct timeval timevalNow;
230  /*int iRC = 0;*/
231  /*iRC = */gettimeofday(&timevalNow, NULL);
232 
233  if (this->displayVerbosity() > 0) {
234  if (m_subDisplayFile) {
235  *m_subDisplayFile << "Ending run at " << ctime(&timevalNow.tv_sec)
236  << "Total run time = " << timevalNow.tv_sec - m_timevalBegin.tv_sec
237  << " seconds"
238  << std::endl;
239  }
240 
241  if (m_fullRank == 0) {
242  std::cout << "Ending run at " << ctime(&timevalNow.tv_sec)
243  << "Total run time = " << timevalNow.tv_sec - m_timevalBegin.tv_sec
244  << " seconds"
245  << std::endl;
246  }
247  }
248 
249  //if (m_subDisplayFile) {
250  // *m_subDisplayFile << "Leaving BaseEnvironment::destructor()"
251  // << std::endl;
252  //}
253 }
254 // Environment, Communicator and Options Input File methods
255 bool
257 {
258  return m_fullEnvIsReady;
259 }
260 //-------------------------------------------------------
261 int
263 {
264  return m_worldRank;
265 }
266 //-------------------------------------------------------
267 int
269 {
270  return m_fullRank;
271 }
272 //-------------------------------------------------------
273 const MpiComm&
275 {
276  queso_require_msg(m_fullComm, "m_fullComm variable is NULL");
277  return *m_fullComm;
278 }
279 //-------------------------------------------------------
282 {
283  return m_subGroup;
284 }
285 //-------------------------------------------------------
286 int
288 {
289  return m_subRank;
290 }
291 //-------------------------------------------------------
292 const MpiComm&
294 {
295  queso_require_msg(m_subComm, "m_subComm variable is NULL");
296  return *m_subComm;
297 }
298 //-------------------------------------------------------
299 const MpiComm&
301 {
302  queso_require_msg(m_selfComm, "m_selfComm variable is NULL");
303  return *m_selfComm;
304 }
305 //-------------------------------------------------------
306 int
308 {
309  return m_inter0Rank;
310 }
311 //-------------------------------------------------------
312 const MpiComm&
314 {
315  queso_require_msg(m_inter0Comm, "m_inter0Comm variable is NULL");
316  return *m_inter0Comm;
317 }
318 //-------------------------------------------------------
319 std::ofstream*
321 {
322  // Potentially dangerous? The user might delete it...
323  return m_subDisplayFile.get();
324 }
325 //-------------------------------------------------------
326 std::string
328 {
329  if (m_optionsObj == NULL) return ".";
330 
331  return m_optionsObj->m_subDisplayFileName;
332 }
333 //-------------------------------------------------------
334 unsigned int
336 {
337  queso_require_msg(m_optionsObj, "m_optionsObj variable is NULL");
338  return m_optionsObj->m_numSubEnvironments;
339 }
340 //-------------------------------------------------------
341 unsigned int
343 {
344  return m_subId;
345 }
346 //-------------------------------------------------------
347 const std::string&
349 {
350  return m_subIdString;
351 }
352 //-------------------------------------------------------
353 std::string
355 {
357  return m_optionsInputFileName;
358  }
359  else {
360  return "";
361  }
362 }
363 //-------------------------------------------------------
364 void
366 {
368 
369  return;
370 }
371 //-------------------------------------------------------
372 #ifndef QUESO_DISABLE_BOOST_PROGRAM_OPTIONS
373 #ifdef UQ_USES_COMMAND_LINE_OPTIONS
374 const boost::program_options::options_description&
376 {
377  queso_deprecated();
378 
379  return *m_allOptionsDesc;
380 }
381 #endif
382 #endif // QUESO_DISABLE_BOOST_PROGRAM_OPTIONS
383 //-------------------------------------------------------
384 #ifndef QUESO_DISABLE_BOOST_PROGRAM_OPTIONS
385 boost::program_options::variables_map&
387 {
388  queso_deprecated();
389 
390  queso_require_msg(m_allOptionsMap, "m_allOptionsMap variable is NULL");
391  return *m_allOptionsMap;
392 }
393 #endif // QUESO_DISABLE_BOOST_PROGRAM_OPTIONS
394 //-------------------------------------------------------
395 #ifndef QUESO_DISABLE_BOOST_PROGRAM_OPTIONS
396 void
397 BaseEnvironment::scanInputFileForMyOptions(const boost::program_options::options_description& optionsDesc) const
398 {
399  queso_deprecated();
400 
401 #ifdef UQ_USES_COMMAND_LINE_OPTIONS
402  // If you want to use command line options, the following line does *not* work outside 'main.C',
403  // e.g., in the constructor of FullEnvironment:
404  // Line: boost::program_options::store(boost::program_options::parse_command_line(argc, argv, *m_allOptionsDesc), *m_allOptionsMap);
405  //
406  // Instead, put the following three lines *immediately after* instantianting the UQ environment
407  // variable "FullEnvironment* env":
408  // Line 1: boost::program_options::store(boost::program_options::parse_command_line(argc, argv, env->allOptionsDesc()), env->allOptionsMap());
409  // Line 2: boost::program_options::notify(env->allOptionsMap());
410  // Line 3: env->getMyOptionValues();
411 #endif
412 
413 #ifdef QUESO_MEMORY_DEBUGGING
414  std::cout << "Entering BaseEnv::scanInputFileForMyOptions()" << std::endl;
415 #endif
416 
417  queso_require_msg(m_allOptionsDesc, "m_allOptionsDesc variable is NULL");
418  m_allOptionsDesc->add(optionsDesc);
419  //if (m_subDisplayFile) {
420  // *m_subDisplayFile << *m_allOptionsDesc
421  // << std::endl;
422  //}
423 
425  std::string("m_optionsInputFileName is 'nothing'"));
426  //std::ifstream ifs(m_optionsInputFileName.c_str());
427  std::ifstream* ifs = new std::ifstream(m_optionsInputFileName.c_str());
428 #ifdef QUESO_MEMORY_DEBUGGING
429  std::cout << "in BaseEnv::scanInputFileForMyOptions(), before store(a)" << std::endl;
430 #endif
431 
432  queso_require_msg(m_allOptionsMap, "m_allOptionsMap variable is NULL");
433  boost::program_options::store(boost::program_options::parse_config_file(*ifs, *m_allOptionsDesc, true), *m_allOptionsMap);
434 #ifdef QUESO_MEMORY_DEBUGGING
435  std::cout << "in BaseEnv::scanInputFileForMyOptions(), after store(a)" << std::endl;
436 #endif
437  boost::program_options::notify(*m_allOptionsMap);
438 
439  //ifs.close();
440  delete ifs;
441 #ifdef QUESO_MEMORY_DEBUGGING
442  std::cout << "Leaving BaseEnv::scanInputFileForMyOptions()" << std::endl;
443 #endif
444 
445  return;
446 }
447 #endif // QUESO_DISABLE_BOOST_PROGRAM_OPTIONS
448 //-----------------------------------------------------
449 unsigned int
451 {
452  queso_require_msg(m_optionsObj, "m_optionsObj variable is NULL");
453  return m_optionsObj->m_displayVerbosity;
454 }
455 //-------------------------------------------------------
456 unsigned int
458 {
459  queso_require_msg(m_optionsObj, "m_optionsObj variable is NULL");
460  return m_optionsObj->m_syncVerbosity;
461 }
462 //-------------------------------------------------------
463 unsigned int
465 {
466  queso_require_msg(m_optionsObj, "m_optionsObj variable is NULL");
467  return m_optionsObj->m_checkingLevel;
468 }
469 //-------------------------------------------------------
470 const RngBase*
472 {
473  return m_rngObject.get();
474 }
475 //-------------------------------------------------------
476 int
478 {
479  return m_rngObject->seed();
480 }
481 //-------------------------------------------------------
482 void
483 BaseEnvironment::resetSeed(int newSeedOption)
484 {
485  m_rngObject->resetSeed(newSeedOption);
486  return;
487 }
488 //-------------------------------------------------------
489 const BasicPdfsBase*
491 {
492  return m_basicPdfs.get();
493 }
494 //-------------------------------------------------------
495 std::string
497 {
498  return m_optionsObj->m_platformName;
499 }
500 //-------------------------------------------------------
501 std::string
503 {
504  return m_optionsObj->m_identifyingString;
505 }
506 //-------------------------------------------------------
507 void
508 BaseEnvironment::resetIdentifyingString(const std::string& newString)
509 {
510  m_optionsObj->m_identifyingString = newString;
511  return;
512 }
513 //-------------------------------------------------------
514 struct timeval
515 BaseEnvironment::timevalBegin() const
516 {
517  return m_timevalBegin;
518 }
519 //-------------------------------------------------------
520 bool
522  const std::string& baseFileName,
523  const std::string& inputFileType,
524  const std::set<unsigned int>& allowedSubEnvIds,
525  bool writeOver,
526  FilePtrSetStruct& filePtrSet) const
527 {
528  std::string fileType(inputFileType);
529 #ifdef QUESO_HAS_HDF5
530  // Do nothing
531 #else
532  if (fileType == UQ_FILE_EXTENSION_FOR_HDF_FORMAT) {
533  if (m_subDisplayFile) {
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
538  << "' instead..."
539  << std::endl;
540  }
541  if (this->subRank() == 0) {
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
546  << "' instead..."
547  << std::endl;
548  }
549  fileType = UQ_FILE_EXTENSION_FOR_MATLAB_FORMAT;
550  }
551 #endif
552 
553  bool returnValue = true;
554  filePtrSet.ofsVar = NULL;
555  if ((baseFileName == UQ_ENV_FILENAME_FOR_NO_OUTPUT_FILE) ||
556  (allowedSubEnvIds.find(this->subId()) == allowedSubEnvIds.end() )) {
557  if ((m_subDisplayFile) && (this->displayVerbosity() > 10)) { // output debug
558  *this->subDisplayFile() << "In BaseEnvironment::openOutputFile()"
559  << ", subId = " << this->subId()
560  << ": no output file opened with base name '" << baseFileName << "." << fileType
561  << "'"
562  << ", writeOver = " << writeOver
563  << std::endl;
564  }
565  returnValue = false;
566  }
567  else {
569  // Open file
571  if ((m_subDisplayFile) && (this->displayVerbosity() > 10)) { // output debug
572  *this->subDisplayFile() << "In BaseEnvironment::openOutputFile()"
573  << ", subId = " << this->subId()
574  << ": opening output file with base name '" << baseFileName << "." << fileType
575  << "'"
576  << ", writeOver = " << writeOver
577  << std::endl;
578  }
579 
580  if (this->subRank() == 0) {
581 #if 0
582  std::cout << "In BaseEnvironment::openOutputFile()"
583  << ": opening output file with base name '" << baseFileName << "." << fileType
584  << "'"
585  << ", writeOver = " << writeOver
586  << std::endl;
587 #endif
588 
590  // Verify parent directory exists (for cases when a user
591  // specifies a relative path for the desired output file).
593  // std::cout << "checking " << baseFileName+"_sub"+this->subIdString()+"."+fileType << std::endl;
594  if ((m_subDisplayFile) && (this->displayVerbosity() > 10)) { // output debug
595  *this->subDisplayFile() << "In BaseEnvironment::openOutputFile()"
596  << ", subId = " << this->subId()
597  << ", trying to open output file with base name '" << baseFileName << "." << fileType
598  << "'"
599  << ", writeOver = " << writeOver
600  << ": calling CheckFilePath()..."
601  << std::endl;
602  }
603  int irtrn = CheckFilePath((baseFileName+"_sub"+this->subIdString()+"."+fileType).c_str());
604  if ((m_subDisplayFile) && (this->displayVerbosity() > 10)) { // output debug
605  *this->subDisplayFile() << "In BaseEnvironment::openOutputFile()"
606  << ", subId = " << this->subId()
607  << ", trying to open output file with base name '" << baseFileName << "." << fileType
608  << "'"
609  << ", writeOver = " << writeOver
610  << ": returned from CheckFilePath() with irtrn = " << irtrn
611  << std::endl;
612  }
613  queso_require_greater_equal_msg(irtrn, 0, "unable to verify output path");
614 
615  if (writeOver) {
617  // Write over an eventual pre-existing file
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);
623  }
624  else if (fileType == UQ_FILE_EXTENSION_FOR_HDF_FORMAT) {
625  queso_error_msg("hdf file type not supported yet");
626  }
627  else {
628  queso_error_msg("invalid file type");
629  }
630  if ((m_subDisplayFile) && (this->displayVerbosity() > 10)) { // output debug
631  *this->subDisplayFile() << "In BaseEnvironment::openOutputFile()"
632  << ": just opened output file with base name '" << baseFileName << "." << fileType
633  << "'"
634  << ", writeOver = " << writeOver
635  << ", options 'out|trunc'"
636  << ", osfvar = " << filePtrSet.ofsVar
637  << std::endl;
638  }
639  }
640  else {
642  // Write at the end of an eventual pre-existing file
644  if ((fileType == UQ_FILE_EXTENSION_FOR_MATLAB_FORMAT) ||
645  (fileType == UQ_FILE_EXTENSION_FOR_TXT_FORMAT)) {
646 #if 0
647  filePtrSet.ofsVar = new std::ofstream((baseFileName+"_sub"+this->subIdString()+"."+fileType).c_str(),
648  std::ofstream::in);
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;
651  if (filePtrSet.ofsVar) delete filePtrSet.ofsVar;
652 #endif
653  // 'm' and Ranger nodes behave differently on ofstream constructor... prudenci 2010/03/05
654  filePtrSet.ofsVar = new std::ofstream((baseFileName+"_sub"+this->subIdString()+"."+fileType).c_str(),
655  std::ofstream::out /*| std::ofstream::in*/ | std::ofstream::app);
656  }
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;
661 
662  // Use H5F_ACC_EXCL because not overwriting, so fail on existing file
663  filePtrSet.h5Var = H5Fcreate(fullFileName.c_str(),
664  H5F_ACC_EXCL,
665  H5P_DEFAULT,
666  H5P_DEFAULT);
667 
668  queso_require_greater_equal_msg(
669  filePtrSet.h5Var, 0,
670  "error opening file `" << fullFileName << "`");
671  }
672 #endif
673  else {
674  queso_error_msg("invalid file type");
675  }
676  if ((m_subDisplayFile) && (this->displayVerbosity() > 10)) { // output debug
677  *this->subDisplayFile() << "In BaseEnvironment::openOutputFile()"
678  << ": just opened output file with base name '" << baseFileName << "." << fileType
679  << "'"
680  << ", writeOver = " << writeOver
681  << ", options 'out|in|app'"
682  << ", osfvar = " << filePtrSet.ofsVar
683  << std::endl;
684  }
685 
686  if (fileType == UQ_FILE_EXTENSION_FOR_MATLAB_FORMAT) {
687  //std::cout << "filePtrSet.ofsVar(2) = " << filePtrSet.ofsVar << std::endl;
688  //if (filePtrSet.ofsVar) std::cout << "filePtrSet.ofsVar(2)->is_open() = " << filePtrSet.ofsVar->is_open() << std::endl;
689  if ((filePtrSet.ofsVar == NULL ) ||
690  (filePtrSet.ofsVar->is_open() == false)) {
691  //std::cout << "Retrying 1..." << std::endl;
692  delete filePtrSet.ofsVar;
693  filePtrSet.ofsVar = new std::ofstream((baseFileName+"_sub"+this->subIdString()+"."+fileType).c_str(),
694  std::ofstream::out | std::ofstream::trunc);
695  if ((m_subDisplayFile) && (this->displayVerbosity() > 10)) { // output debug
696  *this->subDisplayFile() << "In BaseEnvironment::openOutputFile()"
697  << ": just opened output file with base name '" << baseFileName << "." << fileType
698  << "'"
699  << ", writeOver = " << writeOver
700  << ", options 'out|trunc'"
701  << ", osfvar = " << filePtrSet.ofsVar
702  << std::endl;
703  }
704  }
705  } // only for matlab formats
706  }
707 
708  // Check the file actually opened
709  if ((fileType == UQ_FILE_EXTENSION_FOR_MATLAB_FORMAT) ||
710  (fileType == UQ_FILE_EXTENSION_FOR_TXT_FORMAT)) {
711  queso_require_msg(
712  (filePtrSet.ofsVar && filePtrSet.ofsVar->is_open()),
713  "failed to open output file");
714  }
715  }
716  else {
717  returnValue = false;
718  }
719  //this->subComm().Barrier(); // prudenci-2011-01-17
720  }
721 
722  return returnValue;
723 }
724 //-------------------------------------------------------
725 bool
727  const std::string& baseFileName,
728  const std::string& inputFileType,
729  bool writeOver,
730  FilePtrSetStruct& filePtrSet) const
731 {
732  std::string fileType(inputFileType);
733 #ifdef QUESO_HAS_HDF5
734  // Do nothing
735 #else
736  if (fileType == UQ_FILE_EXTENSION_FOR_HDF_FORMAT) {
737  if (m_subDisplayFile) {
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
742  << "' instead..."
743  << std::endl;
744  }
745  if (this->subRank() == 0) {
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
750  << "' instead..."
751  << std::endl;
752  }
753  fileType = UQ_FILE_EXTENSION_FOR_MATLAB_FORMAT;
754  }
755 #endif
756 
757  bool returnValue = true;
758  filePtrSet.ofsVar = NULL;
759  if (baseFileName == ".") {
760  if ((m_subDisplayFile) && (this->displayVerbosity() > 10)) { // output debug
761  *this->subDisplayFile() << "In BaseEnvironment::openUnifiedOutputFile()"
762  << ": no unified output file opened with base name '" << baseFileName << "." << fileType
763  << "'"
764  << ", writeOver = " << writeOver
765  << std::endl;
766  }
767  returnValue = false;
768  }
769  else {
771  // Open file
773  if ((m_subDisplayFile) && (this->displayVerbosity() > 10)) { // output debug
774  *this->subDisplayFile() << "In BaseEnvironment::openUnifiedOutputFile()"
775  << ": opening unified output file with base name '" << baseFileName << "." << fileType
776  << "'"
777  << ", writeOver = " << writeOver
778  << std::endl;
779  }
780 
781 
782  //if ((this->subRank () == 0) &&
783  // (this->inter0Rank() == 0)) {
784 #if 0
785  std::cout << "In BaseEnvironment::openUnifiedOutputFile()"
786  << ": opening output file with base name '" << baseFileName << "." << fileType
787  << "'"
788  << ", writeOver = " << writeOver
789  << std::endl;
790 #endif
791  // Verify parent directory exists (for cases when a user
793  // specifies a relative path for the desired output file). prudenci 2010/06/26
795  // std::cout << "checking " << baseFileName+"."+fileType << std::endl;
796  int irtrn = CheckFilePath((baseFileName+"."+fileType).c_str());
797  queso_require_greater_equal_msg(irtrn, 0, "unable to verify output path");
798 
799  if (writeOver) {
801  // Write over an eventual pre-existing file
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);
807  }
808 #ifdef QUESO_HAS_HDF5
809  else if (fileType == UQ_FILE_EXTENSION_FOR_HDF_FORMAT) {
810  filePtrSet.h5Var = H5Fcreate((baseFileName+"."+fileType).c_str(),
811  H5F_ACC_TRUNC,
812  H5P_DEFAULT,
813  H5P_DEFAULT);
814  }
815 #endif
816  else {
817  queso_error_msg("invalid file type");
818  }
819  if ((m_subDisplayFile) && (this->displayVerbosity() > 10)) { // output debug
820  *this->subDisplayFile() << "In BaseEnvironment::openUnifiedOutputFile()"
821  << ": just opened output file with base name '" << baseFileName << "." << fileType
822  << "'"
823  << ", writeOver = " << writeOver
824  << ", options 'out|trunc'"
825  << ", osfvar = " << filePtrSet.ofsVar
826  << std::endl;
827  }
828  }
829  else {
831  // Write at the end of an eventual pre-existing file
832  // 'm' and Ranger nodes behave differently on ofstream constructor... prudenci 2010/03/05
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::in*/ | std::ofstream::app);
838  }
839 #ifdef QUESO_HAS_HDF5
840  else if (fileType == UQ_FILE_EXTENSION_FOR_HDF_FORMAT) {
841  filePtrSet.h5Var = H5Fcreate((baseFileName+"."+fileType).c_str(), // TEMPORARY - FIX ME
842  H5F_ACC_TRUNC,
843  H5P_DEFAULT,
844  H5P_DEFAULT);
845 
846  // m_worldRank,
847  // "BaseEnvironment::openUnifiedOutputFile(), writeOver=false",
848  // "hdf file type not supported yet");
849  }
850 #endif
851  else {
852  queso_error_msg("invalid file type");
853  }
854  if ((m_subDisplayFile) && (this->displayVerbosity() > 10)) { // output debug
855  *this->subDisplayFile() << "In BaseEnvironment::openUnifiedOutputFile()"
856  << ": just opened output file with base name '" << baseFileName << "." << fileType
857  << "'"
858  << ", writeOver = " << writeOver
859  << ", options 'out|in|app'"
860  << ", osfvar = " << filePtrSet.ofsVar
861  << std::endl;
862  }
863  if ((filePtrSet.ofsVar == NULL ) ||
864  (filePtrSet.ofsVar->is_open() == false)) {
865 #if 0
866  std::cout << "Retrying 2..." << std::endl;
867 #endif
868  delete filePtrSet.ofsVar;
869  filePtrSet.ofsVar = new std::ofstream((baseFileName+"."+fileType).c_str(),
870  std::ofstream::out | std::ofstream::trunc);
871  if ((m_subDisplayFile) && (this->displayVerbosity() > 10)) { // output debug
872  *this->subDisplayFile() << "In BaseEnvironment::openUnifiedOutputFile()"
873  << ": just opened output file with base name '" << baseFileName << "." << fileType
874  << "'"
875  << ", writeOver = " << writeOver
876  << ", options 'out|trunc'"
877  << ", osfvar = " << filePtrSet.ofsVar
878  << std::endl;
879  }
880  }
881  }
882  if (filePtrSet.ofsVar == NULL) {
883  std::cerr << "In BaseEnvironment::openUnifiedOutputFile()"
884  << ": failed to open unified output file with base name '" << baseFileName << "." << fileType
885  << "'"
886  << std::endl;
887  }
888  queso_require_msg((filePtrSet.ofsVar && filePtrSet.ofsVar->is_open()), "failed to open output file");
889  //}
890  }
891 
892  return returnValue;
893 }
894 //-------------------------------------------------------
895 bool
897  const std::string& baseFileName,
898  const std::string& inputFileType,
899  const std::set<unsigned int>& allowedSubEnvIds,
900  FilePtrSetStruct& filePtrSet) const
901 {
902  std::string fileType(inputFileType);
903 #ifdef QUESO_HAS_HDF5
904  // Do nothing
905 #else
906  if (fileType == UQ_FILE_EXTENSION_FOR_HDF_FORMAT) {
907  if (m_subDisplayFile) {
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
912  << "' instead..."
913  << std::endl;
914  }
915  if (this->subRank() == 0) {
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
920  << "' instead..."
921  << std::endl;
922  }
923  fileType = UQ_FILE_EXTENSION_FOR_MATLAB_FORMAT;
924  }
925 #endif
926 
927  bool returnValue = true;
928  filePtrSet.ifsVar = NULL;
929  if ((baseFileName == UQ_ENV_FILENAME_FOR_NO_INPUT_FILE) ||
930  (allowedSubEnvIds.find(this->subId()) == allowedSubEnvIds.end() )) {
931  if ((m_subDisplayFile) && (this->displayVerbosity() >= 10)) {
932  *this->subDisplayFile() << "In BaseEnvironment::openInputFile()"
933  << ": no input file opened with base name '" << baseFileName << "." << fileType
934  << "'"
935  << std::endl;
936  }
937  returnValue = false;
938  }
939  else {
941  // Open file
943  if ((m_subDisplayFile) && (this->displayVerbosity() >= 10)) {
944  *this->subDisplayFile() << "In BaseEnvironment::openInputFile()"
945  << ": opening input file with base name '" << baseFileName << "." << fileType
946  << "'"
947  << std::endl;
948  }
949  if (this->subRank() == 0) {
951  // Verify parent directory exists (for cases when a user
952  // specifies a relative path for the desired output file). prudenci 2010/06/26
954  // std::cout << "checking " << baseFileName+"."+fileType << std::endl;
955  int irtrn = CheckFilePath((baseFileName+"."+fileType).c_str());
956  queso_require_greater_equal_msg(irtrn, 0, "unable to verify input path");
957 
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(),
961  std::ofstream::in);
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
965  << "'"
966  << std::endl;
967  }
968  queso_require_msg(!((filePtrSet.ifsVar == NULL) || (filePtrSet.ifsVar->is_open() == false)), "file with fileName could not be found");
969  }
970 #ifdef QUESO_HAS_HDF5
971  else if (fileType == UQ_FILE_EXTENSION_FOR_HDF_FORMAT) {
972  filePtrSet.h5Var = H5Fopen((baseFileName+"."+fileType).c_str(),
973  H5F_ACC_RDONLY,
974  H5P_DEFAULT);
975  }
976 #endif
977  else {
978  queso_error_msg("invalid file type");
979  }
980  }
981  else {
982  returnValue = false;
983  }
984  //this->subComm().Barrier(); // prudenci-2011-01-17
985  }
986 
987  return returnValue;
988 }
989 //-------------------------------------------------------
990 bool
992  const std::string& baseFileName,
993  const std::string& inputFileType,
994  FilePtrSetStruct& filePtrSet) const
995 {
996  std::string fileType(inputFileType);
997 #ifdef QUESO_HAS_HDF5
998  // Do nothing
999 #else
1000  if (fileType == UQ_FILE_EXTENSION_FOR_HDF_FORMAT) {
1001  if (m_subDisplayFile) {
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
1006  << "' instead..."
1007  << std::endl;
1008  }
1009  if (this->subRank() == 0) {
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
1014  << "' instead..."
1015  << std::endl;
1016  }
1017  fileType = UQ_FILE_EXTENSION_FOR_MATLAB_FORMAT;
1018  }
1019 #endif
1020 
1021  bool returnValue = true;
1022  filePtrSet.ifsVar = NULL;
1023  if (baseFileName == UQ_ENV_FILENAME_FOR_NO_INPUT_FILE) {
1024  if ((m_subDisplayFile) && (this->displayVerbosity() >= 10)) {
1025  *this->subDisplayFile() << "In BaseEnvironment::openUnifiedInputFile()"
1026  << ": no input file opened with base name '" << baseFileName << "." << fileType
1027  << "'"
1028  << std::endl;
1029  }
1030  returnValue = false;
1031  }
1032  else {
1034  // Open file
1036  if ((m_subDisplayFile) && (this->displayVerbosity() >= 10)) {
1037  *this->subDisplayFile() << "In BaseEnvironment::openUnifiedInputFile()"
1038  << ": opening input file with base name '" << baseFileName << "." << fileType
1039  << "'"
1040  << std::endl;
1041  }
1042  if (this->subRank() == 0) { // Needed ???????? prudenci 2010-11-11
1044  // Verify parent directory exists (for cases when a user
1045  // specifies a relative path for the desired output file). prudenci 2010/06/26
1047  // std::cout << "checking " << baseFileName+"."+fileType << std::endl;
1048  int irtrn = CheckFilePath((baseFileName+"."+fileType).c_str());
1049  queso_require_greater_equal_msg(irtrn, 0, "unable to verify input path");
1050 
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(),
1054  std::ofstream::in);
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
1058  << "'"
1059  << std::endl;
1060  }
1061  queso_require_msg(!((filePtrSet.ifsVar == NULL) || (filePtrSet.ifsVar->is_open() == false)), "file with fileName could not be found");
1062  }
1063 #ifdef QUESO_HAS_HDF5
1064  else if (fileType == UQ_FILE_EXTENSION_FOR_HDF_FORMAT) {
1065  filePtrSet.h5Var = H5Fopen((baseFileName+"."+fileType).c_str(),
1066  H5F_ACC_RDONLY,
1067  H5P_DEFAULT);
1068  }
1069 #endif
1070  else {
1071  queso_error_msg("invalid file type");
1072  }
1073  }
1074  //else {
1075  // returnValue = false;
1076  //}
1077  //this->subComm().Barrier();
1078  }
1079 
1080  return returnValue;
1081 }
1082 //-------------------------------------------------------
1083 void
1085  FilePtrSetStruct& filePtrSet,
1086  const std::string& inputFileType) const
1087 {
1088  std::string fileType(inputFileType);
1089 #ifdef QUESO_HAS_HDF5
1090  // Do nothing
1091 #else
1092  if (fileType == UQ_FILE_EXTENSION_FOR_HDF_FORMAT) {
1093  if (m_subDisplayFile) {
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
1098  << "' instead..."
1099  << std::endl;
1100  }
1101  if (this->subRank() == 0) {
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
1106  << "' instead..."
1107  << std::endl;
1108  }
1109  fileType = UQ_FILE_EXTENSION_FOR_MATLAB_FORMAT;
1110  }
1111 #endif
1112 
1113  if ((fileType == UQ_FILE_EXTENSION_FOR_MATLAB_FORMAT) ||
1114  (fileType == UQ_FILE_EXTENSION_FOR_TXT_FORMAT)) {
1115  //filePtrSet.ofsVar->close(); // close() crashes on Mac; need to use delete(); why? prudenci 2010/June
1116  delete filePtrSet.ofsVar;
1117  filePtrSet.ofsVar = NULL;
1118 
1119  //filePtrSet.ifsVar->close();
1120  delete filePtrSet.ifsVar;
1121  filePtrSet.ifsVar = NULL;
1122  }
1123 #ifdef QUESO_HAS_HDF5
1124  else if (fileType == UQ_FILE_EXTENSION_FOR_HDF_FORMAT) {
1125  H5Fclose(filePtrSet.h5Var);
1126  }
1127 #endif
1128  else {
1129  queso_error_msg("invalid file type");
1130  }
1131 
1132  return;
1133 }
1134 //-------------------------------------------------------
1135 void
1137 {
1138  m_exceptionalCircumstance = value;
1139  return;
1140 }
1141 //-------------------------------------------------------
1142 bool
1144 {
1146 }
1147 
1148 const GetPot &
1150 {
1151  return *m_input;
1152 }
1153 
1154 
1155 //*****************************************************
1156 // Empty Environment
1157 //*****************************************************
1159  :
1160  BaseEnvironment("",NULL)
1161 {
1162 }
1163 //-------------------------------------------------------
1165 {
1166 }
1167 //-------------------------------------------------------
1168 void
1169 EmptyEnvironment::print(std::ostream& os) const
1170 {
1171  os.flush(); // just to avoid icpc warnings
1172  return;
1173 }
1174 
1175 //*****************************************************
1176 // Full Environment
1177 //*****************************************************
1178 #ifdef QUESO_HAS_MPI
1180  RawType_MPI_Comm inputComm,
1181  const char* passedOptionsInputFileName,
1182  const char* prefix,
1183  EnvOptionsValues* alternativeOptionsValues)
1184  :
1185  BaseEnvironment(passedOptionsInputFileName,alternativeOptionsValues)
1186 {
1187  this->construct(inputComm, prefix);
1188 }
1189 
1191  RawType_MPI_Comm inputComm,
1192  const std::string& passedOptionsInputFileName,
1193  const std::string& prefix,
1194  EnvOptionsValues* alternativeOptionsValues)
1195  :
1196  BaseEnvironment(passedOptionsInputFileName,alternativeOptionsValues)
1197 {
1198  this->construct(inputComm, prefix.c_str());
1199 }
1200 
1201 void
1203  const char *prefix)
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));
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));
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 }
1465 #endif // QUESO_HAS_MPI
1466 
1468  const char* passedOptionsInputFileName,
1469  const char* prefix,
1470  EnvOptionsValues* alternativeOptionsValues)
1471  :
1472  BaseEnvironment(passedOptionsInputFileName,alternativeOptionsValues)
1473 {
1474  this->construct(prefix);
1475 }
1476 
1478  const std::string& passedOptionsInputFileName,
1479  const std::string& prefix,
1480  EnvOptionsValues* alternativeOptionsValues)
1481  :
1482  BaseEnvironment(passedOptionsInputFileName,alternativeOptionsValues)
1483 {
1484  this->construct(prefix.c_str());
1485 }
1486 
1487 void
1488 FullEnvironment::construct (const char *prefix)
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));
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));
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 }
1718 
1719 //-------------------------------------------------------
1721 {
1722 }
1723 //-------------------------------------------------------
1724 void
1725 FullEnvironment::print(std::ostream& os) const
1726 {
1727  os.flush(); // just to avoid icpc warnings
1728  return;
1729 }
1730 
1732 {
1733 #ifdef QUESO_HAS_MPI
1734  int mpi_initialized;
1735  MPI_Initialized (&mpi_initialized);
1736 
1737  if (mpi_initialized)
1738  {
1739  //MPI_Abort(m_fullComm->Comm(), 1);
1740  MPI_Abort(MPI_COMM_WORLD, 1);
1741  }
1742  else
1743  {
1744  // The system terminate_handler may do useful things like printing
1745  // uncaught exception information, or the user may have created
1746  // their own terminate handler that we want to call.
1748  }
1749 #else
1751 #endif
1752  exit(1);
1753 }
1754 
1755 
1756 //-------------------------------------------------------
1757 void
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 }
1781 
1782 } // End namespace QUESO
ScopedPtr< GetPot >::Type m_input
Definition: Environment.h:453
MPI_Comm RawType_MPI_Comm
Definition: MpiComm.h:41
unsigned int subId() const
Access function to the number of each sub-environment Id: m_subId.
Definition: Environment.C:342
const boost::program_options::options_description & allOptionsDesc() const
Definition: Environment.C:375
std::string platformName() const
Access to the platform name.
Definition: Environment.C:496
ScopedPtr< MpiComm >::Type m_fullComm
Definition: Environment.h:442
This (virtual) class sets up the environment underlying the use of the QUESO library by an executable...
Definition: Environment.h:198
ScopedPtr< EnvOptionsValues >::Type m_optionsObj
Definition: Environment.h:475
void construct(RawType_MPI_Comm inputComm, const char *prefix)
Named constructor backend for multiple constructor overloads.
Definition: Environment.C:1202
TODO: Base class for basic PDFs (via either GSL or Boost).
Definition: BasicPdfsBase.h:44
boost::program_options::variables_map & allOptionsMap() const
Definition: Environment.C:386
TODO: Base class for basic PDFs using Gsl library.
Definition: BasicPdfsGsl.h:43
void closeFile(FilePtrSetStruct &filePtrSet, const std::string &fileType) const
Closes the file.
Definition: Environment.C:1084
const GetPot & input() const
The GetPot input file parser.
Definition: Environment.C:1149
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.
Definition: Environment.C:313
int subRank() const
Returns the rank of the MPI process in the sub-communicator subComm()
Definition: Environment.C:287
std::string optionsInputFileName() const
Access to the attribute m_optionsInputFileName, which stores the name of the input file passed by the...
Definition: Environment.C:354
const MpiComm & selfComm() const
Access function for MpiComm self-communicator.
Definition: Environment.C:300
const RngBase * rngObject() const
Access to the RNG object.
Definition: Environment.C:471
Class for random number generation (base class for either GSL or Boost RNG).
Definition: RngBase.h:45
bool exceptionalCircumstance() const
Decides whether there is an exceptional circumstance.
Definition: Environment.C:1143
FilePtrSetStruct()
Struct constructor.
Definition: Environment.C:130
unsigned int checkingLevel() const
Access function to private attribute m_checkingLevel.
Definition: Environment.C:464
void resetIdentifyingString(const std::string &newString)
Reset private attribute m_identifyingString with the value newString.
Definition: Environment.C:508
RawType_MPI_Group m_fullGroup
Definition: Environment.h:445
std::string subDisplayFileName() const
Access function for m_subDisplayFileName (displays filename on stream).
Definition: Environment.C:327
RawType_MPI_Group m_subGroup
Definition: Environment.h:457
ScopedPtr< RngBase >::Type m_rngObject
Definition: Environment.h:470
int worldRank() const
Returns the same thing as fullRank()
Definition: Environment.C:262
void setExceptionalCircumstance(bool value) const
Set an exceptional circumstance.
Definition: Environment.C:1136
int CheckFilePath(const char *path)
int fullRank() const
Returns the rank of the MPI process in QUESO&#39;s full communicator.
Definition: Environment.C:268
bool openInputFile(const std::string &fileName, const std::string &fileType, const std::set< unsigned int > &allowedSubEnvIds, FilePtrSetStruct &filePtrSet) const
Opens an input file.
Definition: Environment.C:896
ScopedPtr< boost::program_options::variables_map >::Type m_allOptionsMap
Definition: Environment.h:451
BaseEnvironment(const char *passedOptionsInputFileName, EnvOptionsValues *alternativeOptionsValues)
Default constructor.
Definition: Environment.C:145
RawType_MPI_Group subGroup() const
Access function for sub-group.
Definition: Environment.C:281
bool openUnifiedInputFile(const std::string &fileName, const std::string &fileType, FilePtrSetStruct &filePtrSet) const
Opens the unified input file.
Definition: Environment.C:991
ScopedPtr< boost::program_options::options_description >::Type m_allOptionsDesc
Definition: Environment.h:450
unsigned int syncVerbosity() const
Access function to private attribute m_syncVerbosity.
Definition: Environment.C:457
const MpiComm & subComm() const
Access function for each sub-environment&#39;s communicator.
Definition: Environment.C:293
void queso_terminate_handler()
Function for unhandled exceptions in Queso.
Definition: Environment.C:1731
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.
Definition: Environment.C:726
const BasicPdfsBase * basicPdfs() const
Access to Basic PDFs.
Definition: Environment.C:490
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.
Definition: Environment.C:397
std::string m_subIdString
Definition: Environment.h:456
std::ifstream * ifsVar
Provides a stream interface to read data from files.
Definition: Environment.h:89
MPI_Group RawType_MPI_Group
Definition: MpiComm.h:42
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"))
void QUESO_version_print(std::ostream &os)
Definition: Environment.C:56
std::string identifyingString() const
Access function to private attribute m_identifyingString: identifying string.
Definition: Environment.C:502
unsigned int m_subId
Definition: Environment.h:455
This class provides a suite options one can pass to a QUESO environment.
ScopedPtr< MpiComm >::Type m_selfComm
Definition: Environment.h:462
The QUESO MPI Communicator Class.
Definition: MpiComm.h:203
void resetSeed(int newSeedOption)
Reset RNG seed.
Definition: Environment.C:483
void print(std::ostream &os) const
Sends the environment options to the stream.
Definition: Environment.C:1725
ScopedPtr< MpiComm >::Type m_inter0Comm
Definition: Environment.h:465
unsigned int displayVerbosity() const
Definition: Environment.C:450
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.
Definition: Environment.C:348
FullEnvironment(RawType_MPI_Comm inputComm, const char *passedOptionsInputFileName, const char *prefix, EnvOptionsValues *alternativeOptionsValues)
Parallel constructor.
Definition: Environment.C:1179
std::ofstream * ofsVar
Provides a stream interface to write data to files.
Definition: Environment.h:86
std::terminate_handler old_terminate_handler
Definition: Environment.C:139
int QUESO_get_numeric_version()
Definition: Environment.C:86
virtual ~BaseEnvironment()
Destructor.
Definition: Environment.C:222
~FullEnvironment()
Destructor.
Definition: Environment.C:1720
const MpiComm & fullComm() const
Access function for the communicator that was passed to QUESO&#39;s environment.
Definition: Environment.C:274
Struct for handling data input and output from files.
Definition: Environment.h:77
EmptyEnvironment()
Default constructor. Does nothing.
Definition: Environment.C:1158
unsigned int numSubEnvironments() const
Access function to the number of sub-environments.
Definition: Environment.C:335
struct timeval m_timevalBegin
Definition: Environment.h:472
int inter0Rank() const
Returns the process inter0 rank.
Definition: Environment.C:307
~EmptyEnvironment()
Destructor.
Definition: Environment.C:1164
void print(std::ostream &os) const
Definition: Environment.C:1169
ScopedPtr< MpiComm >::Type m_subComm
Definition: Environment.h:458
void setOptionsInputFileAccessState(bool newState) const
Definition: Environment.C:365
bool fullEnvIsReady() const
Returns whether the full environment class is ready (constructor has successfully been called)...
Definition: Environment.C:256
RawType_MPI_Group m_inter0Group
Definition: Environment.h:464
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...
Definition: Environment.C:521
ScopedPtr< BasicPdfsBase >::Type m_basicPdfs
Definition: Environment.h:471
std::ofstream * subDisplayFile() const
Access function for m_subDisplayFile (displays file on stream).
Definition: Environment.C:320
int seed() const
Access to the RNG seed.
Definition: Environment.C:477
ScopedPtr< std::ofstream >::Type m_subDisplayFile
Definition: Environment.h:469

Generated on Tue Jun 5 2018 19:48:54 for queso-0.57.1 by  doxygen 1.8.5