queso-0.51.1
EnvironmentOptions.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,2009,2010,2011,2012,2013 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/EnvironmentOptions.h>
26 #include <queso/Miscellaneous.h>
27 
28 #include <queso/asserts.h>
29 
30 namespace QUESO {
31 
32 // --------------------------------------------------
33 // EnvOptionsValues --------------------------
34 // --------------------------------------------------
35 
36 // Default constructor ------------------------------
38  :
39  m_numSubEnvironments (UQ_ENV_NUM_SUB_ENVIRONMENTS_ODV),
40  m_subDisplayFileName (UQ_ENV_SUB_DISPLAY_FILE_NAME_ODV),
41  m_subDisplayAllowAll (UQ_ENV_SUB_DISPLAY_ALLOW_ALL_ODV),
42  m_subDisplayAllowInter0(UQ_ENV_SUB_DISPLAY_ALLOW_INTER0_ODV),
43 //m_subDisplayAllowedSet (),
44  m_displayVerbosity (UQ_ENV_DISPLAY_VERBOSITY_ODV),
45  m_syncVerbosity (UQ_ENV_SYNC_VERBOSITY_ODV),
46  m_checkingLevel (UQ_ENV_CHECKING_LEVEL_ODV),
47  m_rngType (UQ_ENV_RNG_TYPE_ODV),
48  m_seed (UQ_ENV_SEED_ODV),
49  m_platformName (UQ_ENV_PLATFORM_NAME_ODV),
50  m_identifyingString (UQ_ENV_IDENTIFYING_STRING_ODV),
51  m_numDebugParams (UQ_ENV_NUM_DEBUG_PARAMS_ODV),
52  m_debugParams (m_numDebugParams,0.)
53 {
54 }
55 
56 // Copy constructor ---------------------------------
58 {
59  this->copy(src);
60 }
61 
62 // Destructor ---------------------------------------
64 {
65 }
66 
67 // Set methods---------------------------------------
70 {
71  this->copy(rhs);
72  return *this;
73 }
74 // Private methods-----------------------------------
75 void
77 {
86  m_rngType = src.m_rngType;
87  m_seed = src.m_seed;
92 
93  return;
94 }
95 
96 // --------------------------------------------------
97 // EnvironmentOptions ------------------------
98 // --------------------------------------------------
99 
100 // Default constructor ------------------------------
102  const BaseEnvironment& env,
103  const char* prefix)
104  :
105  m_ov (),
106  m_env (env),
107  m_prefix ((std::string)(prefix) + "env_"),
108  m_optionsDesc (new po::options_description("Environment options")),
109  m_option_help (m_prefix + "help" ),
110  m_option_numSubEnvironments (m_prefix + "numSubEnvironments" ),
111  m_option_subDisplayFileName (m_prefix + "subDisplayFileName" ),
112  m_option_subDisplayAllowAll (m_prefix + "subDisplayAllowAll" ),
113  m_option_subDisplayAllowInter0(m_prefix + "subDisplayAllowInter0"),
114  m_option_subDisplayAllowedSet (m_prefix + "subDisplayAllowedSet" ),
115  m_option_displayVerbosity (m_prefix + "displayVerbosity" ),
116  m_option_syncVerbosity (m_prefix + "syncVerbosity" ),
117  m_option_checkingLevel (m_prefix + "checkingLevel" ),
118  m_option_rngType (m_prefix + "rngType" ),
119  m_option_seed (m_prefix + "seed" ),
120  m_option_platformName (m_prefix + "platformName" ),
121  m_option_identifyingString (m_prefix + "identifyingString" )
122 {
124  m_env.worldRank(),
125  "EnvironmentOptions::constructor(1)",
126  "this constructor is incompatible with the abscense of an options input file");
127 }
128 // Constructor with alternative values --------------
130  const BaseEnvironment& env,
131  const char* prefix,
132  const EnvOptionsValues& alternativeOptionsValues)
133  :
134  m_ov (alternativeOptionsValues),
135  m_env (env),
136  m_prefix ((std::string)(prefix) + "env_"),
137  m_optionsDesc (NULL),
138  m_option_help (m_prefix + "help" ),
139  m_option_numSubEnvironments (m_prefix + "numSubEnvironments" ),
140  m_option_subDisplayFileName (m_prefix + "subDisplayFileName" ),
141  m_option_subDisplayAllowAll (m_prefix + "subDisplayAllowAll" ),
142  m_option_subDisplayAllowInter0(m_prefix + "subDisplayAllowInter0"),
143  m_option_subDisplayAllowedSet (m_prefix + "subDisplayAllowedSet" ),
144  m_option_displayVerbosity (m_prefix + "displayVerbosity" ),
145  m_option_syncVerbosity (m_prefix + "syncVerbosity" ),
146  m_option_checkingLevel (m_prefix + "checkingLevel" ),
147  m_option_rngType (m_prefix + "rngType" ),
148  m_option_seed (m_prefix + "seed" ),
149  m_option_platformName (m_prefix + "platformName" ),
150  m_option_identifyingString (m_prefix + "identifyingString" )
151 {
153  m_env.worldRank(),
154  "EnvironmentOptions::constructor(2)",
155  "this constructor is incompatible with the existence of an options input file");
156 
157  if (m_env.subDisplayFile() != NULL) {
158  *m_env.subDisplayFile() << "In EnvironmentOptions::constructor(2)"
159  << ": after setting values of options with prefix '" << m_prefix
160  << "', state of object is:"
161  << "\n" << *this
162  << std::endl;
163  }
164 }
165 // Destructor ---------------------------------------
167 {
168  if (m_optionsDesc) delete m_optionsDesc;
169 }
170 
171 // I/O methods---------------------------------------
172 void
174 {
176  m_env.worldRank(),
177  "EnvironmentOptions::scanOptionsValues()",
178  "m_optionsDesc variable is NULL");
182 
183  // 'm_subDisplayOutputFile' is still not available at this moment. Use 'std::cout'
184  //if (m_env.subScreenFile() != NULL) {
185  // *m_env.subScreenFile()
186  if ((m_env.fullRank() == 0) && (m_env.displayVerbosity() >= 3)) {
187  std::cout << "In EnvironmentOptions::scanOptionsValues()"
188  << ": after reading values of options with prefix '" << m_prefix
189  << "', state of object is:"
190  << "\n" << *this
191  << std::endl;
192  }
193 
194  return;
195 }
196 // --------------------------------------------------
197 void
198 EnvironmentOptions::print(std::ostream& os) const
199 {
203  //<< "\n" << m_option_subDisplayAllowInter0 << " = " << m_ov.m_subDisplayAllowInter0
204  << "\n" << m_option_subDisplayAllowedSet << " = ";
205  for (std::set<unsigned int>::iterator setIt = m_ov.m_subDisplayAllowedSet.begin(); setIt != m_ov.m_subDisplayAllowedSet.end(); ++setIt) {
206  os << *setIt << " ";
207  }
208  os << "\n" << m_option_displayVerbosity << " = " << m_ov.m_displayVerbosity
209  << "\n" << m_option_syncVerbosity << " = " << m_ov.m_syncVerbosity
210  << "\n" << m_option_checkingLevel << " = " << m_ov.m_checkingLevel
211  << "\n" << m_option_rngType << " = " << m_ov.m_rngType
212  << "\n" << m_option_seed << " = " << m_ov.m_seed
213  << "\n" << m_option_platformName << " = " << m_ov.m_platformName
215  //<< "\n" << m_option_numDebugParams << " = " << m_ov.m_numDebugParams
216  << std::endl;
217  return;
218 }
219 
220 // Private methods ----------------------------------
221 void
222 EnvironmentOptions::defineMyOptions(po::options_description& optionsDesc) const
223 {
224 #ifdef QUESO_MEMORY_DEBUGGING
225  std::cout << "In EnvOptions::defineMyOptions(), before add_options()" << std::endl;
226 #endif
227  optionsDesc.add_options()
228  (m_option_help.c_str(), "produce help message for environment" )
229  (m_option_numSubEnvironments.c_str(), po::value<unsigned int>()->default_value(UQ_ENV_NUM_SUB_ENVIRONMENTS_ODV), "number of subEnvironments" )
230  (m_option_subDisplayFileName.c_str(), po::value<std::string >()->default_value(UQ_ENV_SUB_DISPLAY_FILE_NAME_ODV), "output filename for subscreen writing" )
231  (m_option_subDisplayAllowAll.c_str(), po::value<bool >()->default_value(UQ_ENV_SUB_DISPLAY_ALLOW_ALL_ODV), "Allow all processors to write to output file" )
232  (m_option_subDisplayAllowInter0.c_str(), po::value<bool >()->default_value(UQ_ENV_SUB_DISPLAY_ALLOW_INTER0_ODV), "Allow all inter0 nodes to write to output file")
233  (m_option_subDisplayAllowedSet.c_str(), po::value<std::string >()->default_value(UQ_ENV_SUB_DISPLAY_ALLOWED_SET_ODV), "subEnvs that will write to output file" )
234  (m_option_displayVerbosity.c_str(), po::value<unsigned int>()->default_value(UQ_ENV_DISPLAY_VERBOSITY_ODV), "set verbosity" )
235  (m_option_syncVerbosity.c_str(), po::value<unsigned int>()->default_value(UQ_ENV_SYNC_VERBOSITY_ODV), "set sync verbosity" )
236  (m_option_checkingLevel.c_str(), po::value<unsigned int>()->default_value(UQ_ENV_CHECKING_LEVEL_ODV), "set checking level" )
237  (m_option_rngType.c_str(), po::value<std::string >()->default_value(UQ_ENV_RNG_TYPE_ODV), "set rngType" )
238  (m_option_seed.c_str(), po::value<int >()->default_value(UQ_ENV_SEED_ODV), "set seed" )
239  (m_option_platformName.c_str(), po::value<std::string >()->default_value(UQ_ENV_PLATFORM_NAME_ODV), "platform name" )
240  (m_option_identifyingString.c_str(), po::value<std::string >()->default_value(UQ_ENV_IDENTIFYING_STRING_ODV), "identifying string" )
241  //(m_option_numDebugParams.c_str(), po::value<unsigned int>()->default_value(UQ_ENV_NUM_DEBUG_PARAMS_ODV), "set number of debug parameters" )
242  ;
243 #ifdef QUESO_MEMORY_DEBUGGING
244  std::cout << "In EnvOptions::defineMyOptions(), after add_options()" << std::endl;
245 #endif
246 
247  return;
248 }
249 // --------------------------------------------------
250 void
251 EnvironmentOptions::getMyOptionValues(po::options_description& optionsDesc)
252 {
253 #ifdef QUESO_MEMORY_DEBUGGING
254  std::cout << "Entering EnvOptions::getMyOptionsValues()" << std::endl;
255 #endif
256  if (m_env.allOptionsMap().count(m_option_help.c_str())) {
257  // 'm_subDisplayOutputFile' is still not available at this moment. Use 'std::cout'
258  if (m_env.fullRank() == 0) std::cout << optionsDesc
259  << std::endl;
260  }
261 
262  if (m_env.allOptionsMap().count(m_option_numSubEnvironments.c_str())) {
264  }
266  std::cerr << "In BaseEnvironment::getMyOptionValues()"
267  << ": m_env.fullComm().NumProc() = " << m_env.fullComm().NumProc()
268  << ", m_numSubEnvironments = " << m_ov.m_numSubEnvironments
269  << std::endl;
270  }
272  m_env.worldRank(),
273  "BaseEnvironment::getMyOptionValues()",
274  "total number of processors in environment must be multiple of the specified number of subEnvironments");
275 
276  if (m_env.allOptionsMap().count(m_option_subDisplayFileName.c_str())) {
278  }
279 
280  if (m_env.allOptionsMap().count(m_option_subDisplayAllowAll.c_str())) {
282  }
283 
284  if (m_env.allOptionsMap().count(m_option_subDisplayAllowInter0.c_str())) {
286  }
287 
290  // The line below is commented because 'm_subId' is not set at this point yet
291  //m_subDisplayAllowedSet.insert((unsigned int) m_subId);
292  }
293  else if (m_ov.m_subDisplayAllowInter0) {
295  }
296  else if (m_env.allOptionsMap().count(m_option_subDisplayAllowedSet.c_str())) {
298  std::vector<double> tmpAllow(0,0.);
299  std::string inputString = m_env.allOptionsMap()[m_option_subDisplayAllowedSet].as<std::string>();
300  MiscReadDoublesFromString(inputString,tmpAllow);
301  //if (m_subDisplayOutputFile) {
302  // *m_subDisplayOutputFile << "In EnvironmentOptions::getMyOptionValues(): allow = ";
303  // for (unsigned int i = 0; i < tmpAllow.size(); ++i) {
304  // *m_subDisplayOutputFile << " " << tmpAllow[i];
305  // }
306  // *m_subDisplayOutputFile << std::endl;
307  //}
308 
309  if (tmpAllow.size() > 0) {
310  for (unsigned int i = 0; i < tmpAllow.size(); ++i) {
311  m_ov.m_subDisplayAllowedSet.insert((unsigned int) tmpAllow[i]);
312  }
313  }
314  }
315 
316  if (m_env.allOptionsMap().count(m_option_displayVerbosity.c_str())) {
318  }
319 
320  if (m_env.allOptionsMap().count(m_option_syncVerbosity.c_str())) {
322  }
323 
324  if (m_env.allOptionsMap().count(m_option_checkingLevel.c_str())) {
326  }
327 
328  if (m_env.allOptionsMap().count(m_option_rngType.c_str())) {
329  m_ov.m_rngType = m_env.allOptionsMap()[m_option_rngType].as<std::string>();
330  }
331 
332  if (m_env.allOptionsMap().count(m_option_seed.c_str())) {
334  }
335 
336  if (m_env.allOptionsMap().count(m_option_platformName.c_str())) {
338  }
339 
340  if (m_env.allOptionsMap().count(m_option_identifyingString.c_str())) {
342  }
343 
344  //if (m_env.allOptionsMap().count(m_option_numDebugParams.c_str())) {
345  // m_numDebugParams = m_env.allOptionsMap()[m_option_numDebugParams].as<unsigned int>();
346  //}
347 
348 #ifdef QUESO_MEMORY_DEBUGGING
349  std::cout << "Leaving EnvOptions::getMyOptionsValues()" << std::endl;
350 #endif
351 
352  return;
353 }
354 
355 // Operator outside class definition ----------------
356 std::ostream& operator<<(std::ostream& os, const EnvironmentOptions& obj)
357 {
358  obj.print(os);
359 
360  return os;
361 }
362 
363 } // End namespace QUESO
#define UQ_ENV_CHECKING_LEVEL_ODV
void copy(const EnvOptionsValues &src)
Makes an exact copy of an existing EnvOptionsValues instance.
std::string m_platformName
Platform name.
Definition: Defines.h:160
#define UQ_ENV_SUB_DISPLAY_ALLOW_ALL_ODV
#define UQ_ENV_PLATFORM_NAME_ODV
#define UQ_ENV_IDENTIFYING_STRING_ODV
void scanOptionsValues()
Scans option values from input file.
void print(std::ostream &os) const
Print values of the options chosen.
int worldRank() const
Returns the process world rank.
Definition: Environment.C:235
std::string m_option_rngType
Type of the random number generator.
int NumProc() const
Returns total number of processes.
Definition: MpiComm.C:121
unsigned int m_numDebugParams
Number of debug parameters.
Definition: Defines.h:166
std::ofstream * subDisplayFile() const
Access function for m_subDisplayFile (displays file on stream).
Definition: Environment.C:305
#define UQ_ENV_NUM_SUB_ENVIRONMENTS_ODV
void defineMyOptions(po::options_description &optionsDesc) const
Define my environment options as the default options.
const MpiComm & fullComm() const
Access function for MpiComm full communicator.
Definition: Environment.C:247
po::variables_map & allOptionsMap() const
Definition: Environment.C:368
const BaseEnvironment & m_env
Environment.
This (virtual) class sets up the environment underlying the use of the QUESO library by an executable...
Definition: Environment.h:187
std::string m_option_subDisplayAllowedSet
Sub-environments that will write to output.
bool m_subDisplayAllowAll
Allows (or not) all sub-environments to write to output file.
Definition: Defines.h:134
std::ostream & operator<<(std::ostream &os, const BaseEnvironment &obj)
bool m_subDisplayAllowInter0
Allows (or not) all inter0 nodes to write to output file.
Definition: Defines.h:137
void MiscReadDoublesFromString(const std::string &inputString, std::vector< double > &outputDoubles)
Definition: Miscellaneous.C:39
std::string m_prefix
Options prefix.
std::string optionsInputFileName() const
Access to the attribute m_optionsInputFileName, which stores the name of the input file passed by the...
Definition: Environment.C:341
#define UQ_ENV_NUM_DEBUG_PARAMS_ODV
unsigned int m_numSubEnvironments
Number of sub-environments.
Definition: Defines.h:128
po::options_description * m_optionsDesc
Environment options description.
EnvOptionsValues()
Default constructor.
std::string m_option_numSubEnvironments
My number of sub-environments.
std::string m_option_checkingLevel
Checking level.
int m_seed
Seed of the random number generator.
Definition: Defines.h:157
std::string m_option_platformName
Platform name.
std::string m_option_identifyingString
Identifying string.
EnvironmentOptions(const BaseEnvironment &env, const char *prefix)
Default constructor.
unsigned int m_syncVerbosity
Synchronized verbosity.
Definition: Defines.h:146
std::string m_option_subDisplayFileName
My output filename for sub-screen writing.
std::string m_option_displayVerbosity
Verbosity.
#define UQ_ENV_SUB_DISPLAY_ALLOWED_SET_ODV
int fullRank() const
Returns the process full rank.
Definition: Environment.C:241
std::string m_option_subDisplayAllowInter0
Allows (or not) all inter0 nodes to write to output file.
std::string m_option_subDisplayAllowAll
Allows (or not) all sub-environments to write to output file.
This class provides a suite options one can pass to a QUESO environment.
Definition: Defines.h:105
#define UQ_ENV_RNG_TYPE_ODV
void getMyOptionValues(po::options_description &optionsDesc)
Gets the option values of the environment.
std::set< unsigned int > m_subDisplayAllowedSet
Sub-environments that will write to output.
Definition: Defines.h:140
#define UQ_ENV_SYNC_VERBOSITY_ODV
EnvOptionsValues & operator=(const EnvOptionsValues &rhs)
Operator for copying the options of an environment.
std::string m_option_seed
Seed of the random number generator.
unsigned int m_checkingLevel
Checking level.
Definition: Defines.h:149
std::string m_option_syncVerbosity
Synchronized verbosity.
unsigned int displayVerbosity() const
Definition: Environment.C:436
#define UQ_ENV_SUB_DISPLAY_ALLOW_INTER0_ODV
#define UQ_FATAL_TEST_MACRO(test, givenRank, where, what)
Definition: Defines.h:223
This class reads options one can pass to a QUESO environment through an input file.
std::string m_rngType
Type of the random number generator.
Definition: Defines.h:152
unsigned int m_displayVerbosity
Verbosity.
Definition: Defines.h:143
std::string m_subDisplayFileName
Output filename for sub-screen writing.
Definition: Defines.h:131
std::string m_identifyingString
Identifying string.
Definition: Defines.h:163
#define UQ_ENV_DISPLAY_VERBOSITY_ODV
EnvOptionsValues m_ov
Instance of EnvOptionsValues, a class with default values for QUESO environment.
#define UQ_ENV_SEED_ODV
void scanInputFileForMyOptions(const po::options_description &optionsDesc) const
This method scans the input file provided by the user to QUESO.
Definition: Environment.C:378
std::vector< double > m_debugParams
Debug parameters.
Definition: Defines.h:169
#define UQ_ENV_SUB_DISPLAY_FILE_NAME_ODV

Generated on Thu Apr 23 2015 19:26:15 for queso-0.51.1 by  doxygen 1.8.5