queso-0.53.0
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-2015 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 <boost/program_options.hpp>
26 
27 #include <queso/queso.h>
28 #include <queso/Environment.h>
29 #include <queso/EnvironmentOptions.h>
30 #include <queso/RngGsl.h>
31 #include <queso/RngBoost.h>
32 #include <queso/BasicPdfsGsl.h>
33 #include <queso/BasicPdfsBoost.h>
34 #include <queso/Miscellaneous.h>
35 #include <sys/time.h>
36 #ifdef HAVE_GRVY
37 #include <grvy.h>
38 #endif
39 
40 // queso error handling
41 #include <queso/asserts.h>
42 
43 //-----------------------------
44 // Library versioning routines
45 //-----------------------------
46 
47 namespace QUESO {
48 
49  void QUESO_version_print(std::ostream &os)
50  {
51  {
52  os << "------------------------------------------------------------------------------------------" ;
53  os << "--------------------" << std::endl;
54  os << "QUESO Library: Version = " << QUESO_LIB_VERSION;
55  os << " (" << QUESO_get_numeric_version() << ")" << std::endl << std::endl;
56 
57  os << QUESO_LIB_RELEASE << std::endl << std::endl;
58 
59  os << "Build Date = " << QUESO_BUILD_DATE << std::endl;
60  os << "Build Host = " << QUESO_BUILD_HOST << std::endl;
61  os << "Build User = " << QUESO_BUILD_USER << std::endl;
62  os << "Build Arch = " << QUESO_BUILD_ARCH << std::endl;
63  os << "Build Rev = " << QUESO_BUILD_VERSION << std::endl << std::endl;
64 
65  os << "C++ Config = " << QUESO_CXX << " " << QUESO_CXXFLAGS << std::endl;
66  os << std::endl;
67  os << "Trilinos DIR = " << QUESO_TRILINOS_DIR << std::endl;
68  os << "GSL Libs = " << QUESO_GSL_DIR << std::endl;
69  os << "GRVY DIR = " << QUESO_GRVY_DIR << std::endl;
70  os << "GLPK DIR = " << QUESO_GLPK_DIR << std::endl;
71  os << "HDF5 DIR = " << QUESO_HDF5_DIR << std::endl;
72  os << "------------------------------------------------------------------------------------------" ;
73  os << "--------------------" << std::endl;
74  }
75 
76  return;
77  }
78 
80  {
81  // Note: return format follows the versioning convention xx.yy.z where
82  //
83  // xx = major version number
84  // yy = minor version number
85  // zz = micro version number
86  //
87  // For example:
88  // v. 0.23 -> 002300 = 2300
89  // v. 0.23.1 -> 002301 = 2301
90  // v. 10.23.2 -> 102302
91 
92  int major_version = 0;
93  int minor_version = 0;
94  int micro_version = 0;
95 
96 #ifdef QUESO_MAJOR_VERSION
97  major_version = QUESO_MAJOR_VERSION;
98 #endif
99 
100 #ifdef QUESO_MINOR_VERSION
101  minor_version = QUESO_MINOR_VERSION;
102 #endif
103 
104 #ifdef QUESO_MICRO_VERSION
105  micro_version = QUESO_MICRO_VERSION;
106 #endif
107 
108  return(major_version*10000 + minor_version*100 + micro_version);
109  }
110 
112  :
113  ofsVar(NULL),
114  ifsVar(NULL)
115 {
116 }
117 
119 {
120 }
121 
122  //
123  // queso terminate handler will be invoked for unhandled exceptions
124  // needs to be invoked in FullEnvironment constructor
125  //
126  std::terminate_handler old_terminate_handler;
127 
128 //*****************************************************
129 // Base class
130 //*****************************************************
131 // Default constructor --------------------------------
133  const char* passedOptionsInputFileName,
134  EnvOptionsValues* alternativeOptionsValues)
135  :
136  m_fullEnvIsReady (false),
137  m_worldRank (-1),
138  m_fullComm (NULL),
139  m_fullRank (-1),
140  m_fullCommSize (1),
141  m_optionsInputFileName (""),
142  m_optionsInputFileAccessState(true),
143  m_allOptionsDesc (NULL),
144  m_allOptionsMap (NULL),
145  m_subComm (NULL),
146  m_subRank (-1),
147  m_subCommSize (1),
148  m_selfComm (NULL),
149  m_inter0Comm (NULL),
150  m_inter0Rank (-1),
151  m_inter0CommSize (1),
152  m_subDisplayFile (NULL),
153  m_rngObject (NULL),
154  m_basicPdfs (NULL),
155  m_exceptionalCircumstance (false),
156  m_optionsObj (alternativeOptionsValues)
157 {
158  if (passedOptionsInputFileName) m_optionsInputFileName = passedOptionsInputFileName;
159 }
160 // Destructor -------------------------------------------
162 {
163  //if (m_subDisplayFile) {
164  // *m_subDisplayFile << "Entering BaseEnvironment::destructor()"
165  // << std::endl;
166  //}
167 
168  struct timeval timevalNow;
169  /*int iRC = 0;*/
170  /*iRC = */gettimeofday(&timevalNow, NULL);
171 
172  if( this->displayVerbosity() > 0 )
173  {
174  if (m_subDisplayFile) {
175  *m_subDisplayFile << "Ending run at " << ctime(&timevalNow.tv_sec)
176  << "Total run time = " << timevalNow.tv_sec - m_timevalBegin.tv_sec
177  << " seconds"
178  << std::endl;
179  }
180 
181  if (m_fullRank == 0) {
182  std::cout << "Ending run at " << ctime(&timevalNow.tv_sec)
183  << "Total run time = " << timevalNow.tv_sec - m_timevalBegin.tv_sec
184  << " seconds"
185  << std::endl;
186  }
187  }
188 
189  if (m_allOptionsMap) {
190  delete m_allOptionsMap;
191  delete m_allOptionsDesc;
192  }
193 
194  if (m_basicPdfs) delete m_basicPdfs;
195  if (m_rngObject) delete m_rngObject;
196 
197  //if (m_subDisplayFile) {
198  // *m_subDisplayFile << "Leaving BaseEnvironment::destructor()"
199  // << std::endl;
200  //}
201 
203  if (m_inter0Comm ) delete m_inter0Comm;
204  if (m_selfComm ) delete m_selfComm;
205  if (m_subComm ) delete m_subComm;
206  if (m_fullComm ) delete m_fullComm;
207 }
208 // Environment, Communicator and Options Input File methods
209 bool
211 {
212  return m_fullEnvIsReady;
213 }
214 //-------------------------------------------------------
215 int
217 {
218  return m_worldRank;
219 }
220 //-------------------------------------------------------
221 int
223 {
224  return m_fullRank;
225 }
226 //-------------------------------------------------------
227 const MpiComm&
229 {
230  queso_require_msg(m_fullComm, "m_fullComm variable is NULL");
231  return *m_fullComm;
232 }
233 //-------------------------------------------------------
236 {
237  return m_subGroup;
238 }
239 //-------------------------------------------------------
240 int
242 {
243  return m_subRank;
244 }
245 //-------------------------------------------------------
246 const MpiComm&
248 {
249  queso_require_msg(m_subComm, "m_subComm variable is NULL");
250  return *m_subComm;
251 }
252 //-------------------------------------------------------
253 const MpiComm&
255 {
256  queso_require_msg(m_selfComm, "m_selfComm variable is NULL");
257  return *m_selfComm;
258 }
259 //-------------------------------------------------------
260 int
262 {
263  return m_inter0Rank;
264 }
265 //-------------------------------------------------------
266 const MpiComm&
268 {
269  queso_require_msg(m_inter0Comm, "m_inter0Comm variable is NULL");
270  return *m_inter0Comm;
271 }
272 //-------------------------------------------------------
273 std::ofstream*
275 {
276  return m_subDisplayFile;
277 }
278 //-------------------------------------------------------
279 std::string
281 {
282  if (m_optionsObj == NULL) return ".";
283 
285 }
286 //-------------------------------------------------------
287 unsigned int
289 {
290  queso_require_msg(m_optionsObj, "m_optionsObj variable is NULL");
292 }
293 //-------------------------------------------------------
294 unsigned int
296 {
297  return m_subId;
298 }
299 //-------------------------------------------------------
300 const std::string&
302 {
303  return m_subIdString;
304 }
305 //-------------------------------------------------------
306 std::string
308 {
310  return m_optionsInputFileName;
311  }
312  else {
313  return "";
314  }
315 }
316 //-------------------------------------------------------
317 void
319 {
321 
322  return;
323 }
324 //-------------------------------------------------------
325 #ifdef UQ_USES_COMMAND_LINE_OPTIONS
326 const boost::program_options::options_description&
327 BaseEnvironment::allOptionsDesc() const
328 {
330 
331  return *m_allOptionsDesc;
332 }
333 #endif
334 //-------------------------------------------------------
335 boost::program_options::variables_map&
337 {
339 
340  queso_require_msg(m_allOptionsMap, "m_allOptionsMap variable is NULL");
341  return *m_allOptionsMap;
342 }
343 //-------------------------------------------------------
344 void
345 BaseEnvironment::scanInputFileForMyOptions(const boost::program_options::options_description& optionsDesc) const
346 {
348 
349 #ifdef UQ_USES_COMMAND_LINE_OPTIONS
350  // If you want to use command line options, the following line does *not* work outside 'main.C',
351  // e.g., in the constructor of FullEnvironment:
352  // Line: boost::program_options::store(boost::program_options::parse_command_line(argc, argv, *m_allOptionsDesc), *m_allOptionsMap);
353  //
354  // Instead, put the following three lines *immediately after* instantianting the UQ environment
355  // variable "FullEnvironment* env":
356  // Line 1: boost::program_options::store(boost::program_options::parse_command_line(argc, argv, env->allOptionsDesc()), env->allOptionsMap());
357  // Line 2: boost::program_options::notify(env->allOptionsMap());
358  // Line 3: env->getMyOptionValues();
359 #endif
360 
361 #ifdef QUESO_MEMORY_DEBUGGING
362  std::cout << "Entering BaseEnv::scanInputFileForMyOptions()" << std::endl;
363 #endif
364 
365  queso_require_msg(m_allOptionsDesc, "m_allOptionsDesc variable is NULL");
366  m_allOptionsDesc->add(optionsDesc);
367  //if (m_subDisplayFile) {
368  // *m_subDisplayFile << *m_allOptionsDesc
369  // << std::endl;
370  //}
371 
372  queso_require_not_equal_to_msg(m_optionsInputFileName, "", "m_optionsInputFileName is 'nothing'");
373  //std::ifstream ifs(m_optionsInputFileName.c_str());
374  std::ifstream* ifs = new std::ifstream(m_optionsInputFileName.c_str());
375 #ifdef QUESO_MEMORY_DEBUGGING
376  std::cout << "in BaseEnv::scanInputFileForMyOptions(), before store(a)" << std::endl;
377 #endif
378 
379  queso_require_msg(m_allOptionsMap, "m_allOptionsMap variable is NULL");
380  boost::program_options::store(boost::program_options::parse_config_file(*ifs, *m_allOptionsDesc, true), *m_allOptionsMap);
381 #ifdef QUESO_MEMORY_DEBUGGING
382  std::cout << "in BaseEnv::scanInputFileForMyOptions(), after store(a)" << std::endl;
383 #endif
384  boost::program_options::notify(*m_allOptionsMap);
385 
386  //ifs.close();
387  delete ifs;
388 #ifdef QUESO_MEMORY_DEBUGGING
389  std::cout << "Leaving BaseEnv::scanInputFileForMyOptions()" << std::endl;
390 #endif
391 
392  return;
393 }
394 //-----------------------------------------------------
395 unsigned int
397 {
398  queso_require_msg(m_optionsObj, "m_optionsObj variable is NULL");
400 }
401 //-------------------------------------------------------
402 unsigned int
404 {
405  queso_require_msg(m_optionsObj, "m_optionsObj variable is NULL");
407 }
408 //-------------------------------------------------------
409 unsigned int
411 {
412  queso_require_msg(m_optionsObj, "m_optionsObj variable is NULL");
414 }
415 //-------------------------------------------------------
416 const RngBase*
418 {
419  return m_rngObject;
420 }
421 //-------------------------------------------------------
422 int
424 {
425  return m_rngObject->seed();
426 }
427 //-------------------------------------------------------
428 void
429 BaseEnvironment::resetSeed(int newSeedOption)
430 {
431  m_rngObject->resetSeed(newSeedOption);
432  return;
433 }
434 //-------------------------------------------------------
435 const BasicPdfsBase*
437 {
438  return m_basicPdfs;
439 }
440 //-------------------------------------------------------
441 std::string
443 {
445 }
446 //-------------------------------------------------------
447 std::string
449 {
451 }
452 //-------------------------------------------------------
453 void
454 BaseEnvironment::resetIdentifyingString(const std::string& newString)
455 {
456  m_optionsObj->m_identifyingString = newString;
457  return;
458 }
459 //-------------------------------------------------------
460 struct timeval
461 BaseEnvironment::timevalBegin() const
462 {
463  return m_timevalBegin;
464 }
465 //-------------------------------------------------------
466 bool
468  const std::string& baseFileName,
469  const std::string& inputFileType,
470  const std::set<unsigned int>& allowedSubEnvIds,
471  bool writeOver,
472  FilePtrSetStruct& filePtrSet) const
473 {
474  std::string fileType(inputFileType);
475 #ifdef QUESO_HAS_HDF5
476  // Do nothing
477 #else
478  if (fileType == UQ_FILE_EXTENSION_FOR_HDF_FORMAT) {
479  if (m_subDisplayFile) {
480  *this->subDisplayFile() << "WARNING in BaseEnvironment::openOutputFile()"
481  << ": file format '" << UQ_FILE_EXTENSION_FOR_HDF_FORMAT
482  << "' has been requested, but this QUESO library has not been built with 'hdf5'"
483  << ". Code will therefore process the file format '" << UQ_FILE_EXTENSION_FOR_HDF_FORMAT
484  << "' instead..."
485  << std::endl;
486  }
487  if (this->subRank() == 0) {
488  std::cerr << "WARNING in BaseEnvironment::openOutputFile()"
489  << ": file format '" << UQ_FILE_EXTENSION_FOR_HDF_FORMAT
490  << "' has been requested, but this QUESO library has not been built with 'hdf5'"
491  << ". Code will therefore process the file format '" << UQ_FILE_EXTENSION_FOR_HDF_FORMAT
492  << "' instead..."
493  << std::endl;
494  }
496  }
497 #endif
498 
499  bool returnValue = true;
500  filePtrSet.ofsVar = NULL;
501  if ((baseFileName == UQ_ENV_FILENAME_FOR_NO_OUTPUT_FILE) ||
502  (allowedSubEnvIds.find(this->subId()) == allowedSubEnvIds.end() )) {
503  if ((m_subDisplayFile) && (this->displayVerbosity() > 10)) { // output debug
504  *this->subDisplayFile() << "In BaseEnvironment::openOutputFile()"
505  << ", subId = " << this->subId()
506  << ": no output file opened with base name '" << baseFileName << "." << fileType
507  << "'"
508  << ", writeOver = " << writeOver
509  << std::endl;
510  }
511  returnValue = false;
512  }
513  else {
515  // Open file
517  if ((m_subDisplayFile) && (this->displayVerbosity() > 10)) { // output debug
518  *this->subDisplayFile() << "In BaseEnvironment::openOutputFile()"
519  << ", subId = " << this->subId()
520  << ": opening output file with base name '" << baseFileName << "." << fileType
521  << "'"
522  << ", writeOver = " << writeOver
523  << std::endl;
524  }
525 
526  if (this->subRank() == 0) {
527 #if 0
528  std::cout << "In BaseEnvironment::openOutputFile()"
529  << ": opening output file with base name '" << baseFileName << "." << fileType
530  << "'"
531  << ", writeOver = " << writeOver
532  << std::endl;
533 #endif
534 
536  // Verify parent directory exists (for cases when a user
537  // specifies a relative path for the desired output file).
539  // std::cout << "checking " << baseFileName+"_sub"+this->subIdString()+"."+fileType << std::endl;
540  if ((m_subDisplayFile) && (this->displayVerbosity() > 10)) { // output debug
541  *this->subDisplayFile() << "In BaseEnvironment::openOutputFile()"
542  << ", subId = " << this->subId()
543  << ", trying to open output file with base name '" << baseFileName << "." << fileType
544  << "'"
545  << ", writeOver = " << writeOver
546  << ": calling CheckFilePath()..."
547  << std::endl;
548  }
549  int irtrn = CheckFilePath((baseFileName+"_sub"+this->subIdString()+"."+fileType).c_str());
550  if ((m_subDisplayFile) && (this->displayVerbosity() > 10)) { // output debug
551  *this->subDisplayFile() << "In BaseEnvironment::openOutputFile()"
552  << ", subId = " << this->subId()
553  << ", trying to open output file with base name '" << baseFileName << "." << fileType
554  << "'"
555  << ", writeOver = " << writeOver
556  << ": returned from CheckFilePath() with irtrn = " << irtrn
557  << std::endl;
558  }
559  queso_require_greater_equal_msg(irtrn, 0, "unable to verify output path");
560 
561  if (writeOver) {
563  // Write over an eventual pre-existing file
565  if (fileType == UQ_FILE_EXTENSION_FOR_MATLAB_FORMAT) {
566  filePtrSet.ofsVar = new std::ofstream((baseFileName+"_sub"+this->subIdString()+"."+fileType).c_str(),
567  std::ofstream::out | std::ofstream::trunc);
568  }
569  else if (fileType == UQ_FILE_EXTENSION_FOR_HDF_FORMAT) {
570  queso_error_msg("hdf file type not supported yet");
571  }
572  else {
573  queso_error_msg("invalid file type");
574  }
575  if ((m_subDisplayFile) && (this->displayVerbosity() > 10)) { // output debug
576  *this->subDisplayFile() << "In BaseEnvironment::openOutputFile()"
577  << ": just opened output file with base name '" << baseFileName << "." << fileType
578  << "'"
579  << ", writeOver = " << writeOver
580  << ", options 'out|trunc'"
581  << ", osfvar = " << filePtrSet.ofsVar
582  << std::endl;
583  }
584  }
585  else {
587  // Write at the end of an eventual pre-existing file
589  if (fileType == UQ_FILE_EXTENSION_FOR_MATLAB_FORMAT) {
590 #if 0
591  filePtrSet.ofsVar = new std::ofstream((baseFileName+"_sub"+this->subIdString()+"."+fileType).c_str(),
592  std::ofstream::in);
593  std::cout << "filePtrSet.ofsVar(1) = " << filePtrSet.ofsVar << std::endl;
594  if (filePtrSet.ofsVar) std::cout << "filePtrSet.ofsVar(1)->is_open() = " << filePtrSet.ofsVar->is_open() << std::endl;
595  if (filePtrSet.ofsVar) delete filePtrSet.ofsVar;
596 #endif
597  // 'm' and Ranger nodes behave differently on ofstream constructor... prudenci 2010/03/05
598  filePtrSet.ofsVar = new std::ofstream((baseFileName+"_sub"+this->subIdString()+"."+fileType).c_str(),
599  std::ofstream::out /*| std::ofstream::in*/ | std::ofstream::app);
600  }
601  else if (fileType == UQ_FILE_EXTENSION_FOR_HDF_FORMAT) {
602  queso_error_msg("hdf file type not supported yet");
603  }
604  else {
605  queso_error_msg("invalid file type");
606  }
607  if ((m_subDisplayFile) && (this->displayVerbosity() > 10)) { // output debug
608  *this->subDisplayFile() << "In BaseEnvironment::openOutputFile()"
609  << ": just opened output file with base name '" << baseFileName << "." << fileType
610  << "'"
611  << ", writeOver = " << writeOver
612  << ", options 'out|in|app'"
613  << ", osfvar = " << filePtrSet.ofsVar
614  << std::endl;
615  }
616 
617  if (fileType == UQ_FILE_EXTENSION_FOR_MATLAB_FORMAT) {
618  //std::cout << "filePtrSet.ofsVar(2) = " << filePtrSet.ofsVar << std::endl;
619  //if (filePtrSet.ofsVar) std::cout << "filePtrSet.ofsVar(2)->is_open() = " << filePtrSet.ofsVar->is_open() << std::endl;
620  if ((filePtrSet.ofsVar == NULL ) ||
621  (filePtrSet.ofsVar->is_open() == false)) {
622  //std::cout << "Retrying 1..." << std::endl;
623  delete filePtrSet.ofsVar;
624  filePtrSet.ofsVar = new std::ofstream((baseFileName+"_sub"+this->subIdString()+"."+fileType).c_str(),
625  std::ofstream::out | std::ofstream::trunc);
626  if ((m_subDisplayFile) && (this->displayVerbosity() > 10)) { // output debug
627  *this->subDisplayFile() << "In BaseEnvironment::openOutputFile()"
628  << ": just opened output file with base name '" << baseFileName << "." << fileType
629  << "'"
630  << ", writeOver = " << writeOver
631  << ", options 'out|trunc'"
632  << ", osfvar = " << filePtrSet.ofsVar
633  << std::endl;
634  }
635  }
636  } // only for matlab formats
637  }
638  if (filePtrSet.ofsVar != NULL) {
639  if ((m_subDisplayFile) && (this->displayVerbosity() > 10)) { // output debug
640  *this->subDisplayFile() << "In BaseEnvironment::openOutputFile()"
641  << ", subId = " << this->subId()
642  << ": succeeded on opening output file with base name '" << baseFileName << "." << fileType
643  << "'"
644  << ", writeOver = " << writeOver
645  << std::endl;
646  }
647  }
648  else {
649  std::cerr << "In BaseEnvironment::openOutputFile()"
650  << ": failed to open output file with base name '" << baseFileName << "." << fileType
651  << "'"
652  << std::endl;
653  }
654  queso_require_msg((filePtrSet.ofsVar && filePtrSet.ofsVar->is_open()), "failed to open output file");
655  }
656  else {
657  returnValue = false;
658  }
659  //this->subComm().Barrier(); // prudenci-2011-01-17
660  }
661 
662  return returnValue;
663 }
664 //-------------------------------------------------------
665 bool
667  const std::string& baseFileName,
668  const std::string& inputFileType,
669  bool writeOver,
670  FilePtrSetStruct& filePtrSet) const
671 {
672  std::string fileType(inputFileType);
673 #ifdef QUESO_HAS_HDF5
674  // Do nothing
675 #else
676  if (fileType == UQ_FILE_EXTENSION_FOR_HDF_FORMAT) {
677  if (m_subDisplayFile) {
678  *this->subDisplayFile() << "WARNING in BaseEnvironment::openUnifiedOutputFile()"
679  << ": file format '" << UQ_FILE_EXTENSION_FOR_HDF_FORMAT
680  << "' has been requested, but this QUESO library has not been built with 'hdf5'"
681  << ". Code will therefore process the file format '" << UQ_FILE_EXTENSION_FOR_HDF_FORMAT
682  << "' instead..."
683  << std::endl;
684  }
685  if (this->subRank() == 0) {
686  std::cerr << "WARNING in BaseEnvironment::openUnifiedOutputFile()"
687  << ": file format '" << UQ_FILE_EXTENSION_FOR_HDF_FORMAT
688  << "' has been requested, but this QUESO library has not been built with 'hdf5'"
689  << ". Code will therefore process the file format '" << UQ_FILE_EXTENSION_FOR_HDF_FORMAT
690  << "' instead..."
691  << std::endl;
692  }
694  }
695 #endif
696 
697  bool returnValue = true;
698  filePtrSet.ofsVar = NULL;
699  if (baseFileName == ".") {
700  if ((m_subDisplayFile) && (this->displayVerbosity() > 10)) { // output debug
701  *this->subDisplayFile() << "In BaseEnvironment::openUnifiedOutputFile()"
702  << ": no unified output file opened with base name '" << baseFileName << "." << fileType
703  << "'"
704  << ", writeOver = " << writeOver
705  << std::endl;
706  }
707  returnValue = false;
708  }
709  else {
711  // Open file
713  if ((m_subDisplayFile) && (this->displayVerbosity() > 10)) { // output debug
714  *this->subDisplayFile() << "In BaseEnvironment::openUnifiedOutputFile()"
715  << ": opening unified output file with base name '" << baseFileName << "." << fileType
716  << "'"
717  << ", writeOver = " << writeOver
718  << std::endl;
719  }
720 
721 
722  //if ((this->subRank () == 0) &&
723  // (this->inter0Rank() == 0)) {
724 #if 0
725  std::cout << "In BaseEnvironment::openUnifiedOutputFile()"
726  << ": opening output file with base name '" << baseFileName << "." << fileType
727  << "'"
728  << ", writeOver = " << writeOver
729  << std::endl;
730 #endif
731  // Verify parent directory exists (for cases when a user
733  // specifies a relative path for the desired output file). prudenci 2010/06/26
735  // std::cout << "checking " << baseFileName+"."+fileType << std::endl;
736  int irtrn = CheckFilePath((baseFileName+"."+fileType).c_str());
737  queso_require_greater_equal_msg(irtrn, 0, "unable to verify output path");
738 
739  if (writeOver) {
741  // Write over an eventual pre-existing file
743  if (fileType == UQ_FILE_EXTENSION_FOR_MATLAB_FORMAT) {
744  filePtrSet.ofsVar = new std::ofstream((baseFileName+"."+fileType).c_str(),
745  std::ofstream::out | std::ofstream::trunc);
746  }
747 #ifdef QUESO_HAS_HDF5
748  else if (fileType == UQ_FILE_EXTENSION_FOR_HDF_FORMAT) {
749  filePtrSet.h5Var = H5Fcreate((baseFileName+"."+fileType).c_str(),
750  H5F_ACC_TRUNC,
751  H5P_DEFAULT,
752  H5P_DEFAULT);
753  }
754 #endif
755  else {
756  queso_error_msg("invalid file type");
757  }
758  if ((m_subDisplayFile) && (this->displayVerbosity() > 10)) { // output debug
759  *this->subDisplayFile() << "In BaseEnvironment::openUnifiedOutputFile()"
760  << ": just opened output file with base name '" << baseFileName << "." << fileType
761  << "'"
762  << ", writeOver = " << writeOver
763  << ", options 'out|trunc'"
764  << ", osfvar = " << filePtrSet.ofsVar
765  << std::endl;
766  }
767  }
768  else {
770  // Write at the end of an eventual pre-existing file
771  // 'm' and Ranger nodes behave differently on ofstream constructor... prudenci 2010/03/05
773  if (fileType == UQ_FILE_EXTENSION_FOR_MATLAB_FORMAT) {
774  filePtrSet.ofsVar = new std::ofstream((baseFileName+"."+fileType).c_str(),
775  std::ofstream::out /*| std::ofstream::in*/ | std::ofstream::app);
776  }
777 #ifdef QUESO_HAS_HDF5
778  else if (fileType == UQ_FILE_EXTENSION_FOR_HDF_FORMAT) {
779  filePtrSet.h5Var = H5Fcreate((baseFileName+"."+fileType).c_str(), // TEMPORARY - FIX ME
780  H5F_ACC_TRUNC,
781  H5P_DEFAULT,
782  H5P_DEFAULT);
783 
784  // m_worldRank,
785  // "BaseEnvironment::openUnifiedOutputFile(), writeOver=false",
786  // "hdf file type not supported yet");
787  }
788 #endif
789  else {
790  queso_error_msg("invalid file type");
791  }
792  if ((m_subDisplayFile) && (this->displayVerbosity() > 10)) { // output debug
793  *this->subDisplayFile() << "In BaseEnvironment::openUnifiedOutputFile()"
794  << ": just opened output file with base name '" << baseFileName << "." << fileType
795  << "'"
796  << ", writeOver = " << writeOver
797  << ", options 'out|in|app'"
798  << ", osfvar = " << filePtrSet.ofsVar
799  << std::endl;
800  }
801  if ((filePtrSet.ofsVar == NULL ) ||
802  (filePtrSet.ofsVar->is_open() == false)) {
803 #if 0
804  std::cout << "Retrying 2..." << std::endl;
805 #endif
806  delete filePtrSet.ofsVar;
807  filePtrSet.ofsVar = new std::ofstream((baseFileName+"."+fileType).c_str(),
808  std::ofstream::out | std::ofstream::trunc);
809  if ((m_subDisplayFile) && (this->displayVerbosity() > 10)) { // output debug
810  *this->subDisplayFile() << "In BaseEnvironment::openUnifiedOutputFile()"
811  << ": just opened output file with base name '" << baseFileName << "." << fileType
812  << "'"
813  << ", writeOver = " << writeOver
814  << ", options 'out|trunc'"
815  << ", osfvar = " << filePtrSet.ofsVar
816  << std::endl;
817  }
818  }
819  }
820  if (filePtrSet.ofsVar == NULL) {
821  std::cerr << "In BaseEnvironment::openUnifiedOutputFile()"
822  << ": failed to open unified output file with base name '" << baseFileName << "." << fileType
823  << "'"
824  << std::endl;
825  }
826  queso_require_msg((filePtrSet.ofsVar && filePtrSet.ofsVar->is_open()), "failed to open output file");
827  //}
828  }
829 
830  return returnValue;
831 }
832 //-------------------------------------------------------
833 bool
835  const std::string& baseFileName,
836  const std::string& inputFileType,
837  const std::set<unsigned int>& allowedSubEnvIds,
838  FilePtrSetStruct& filePtrSet) const
839 {
840  std::string fileType(inputFileType);
841 #ifdef QUESO_HAS_HDF5
842  // Do nothing
843 #else
844  if (fileType == UQ_FILE_EXTENSION_FOR_HDF_FORMAT) {
845  if (m_subDisplayFile) {
846  *this->subDisplayFile() << "WARNING in BaseEnvironment::openInputFile()"
847  << ": file format '" << UQ_FILE_EXTENSION_FOR_HDF_FORMAT
848  << "' has been requested, but this QUESO library has not been built with 'hdf5'"
849  << ". Code will therefore process the file format '" << UQ_FILE_EXTENSION_FOR_HDF_FORMAT
850  << "' instead..."
851  << std::endl;
852  }
853  if (this->subRank() == 0) {
854  std::cerr << "WARNING in BaseEnvironment::openInputFile()"
855  << ": file format '" << UQ_FILE_EXTENSION_FOR_HDF_FORMAT
856  << "' has been requested, but this QUESO library has not been built with 'hdf5'"
857  << ". Code will therefore process the file format '" << UQ_FILE_EXTENSION_FOR_HDF_FORMAT
858  << "' instead..."
859  << std::endl;
860  }
862  }
863 #endif
864 
865  bool returnValue = true;
866  filePtrSet.ifsVar = NULL;
867  if ((baseFileName == UQ_ENV_FILENAME_FOR_NO_INPUT_FILE) ||
868  (allowedSubEnvIds.find(this->subId()) == allowedSubEnvIds.end() )) {
869  if ((m_subDisplayFile) && (this->displayVerbosity() >= 10)) {
870  *this->subDisplayFile() << "In BaseEnvironment::openInputFile()"
871  << ": no input file opened with base name '" << baseFileName << "." << fileType
872  << "'"
873  << std::endl;
874  }
875  returnValue = false;
876  }
877  else {
879  // Open file
881  if ((m_subDisplayFile) && (this->displayVerbosity() >= 10)) {
882  *this->subDisplayFile() << "In BaseEnvironment::openInputFile()"
883  << ": opening input file with base name '" << baseFileName << "." << fileType
884  << "'"
885  << std::endl;
886  }
887  if (this->subRank() == 0) {
889  // Verify parent directory exists (for cases when a user
890  // specifies a relative path for the desired output file). prudenci 2010/06/26
892  // std::cout << "checking " << baseFileName+"."+fileType << std::endl;
893  int irtrn = CheckFilePath((baseFileName+"."+fileType).c_str());
894  queso_require_greater_equal_msg(irtrn, 0, "unable to verify input path");
895 
896  if (fileType == UQ_FILE_EXTENSION_FOR_MATLAB_FORMAT) {
897  filePtrSet.ifsVar = new std::ifstream((baseFileName+"."+fileType).c_str(),
898  std::ofstream::in);
899  if ((filePtrSet.ifsVar == NULL) || (filePtrSet.ifsVar->is_open() == false)) {
900  std::cerr << "In BaseEnvironment::openInputFile()"
901  << ": failed to open input file with base name '" << baseFileName << "." << fileType
902  << "'"
903  << std::endl;
904  }
905  queso_require_msg(!((filePtrSet.ifsVar == NULL) || (filePtrSet.ifsVar->is_open() == false)), "file with fileName could not be found");
906  }
907 #ifdef QUESO_HAS_HDF5
908  else if (fileType == UQ_FILE_EXTENSION_FOR_HDF_FORMAT) {
909  filePtrSet.h5Var = H5Fopen((baseFileName+"."+fileType).c_str(),
910  H5F_ACC_RDONLY,
911  H5P_DEFAULT);
912  }
913 #endif
914  else {
915  queso_error_msg("invalid file type");
916  }
917  }
918  else {
919  returnValue = false;
920  }
921  //this->subComm().Barrier(); // prudenci-2011-01-17
922  }
923 
924  return returnValue;
925 }
926 //-------------------------------------------------------
927 bool
929  const std::string& baseFileName,
930  const std::string& inputFileType,
931  FilePtrSetStruct& filePtrSet) const
932 {
933  std::string fileType(inputFileType);
934 #ifdef QUESO_HAS_HDF5
935  // Do nothing
936 #else
937  if (fileType == UQ_FILE_EXTENSION_FOR_HDF_FORMAT) {
938  if (m_subDisplayFile) {
939  *this->subDisplayFile() << "WARNING in BaseEnvironment::openUnifiedInputFile()"
940  << ": file format '" << UQ_FILE_EXTENSION_FOR_HDF_FORMAT
941  << "' has been requested, but this QUESO library has not been built with 'hdf5'"
942  << ". Code will therefore process the file format '" << UQ_FILE_EXTENSION_FOR_HDF_FORMAT
943  << "' instead..."
944  << std::endl;
945  }
946  if (this->subRank() == 0) {
947  std::cerr << "WARNING in BaseEnvironment::openUnifiedInputFile()"
948  << ": file format '" << UQ_FILE_EXTENSION_FOR_HDF_FORMAT
949  << "' has been requested, but this QUESO library has not been built with 'hdf5'"
950  << ". Code will therefore process the file format '" << UQ_FILE_EXTENSION_FOR_HDF_FORMAT
951  << "' instead..."
952  << std::endl;
953  }
955  }
956 #endif
957 
958  bool returnValue = true;
959  filePtrSet.ifsVar = NULL;
960  if (baseFileName == UQ_ENV_FILENAME_FOR_NO_INPUT_FILE) {
961  if ((m_subDisplayFile) && (this->displayVerbosity() >= 10)) {
962  *this->subDisplayFile() << "In BaseEnvironment::openUnifiedInputFile()"
963  << ": no input file opened with base name '" << baseFileName << "." << fileType
964  << "'"
965  << std::endl;
966  }
967  returnValue = false;
968  }
969  else {
971  // Open file
973  if ((m_subDisplayFile) && (this->displayVerbosity() >= 10)) {
974  *this->subDisplayFile() << "In BaseEnvironment::openUnifiedInputFile()"
975  << ": opening input file with base name '" << baseFileName << "." << fileType
976  << "'"
977  << std::endl;
978  }
979  if (this->subRank() == 0) { // Needed ???????? prudenci 2010-11-11
981  // Verify parent directory exists (for cases when a user
982  // specifies a relative path for the desired output file). prudenci 2010/06/26
984  // std::cout << "checking " << baseFileName+"."+fileType << std::endl;
985  int irtrn = CheckFilePath((baseFileName+"."+fileType).c_str());
986  queso_require_greater_equal_msg(irtrn, 0, "unable to verify input path");
987 
988  if (fileType == UQ_FILE_EXTENSION_FOR_MATLAB_FORMAT) {
989  filePtrSet.ifsVar = new std::ifstream((baseFileName+"."+fileType).c_str(),
990  std::ofstream::in);
991  if ((filePtrSet.ifsVar == NULL) || (filePtrSet.ifsVar->is_open() == false)) {
992  std::cerr << "In BaseEnvironment::openUnifiedInputFile()"
993  << ": failed to open input file with base name '" << baseFileName << "." << fileType
994  << "'"
995  << std::endl;
996  }
997  queso_require_msg(!((filePtrSet.ifsVar == NULL) || (filePtrSet.ifsVar->is_open() == false)), "file with fileName could not be found");
998  }
999 #ifdef QUESO_HAS_HDF5
1000  else if (fileType == UQ_FILE_EXTENSION_FOR_HDF_FORMAT) {
1001  filePtrSet.h5Var = H5Fopen((baseFileName+"."+fileType).c_str(),
1002  H5F_ACC_RDONLY,
1003  H5P_DEFAULT);
1004  }
1005 #endif
1006  else {
1007  queso_error_msg("invalid file type");
1008  }
1009  }
1010  //else {
1011  // returnValue = false;
1012  //}
1013  //this->subComm().Barrier();
1014  }
1015 
1016  return returnValue;
1017 }
1018 //-------------------------------------------------------
1019 void
1021  FilePtrSetStruct& filePtrSet,
1022  const std::string& inputFileType) const
1023 {
1024  std::string fileType(inputFileType);
1025 #ifdef QUESO_HAS_HDF5
1026  // Do nothing
1027 #else
1028  if (fileType == UQ_FILE_EXTENSION_FOR_HDF_FORMAT) {
1029  if (m_subDisplayFile) {
1030  *this->subDisplayFile() << "WARNING in BaseEnvironment::closeFile()"
1031  << ": file format '" << UQ_FILE_EXTENSION_FOR_HDF_FORMAT
1032  << "' has been requested, but this QUESO library has not been built with 'hdf5'"
1033  << ". Code will therefore process the file format '" << UQ_FILE_EXTENSION_FOR_HDF_FORMAT
1034  << "' instead..."
1035  << std::endl;
1036  }
1037  if (this->subRank() == 0) {
1038  std::cerr << "WARNING in BaseEnvironment::closeFile()"
1039  << ": file format '" << UQ_FILE_EXTENSION_FOR_HDF_FORMAT
1040  << "' has been requested, but this QUESO library has not been built with 'hdf5'"
1041  << ". Code will therefore process the file format '" << UQ_FILE_EXTENSION_FOR_HDF_FORMAT
1042  << "' instead..."
1043  << std::endl;
1044  }
1046  }
1047 #endif
1048 
1049  if (fileType == UQ_FILE_EXTENSION_FOR_MATLAB_FORMAT) {
1050  //filePtrSet.ofsVar->close(); // close() crashes on Mac; need to use delete(); why? prudenci 2010/June
1051  delete filePtrSet.ofsVar;
1052  filePtrSet.ofsVar = NULL;
1053 
1054  //filePtrSet.ifsVar->close();
1055  delete filePtrSet.ifsVar;
1056  filePtrSet.ifsVar = NULL;
1057  }
1058 #ifdef QUESO_HAS_HDF5
1059  else if (fileType == UQ_FILE_EXTENSION_FOR_HDF_FORMAT) {
1060  H5Fclose(filePtrSet.h5Var);
1061  }
1062 #endif
1063  else {
1064  queso_error_msg("invalid file type");
1065  }
1066 
1067  return;
1068 }
1069 //-------------------------------------------------------
1070 void
1072 {
1073  m_exceptionalCircumstance = value;
1074  return;
1075 }
1076 //-------------------------------------------------------
1077 bool
1079 {
1081 }
1082 
1083 
1084 //*****************************************************
1085 // Empty Environment
1086 //*****************************************************
1088  :
1089  BaseEnvironment("",NULL)
1090 {
1091 }
1092 //-------------------------------------------------------
1094 {
1095 }
1096 //-------------------------------------------------------
1097 void
1098 EmptyEnvironment::print(std::ostream& os) const
1099 {
1100  os.flush(); // just to avoid icpc warnings
1101  return;
1102 }
1103 
1104 //*****************************************************
1105 // Full Environment
1106 //*****************************************************
1108  RawType_MPI_Comm inputComm,
1109  const char* passedOptionsInputFileName,
1110  const char* prefix,
1111  EnvOptionsValues* alternativeOptionsValues)
1112  :
1113  BaseEnvironment(passedOptionsInputFileName,alternativeOptionsValues)
1114 {
1115 #ifdef QUESO_MEMORY_DEBUGGING
1116  std::cout << "Entering FullEnv" << std::endl;
1117 #endif
1118 
1120  // Initialize "full" communicator -- Not necessarily MPI_COMM_WORLD
1122  int mpiRC = MPI_Comm_rank(inputComm,&m_worldRank);
1123  queso_require_equal_to_msg(mpiRC, MPI_SUCCESS, "failed to get world fullRank()");
1124 
1125  m_fullComm = new MpiComm(*this,inputComm);
1128 
1129  mpiRC = MPI_Comm_group(m_fullComm->Comm(), &m_fullGroup);
1130  queso_require_equal_to_msg(mpiRC, MPI_SUCCESS, "failed MPI_Comm_group()");
1131 
1132  // saving old uncaught exception handler, invoking queso_terminate
1133  old_terminate_handler = std::set_terminate(queso_terminate_handler);
1134 
1135 #ifdef QUESO_MEMORY_DEBUGGING
1136  std::cout << "In FullEnv, finished dealing with MPI initially" << std::endl;
1137 #endif
1138 
1140  // Read options
1142  // If NULL, we create one
1143  if (m_optionsObj == NULL) {
1144  EnvOptionsValues * tempOptions = new EnvOptionsValues(this, prefix);
1145 
1146  // If there's an input file, we grab the options from there. Otherwise the
1147  // defaults are used
1148  if (m_optionsInputFileName != "") {
1149  m_allOptionsMap = new boost::program_options::variables_map();
1150  m_allOptionsDesc = new boost::program_options::options_description("Allowed options");
1151 
1153  }
1154 
1155  // We did this dance because scanOptionsValues is not a const method, but
1156  // m_optionsObj is a pointer to const
1157  m_optionsObj = tempOptions;
1158  }
1159 
1160  // If help option was supplied, print info
1161  if (m_optionsObj->m_help != "") {
1162  // We write to std::cout because subDisplayFile() isn't ready yet?
1163  std::cout << (*m_optionsObj) << std::endl;
1164  }
1165 
1167  fullComm().NumProc() % m_optionsObj->m_numSubEnvironments, 0,
1168  "total number of processors in environment must be multiple of the specified number of subEnvironments");
1169 
1170 #ifdef QUESO_MEMORY_DEBUGGING
1171  std::cout << "In FullEnv, finished scanning options" << std::endl;
1172 #endif
1173 
1174  // Only display these messages if the user wants them
1175  // NOTE: This got moved below the Read Options section
1176  // because we need the options to be read to know what
1177  // the verbosity level is.
1178  if (this->displayVerbosity() > 0) {
1180  // Display main initial messages
1181  // 'std::cout' is for: main trace messages + synchronized trace messages + error messages prior to 'exit()' or 'abort()'
1183  /*int iRC = 0;*/
1184  /*iRC = */gettimeofday(&m_timevalBegin, NULL);
1185 
1186  if (m_fullRank == 0) {
1187  QUESO_version_print(std::cout);
1188  }
1189 
1190  if (m_fullRank == 0) {
1191  std::cout << "Beginning run at " << ctime(&m_timevalBegin.tv_sec)
1192  << std::endl;
1193  }
1194  }
1195 
1197  // Deal with multiple subEnvironments: create the sub communicators, one for each subEnvironment
1199  unsigned int numRanksPerSubEnvironment = m_fullCommSize/m_optionsObj->m_numSubEnvironments;
1200 
1201  m_subId = m_fullRank/numRanksPerSubEnvironment;
1202  char tmpSubId[16];
1203  sprintf(tmpSubId,"%u",m_subId);
1204  m_subIdString = tmpSubId;
1205 
1207  m_optionsObj->m_subDisplayAllowedSet.insert((unsigned int) m_subId);
1208  }
1209 
1210  std::vector<int> fullRanksOfMySubEnvironment(numRanksPerSubEnvironment,0);
1211  for (unsigned int i = 0; i < numRanksPerSubEnvironment; ++i) {
1212  fullRanksOfMySubEnvironment[i] = m_subId * numRanksPerSubEnvironment + i;
1213  }
1214 
1215  mpiRC = MPI_Group_incl(m_fullGroup, (int) numRanksPerSubEnvironment, &fullRanksOfMySubEnvironment[0], &m_subGroup);
1216  queso_require_equal_to_msg(mpiRC, MPI_SUCCESS, "failed MPI_Group_incl() for a subEnvironment");
1217 
1218  RawType_MPI_Comm subRawComm;
1219  mpiRC = MPI_Comm_create(m_fullComm->Comm(), m_subGroup, &subRawComm);
1220  queso_require_equal_to_msg(mpiRC, MPI_SUCCESS, "failed MPI_Comm_group() for a subEnvironment");
1221  m_subComm = new MpiComm(*this,subRawComm);
1222  m_subRank = m_subComm->MyPID();
1224 
1226  // Deal with multiple subEnvironments: create the self communicator
1229 
1231  // Deal with multiple subEnvironments: create the inter0 communicator
1233  std::vector<int> fullRanksOfInter0(m_optionsObj->m_numSubEnvironments,0);
1234  for (unsigned int i = 0; i < m_optionsObj->m_numSubEnvironments; ++i) {
1235  fullRanksOfInter0[i] = i * numRanksPerSubEnvironment;
1236  }
1237  mpiRC = MPI_Group_incl(m_fullGroup, (int) m_optionsObj->m_numSubEnvironments, &fullRanksOfInter0[0], &m_inter0Group);
1238  queso_require_equal_to_msg(mpiRC, MPI_SUCCESS, "failed MPI_Group_incl() for inter0");
1239  RawType_MPI_Comm inter0RawComm;
1240  mpiRC = MPI_Comm_create(m_fullComm->Comm(), m_inter0Group, &inter0RawComm);
1241  queso_require_equal_to_msg(mpiRC, MPI_SUCCESS, "failed MPI_Comm_group() for inter0");
1242  if (m_fullRank%numRanksPerSubEnvironment == 0) {
1243  m_inter0Comm = new MpiComm(*this,inter0RawComm);
1246  }
1247 
1249  // This situation has been already taken care of above
1250  }
1252  if (m_inter0Rank >= 0) {
1253  m_optionsObj->m_subDisplayAllowedSet.insert((unsigned int) m_subId);
1254  }
1255  }
1256 
1257 
1259  // Open "screen" file
1261  bool openFile = false;
1262  if ((m_subRank == 0 ) &&
1265  openFile = true;
1266  }
1267 
1268  if (openFile && m_worldRank == 0) {
1270  // Verify parent directory exists (for cases when a user
1271  // specifies a relative path for the desired output file).
1273  int irtrn = CheckFilePath((m_optionsObj->m_subDisplayFileName+"_sub"+m_subIdString+".txt").c_str());
1274  queso_require_greater_equal_msg(irtrn, 0, "unable to verify output path");
1275  }
1276 
1278  // Ensure that rank 0 has created path, if necessary, before other tasks use it
1280  m_fullComm->Barrier();
1281 
1282  if (openFile) {
1284  // Always write over an eventual pre-existing file
1286  m_subDisplayFile = new std::ofstream((m_optionsObj->m_subDisplayFileName+"_sub"+m_subIdString+".txt").c_str(),
1287  std::ofstream::out | std::ofstream::trunc);
1288  queso_require_msg((m_subDisplayFile && m_subDisplayFile->is_open()), "failed to open sub screen file");
1289 
1291 
1292  *m_subDisplayFile << "Beginning run at " << ctime(&m_timevalBegin.tv_sec)
1293  << std::endl;
1294  }
1295 
1297  // Debug message related to subEnvironments
1299  if (this->displayVerbosity() >= 2) {
1300  for (int i = 0; i < m_fullCommSize; ++i) {
1301  if (i == m_fullRank) {
1302  //std::cout << "In FullEnvironment::commonConstructor()"
1303  std::cout << "MPI node of worldRank " << m_worldRank
1304  << " has fullRank " << m_fullRank
1305  << ", belongs to subEnvironment of id " << m_subId
1306  << ", and has subRank " << m_subRank
1307  << std::endl;
1308 
1309  std::cout << "MPI node of worldRank " << m_worldRank
1310  << " belongs to sub communicator with full ranks";
1311  for (unsigned int j = 0; j < fullRanksOfMySubEnvironment.size(); ++j) {
1312  std::cout << " " << fullRanksOfMySubEnvironment[j];
1313  }
1314  std::cout << "\n";
1315 
1316  if (m_inter0Comm) {
1317  std::cout << "MPI node of worldRank " << m_worldRank
1318  << " also belongs to inter0 communicator with full ranks";
1319  for (unsigned int j = 0; j < fullRanksOfInter0.size(); ++j) {
1320  std::cout << " " << fullRanksOfInter0[j];
1321  }
1322  std::cout << ", and has inter0Rank " << m_inter0Rank;
1323  }
1324  std::cout << "\n";
1325 
1326  std::cout << std::endl;
1327  }
1328  m_fullComm->Barrier();
1329  }
1330  //if (this->fullRank() == 0) std::cout << "Sleeping 3 seconds..."
1331  // << std::endl;
1332  //sleep(3);
1333  }
1334 
1336  // Deal with seed
1338  if (m_optionsObj->m_rngType == "gsl") {
1341  }
1342  else if (m_optionsObj->m_rngType == "boost") {
1345  }
1346  else {
1347  std::cerr << "In Environment::constructor()"
1348  << ": rngType = " << m_optionsObj->m_rngType
1349  << std::endl;
1350  queso_error_msg("the requested 'rngType' is not supported yet");
1351  }
1352 
1354  // Leave commonConstructor()
1356  m_fullComm->Barrier();
1357  m_fullEnvIsReady = true;
1358 
1359  if ((m_subDisplayFile) && (this->displayVerbosity() >= 5)) {
1360  *m_subDisplayFile << "Done with initializations at FullEnvironment::commonConstructor()"
1361  << std::endl;
1362  }
1363 
1364  return;
1365 }
1366 //-------------------------------------------------------
1368 {
1369 }
1370 //-------------------------------------------------------
1371 void
1372 FullEnvironment::print(std::ostream& os) const
1373 {
1374  os.flush(); // just to avoid icpc warnings
1375  return;
1376 }
1377 
1379 {
1380  int mpi_initialized;
1381  MPI_Initialized (&mpi_initialized);
1382 
1383  if (mpi_initialized)
1384  {
1385  //MPI_Abort(m_fullComm->Comm(), 1);
1386  MPI_Abort(MPI_COMM_WORLD, 1);
1387  }
1388  else
1389  {
1390  // The system terminate_handler may do useful things like printing
1391  // uncaught exception information, or the user may have created
1392  // their own terminate handler that we want to call.
1394  }
1395  exit(1);
1396 }
1397 
1398 
1399 //-------------------------------------------------------
1400 void
1402 {
1403  std::ifstream* ifs = new std::ifstream(m_optionsInputFileName.c_str());
1404  if (ifs->is_open()) {
1405  //ifs->close();
1406  delete ifs;
1407  }
1408  else {
1409  if (m_fullRank == 0) std::cout << "An invalid input file has been passed to the 'environment' class constructor!"
1410  << ": name of file is '" << m_optionsInputFileName.c_str() << "'"
1411  << std::endl;
1412 
1413  if (m_fullRank == 0) std::cout << "\nThis is a help message of the QUESO library."
1414  << "\nAn application using the QUESO library shall be executed by typing"
1415  << "\n '<eventual mpi commands and options> <Application> <InputFile>'"
1416  << "\nin the command line."
1417  << "\n"
1418  << std::endl;
1419  queso_error();
1420  }
1421 
1422  return;
1423 }
1424 
1425 } // End namespace QUESO
#define QUESO_TRILINOS_DIR
Definition: queso.h:52
MPI_Comm RawType_MPI_Comm
Definition: MpiComm.h:38
unsigned int displayVerbosity() const
Definition: Environment.C:396
const MpiComm & subComm() const
Access function for MpiComm sub communicator.
Definition: Environment.C:247
#define QUESO_MAJOR_VERSION
Definition: queso.h:34
void print(std::ostream &os) const
Sends the environment options to the stream.
Definition: Environment.C:1372
BasicPdfsBase * m_basicPdfs
Definition: Environment.h:379
int subRank() const
Access function for sub-rank.
Definition: Environment.C:241
boost::program_options::variables_map * m_allOptionsMap
Definition: Environment.h:361
void setOptionsInputFileAccessState(bool newState) const
Definition: Environment.C:318
bool exceptionalCircumstance() const
Decides whether there is an exceptional circumstance.
Definition: Environment.C:1078
int MyPID() const
Return my process ID.
Definition: MpiComm.C:94
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:345
int seed() const
Access to the RNG seed.
Definition: Environment.C:423
#define UQ_FILE_EXTENSION_FOR_HDF_FORMAT
Definition: Defines.h:90
std::string m_optionsInputFileName
Definition: Environment.h:358
FilePtrSetStruct()
Struct constructor.
Definition: Environment.C:111
#define QUESO_BUILD_VERSION
Definition: queso.h:42
std::terminate_handler old_terminate_handler
Definition: Environment.C:126
void Barrier() const
Pause every process in *this communicator until all the processes reach this point.
Definition: MpiComm.C:122
#define QUESO_BUILD_HOST
Definition: queso.h:40
int NumProc() const
Returns total number of processes.
Definition: MpiComm.C:103
~FilePtrSetStruct()
Destructor.
Definition: Environment.C:118
TODO: Base class for basic PDFs using Boost library.
std::ofstream * ofsVar
Provides a stream interface to write data to files.
Definition: Environment.h:81
int fullRank() const
Returns the process full rank.
Definition: Environment.C:222
#define QUESO_CXXFLAGS
Definition: queso.h:48
unsigned int m_checkingLevel
Checking level.
#define queso_require_not_equal_to_msg(expr1, expr2, msg)
Definition: asserts.h:86
Struct for handling data input and output from files.
Definition: Environment.h:72
EmptyEnvironment()
Default constructor. Does nothing.
Definition: Environment.C:1087
std::string identifyingString() const
Access function to private attribute m_identifyingString: identifying string.
Definition: Environment.C:448
int m_seed
Seed of the random number generator.
void readOptionsInputFile()
Checks the options input file and reads the options.
Definition: Environment.C:1401
RawType_MPI_Group subGroup() const
Access function for sub-group.
Definition: Environment.C:235
#define QUESO_GLPK_DIR
Definition: queso.h:55
#define queso_error_msg(msg)
Definition: asserts.h:47
const MpiComm & fullComm() const
Access function for MpiComm full communicator.
Definition: Environment.C:228
This class provides a suite options one can pass to a QUESO environment.
int seed() const
Sets the seed.
Definition: RngBase.C:43
void QUESO_version_print(std::ostream &os)
Definition: Environment.C:49
unsigned int m_syncVerbosity
Synchronized verbosity.
unsigned int syncVerbosity() const
Access function to private attribute m_syncVerbosity.
Definition: Environment.C:403
#define QUESO_LIB_VERSION
Definition: queso.h:44
EnvOptionsValues * m_optionsObj
Definition: Environment.h:383
unsigned int numSubEnvironments() const
Access function to the number of sub-environments.
Definition: Environment.C:288
unsigned int m_displayVerbosity
Verbosity.
boost::program_options::variables_map & allOptionsMap() const
Definition: Environment.C:336
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:301
std::string m_subDisplayFileName
Output filename for sub-screen writing.
int inter0Rank() const
Returns the process inter0 rank.
Definition: Environment.C:261
int QUESO_get_numeric_version()
Definition: Environment.C:79
#define QUESO_MICRO_VERSION
Definition: queso.h:36
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:666
The QUESO MPI Communicator Class.
Definition: MpiComm.h:75
virtual ~BaseEnvironment()
Destructor.
Definition: Environment.C:161
FullEnvironment(RawType_MPI_Comm inputComm, const char *passedOptionsInputFileName, const char *prefix, EnvOptionsValues *alternativeOptionsValues)
Default constructor.
Definition: Environment.C:1107
void closeFile(FilePtrSetStruct &filePtrSet, const std::string &fileType) const
Closes the file.
Definition: Environment.C:1020
#define queso_require_equal_to_msg(expr1, expr2, msg)
Definition: asserts.h:85
#define QUESO_CXX
Definition: queso.h:47
std::string m_subIdString
Definition: Environment.h:364
~FullEnvironment()
Destructor.
Definition: Environment.C:1367
std::string optionsInputFileName() const
Access to the attribute m_optionsInputFileName, which stores the name of the input file passed by the...
Definition: Environment.C:307
const MpiComm & selfComm() const
Access function for MpiComm self-communicator.
Definition: Environment.C:254
bool fullEnvIsReady() const
Returns whether the full environment class is ready (constructor has successfully been called)...
Definition: Environment.C:210
#define queso_require_msg(asserted, msg)
Definition: asserts.h:69
#define queso_error()
Definition: asserts.h:53
Class for random number generation (base class for either GSL or Boost RNG).
Definition: RngBase.h:45
std::ofstream * subDisplayFile() const
Access function for m_subDisplayFile (displays file on stream).
Definition: Environment.C:274
#define QUESO_BUILD_USER
Definition: queso.h:38
RawType_MPI_Group m_fullGroup
Definition: Environment.h:356
~EmptyEnvironment()
Destructor.
Definition: Environment.C:1093
int CheckFilePath(const char *path)
#define QUESO_BUILD_ARCH
Definition: queso.h:39
RawType_MPI_Comm Comm() const
Extract MPI Communicator from a MpiComm object.
Definition: MpiComm.C:85
This (virtual) class sets up the environment underlying the use of the QUESO library by an executable...
Definition: Environment.h:193
unsigned int m_subId
Definition: Environment.h:363
void setExceptionalCircumstance(bool value) const
Set an exceptional circumstance.
Definition: Environment.C:1071
bool m_subDisplayAllowAll
Allows (or not) all sub-environments to write to output file.
#define UQ_FILE_EXTENSION_FOR_MATLAB_FORMAT
Definition: Defines.h:89
std::set< unsigned int > m_subDisplayAllowedSet
Sub-environments that will write to output.
boost::program_options::options_description * m_allOptionsDesc
Definition: Environment.h:360
unsigned int subId() const
Access function to the number of each sub-environment Id: m_subId.
Definition: Environment.C:295
void resetSeed(int newSeedOption)
Reset RNG seed.
Definition: Environment.C:429
TODO: Base class for basic PDFs (via either GSL or Boost).
Definition: BasicPdfsBase.h:44
virtual void resetSeed(int newSeed)
Resets the seed with value newSeed.
Definition: RngBase.C:49
#define QUESO_GRVY_DIR
Definition: queso.h:54
std::string platformName() const
Access to the platform name.
Definition: Environment.C:442
#define QUESO_MINOR_VERSION
Definition: queso.h:35
const MpiComm & inter0Comm() const
Access function for MpiComm inter0-communicator.
Definition: Environment.C:267
#define queso_deprecated()
Definition: Defines.h:120
struct timeval m_timevalBegin
Definition: Environment.h:380
std::ofstream * m_subDisplayFile
Definition: Environment.h:377
const BasicPdfsBase * basicPdfs() const
Access to Basic PDFs.
Definition: Environment.C:436
RawType_MPI_Group m_inter0Group
Definition: Environment.h:372
#define RawValue_MPI_COMM_SELF
Definition: MpiComm.h:43
const RngBase * rngObject() const
Access to the RNG object.
Definition: Environment.C:417
std::string m_rngType
Type of the random number generator.
bool openOutputFile(const std::string &fileName, const std::string &fileType, const std::set< unsigned int > &allowedSubEnvIds, bool writeOver, FilePtrSetStruct &filePtrSet) const
Opens an output file for each sub-environment that was chosen to send data to the file...
Definition: Environment.C:467
#define queso_require_greater_equal_msg(expr1, expr2, msg)
Definition: asserts.h:90
std::ifstream * ifsVar
Provides a stream interface to read data from files.
Definition: Environment.h:84
unsigned int checkingLevel() const
Access function to private attribute m_checkingLevel.
Definition: Environment.C:410
std::string m_platformName
Platform name.
std::string subDisplayFileName() const
Access function for m_subDisplayFileName (displays filename on stream).
Definition: Environment.C:280
std::string m_identifyingString
Identifying string.
int worldRank() const
Returns the process world rank.
Definition: Environment.C:216
bool m_subDisplayAllowInter0
Allows (or not) all inter0 nodes to write to output file.
TODO: Base class for basic PDFs using Gsl library.
Definition: BasicPdfsGsl.h:43
#define QUESO_LIB_RELEASE
Definition: queso.h:45
#define UQ_ENV_FILENAME_FOR_NO_INPUT_FILE
void resetIdentifyingString(const std::string &newString)
Reset private attribute m_identifyingString with the value newString.
Definition: Environment.C:454
#define QUESO_GSL_DIR
Definition: queso.h:53
RawType_MPI_Group m_subGroup
Definition: Environment.h:365
BaseEnvironment(const char *passedOptionsInputFileName, EnvOptionsValues *alternativeOptionsValues)
Default constructor.
Definition: Environment.C:132
#define QUESO_HDF5_DIR
Definition: queso.h:56
void queso_terminate_handler()
Function for unhandled exceptions in Queso.
Definition: Environment.C:1378
#define QUESO_BUILD_DATE
Definition: queso.h:41
bool openUnifiedInputFile(const std::string &fileName, const std::string &fileType, FilePtrSetStruct &filePtrSet) const
Opens the unified input file.
Definition: Environment.C:928
void print(std::ostream &os) const
Definition: Environment.C:1098
#define UQ_ENV_FILENAME_FOR_NO_OUTPUT_FILE
bool openInputFile(const std::string &fileName, const std::string &fileType, const std::set< unsigned int > &allowedSubEnvIds, FilePtrSetStruct &filePtrSet) const
Opens an input file.
Definition: Environment.C:834
MPI_Group RawType_MPI_Group
Definition: MpiComm.h:39

Generated on Thu Jun 11 2015 13:52:31 for queso-0.53.0 by  doxygen 1.8.5