Sierra Toolkit  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Env.cpp
1 
10 #include <pwd.h>
11 #include <unistd.h>
12 
13 #include <ostream>
14 #include <fstream>
15 #include <sstream>
16 #include <string>
17 #include <cstring>
18 #include <cstdlib>
19 #include <stdexcept>
20 #include <numeric>
21 #include <iomanip>
22 #include <algorithm>
23 #include <locale>
24 #include <map>
25 
26 #include <stk_util/util/Null_Streambuf.hpp>
27 #include <stk_util/parallel/mpi_filebuf.hpp>
28 
29 #include <stk_util/diag/Timer.hpp>
30 #include <stk_util/diag/Writer.hpp>
31 #include <stk_util/diag/WriterRegistry.hpp>
32 #include <stk_util/diag/Env.hpp>
33 #include <stk_util/diag/Platform.hpp>
34 #include <stk_util/diag/Signal.hpp>
36 #include <stk_util/parallel/ExceptionReport.hpp>
37 #include <stk_util/parallel/MPI.hpp>
39 #include <stk_util/environment/ProductRegistry.hpp>
40 #include <stk_util/diag/StringUtil.hpp>
43 #include <stk_util/diag/PreParse.hpp>
44 
46 #include <stk_util/environment/ProgramOptions.hpp>
48 #include <stk_util/parallel/BroadcastArg.hpp>
49 #include <stk_util/parallel/ParallelReduce.hpp>
50 #include <stk_util/util/Bootstrap.hpp>
51 #include <stk_util/util/IndentStreambuf.hpp>
52 
53 namespace sierra {
54 namespace Env {
55 
56 namespace {
57 
58 void bootstrap()
59 {
60  // Add my command line options to the option descriptions.
61  boost::program_options::options_description desc("Runtime environment", 120);
62  desc.add_options()
63  ("help,h", "Display command line options")
64  ("directory,d", boost::program_options::value<std::string>()->default_value("./"), "Set working directory")
65  ("output-log,o", boost::program_options::value<std::string>()->default_value(""), "Output log file path, one of : 'cout', 'cerr', or a file path")
66  ("logfile,l", boost::program_options::value<std::string>()->default_value(""), "Output log file path, one of : 'cout', 'cerr', or a file path")
67  ("pout", boost::program_options::value<std::string>()->implicit_value("-"), "Per-processor log file path")
68  ("dout", boost::program_options::value<std::string>()->implicit_value("out"), "Diagnostic output stream one of: 'cout', 'cerr', 'out' or a file path")
69 // ("timer", boost::program_options::value<std::string>(), "Wall and CPU time options") // , &Diag::Timer::theTimerParser())
70  ("version", "Display version information")
71  ("jamsub", boost::program_options::value<std::string>(), "Display user subroutine build command")
72  ("runtest", boost::program_options::value<std::string>()->implicit_value("pid"), "Record process host and pid to this file")
73  ("developer-mode", "Activate developer specific features")
74  ("architecture", boost::program_options::value<std::string>(), "Specifies the architecture running the sierra application");
75 
76  stk::get_options_description().add(desc);
77 }
78 
79 stk::Bootstrap x(&bootstrap);
80 
81 struct EnvData
82 {
83  typedef std::map<ExecType, ExecInfo> ExecMap;
84 
85  static EnvData &instance() {
86  static EnvData s_env;
87 
88  return s_env;
89  }
90 
91  EnvData()
92  : m_productName("not specified"),
93  m_vm(stk::get_variables_map()),
94  m_nullBuf(),
95  m_outputNull(&m_nullBuf),
96  m_outputP0(&std::cout),
97  m_output(),
98  m_startTime((double) ::time(NULL)),
99  m_executablePath(),
100  m_shutdownRequested(false),
101  m_inputFileRequired(true),
102  m_checkSubCycle(false),
103  m_worldComm(MPI_COMM_NULL),
104  m_parallelComm(MPI_COMM_NULL),
105  m_parallelSize(-1),
106  m_parallelRank(-1),
107  m_emptyString(),
108  m_onString(PARAM_ON),
109  m_inputFile("")
110  {
111  m_execMap[EXEC_TYPE_LAG].m_master = -1;
112  m_execMap[EXEC_TYPE_LAG].m_groupComm = MPI_COMM_NULL;
113  m_execMap[EXEC_TYPE_FLUID].m_master = -1;
114  m_execMap[EXEC_TYPE_FLUID].m_groupComm = MPI_COMM_NULL;
115  stk::register_log_ostream(std::cout, "cout");
116  stk::register_log_ostream(std::cerr, "cerr");
117 
122 
123  static_cast<stk::indent_streambuf *>(sierra::dwout().rdbuf())->redirect(sierra::dout().rdbuf());
124  }
125 
126  ~EnvData()
127  {
128  static_cast<stk::indent_streambuf *>(sierra::dwout().rdbuf())->redirect(std::cout.rdbuf());
129 
134 
135  stk::unregister_log_ostream(std::cerr);
136  stk::unregister_log_ostream(std::cout);
137  }
138 
139  std::string m_productName;
140 
141  boost::program_options::variables_map & m_vm;
142 
143  null_streambuf m_nullBuf;
144  std::ostream m_outputNull;
145  std::ostream * m_outputP0;
146  std::ostringstream m_output;
147 
148  double m_startTime;
149  std::string m_executablePath;
150 
151  bool m_shutdownRequested;
152  bool m_inputFileRequired;
153  bool m_checkSubCycle;
154 
155  MPI_Comm m_worldComm;
156 
157  MPI_Comm m_parallelComm;
158  int m_parallelSize;
159  int m_parallelRank;
160 
161  ExecMap m_execMap;
162 
163  const std::string m_emptyString;
164  const std::string m_onString;
165 
166  std::string m_inputFile;
167 };
168 
169 } // namespace <unnamed>
170 
171 const std::string &
173 {
174  return EnvData::instance().m_productName;
175 }
176 
177 
178 const std::string &
180 {
181  return EnvData::instance().m_executablePath;
182 }
183 
184 
185 const std::string &
187 {
188  static std::string executable_date;
189 
190  if (executable_date.empty())
191  executable_date = ProductRegistry::instance().getProductAttribute(EnvData::instance().m_productName, ProductRegistry::BUILD_TIME);
192 
193  return executable_date;
194 }
195 
196 
197 const std::string &
199 {
200  static std::string startup_date;
201 
202  if (startup_date.empty())
203  startup_date = format_time(EnvData::instance().m_startTime).c_str();
204 
205  return startup_date;
206 }
207 
208 
209 double
211 {
212  return EnvData::instance().m_startTime;
213 }
214 
215 
216 bool
218 {
219  return !get_param("developer-mode").empty();
220 }
221 
222 
223 void setInputFileName(std::string name) {
224  EnvData::instance().m_inputFile = name;
225 }
226 
227 std::string getInputFileName() {
228  return EnvData::instance().m_inputFile;
229 }
230 
231 void set_input_file_required(bool value)
232 {
233  EnvData::instance().m_inputFileRequired = value;
234 }
235 
236 void set_check_subcycle(bool value)
237 {
238  EnvData::instance().m_checkSubCycle = value;
239 }
240 
241 
242 const std::string &
244 {
245  return get_param("architecture");
246 }
247 
248 
249 const std::string
251  char cwd[PATH_MAX];
252  std::string directory = get_param("directory");
253  if (directory[0] != '/' && getcwd(cwd, PATH_MAX) != NULL) {
254  directory = cwd;
255  directory += '/';
256  }
257  return directory;
258 }
259 
260 
261 std::ostream &
263 {
264  return EnvData::instance().m_output;
265 }
266 
267 
268 std::ostream &
270 {
271  return *EnvData::instance().m_outputP0;
272 }
273 
274 
275 std::ostream &
277  return EnvData::instance().m_outputNull;
278 }
279 
280 
281 const char *
283 {
284  static const char *s_sectionSeparator = "+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----";
285 
286  return s_sectionSeparator;
287 }
288 
289 
290 const char *
292 {
293  static const char *s_subsectionSeparator = "---------------------------------------------------";
294 
295  return s_subsectionSeparator;
296 }
297 
298 
299 std::string
301  const std::string & title)
302 {
303  static size_t s_sectionSeparatorLength = std::strlen(section_separator());
304 
305  std::ostringstream strout;
306 
307  strout << std::left << std::setw(s_sectionSeparatorLength - 20) << title << std::right << std::setw(20) << format_time(Env::wall_now());
308  return strout.str();
309 }
310 
311 
313  return EnvData::instance().m_parallelSize;
314 }
315 
317  return EnvData::instance().m_parallelRank;
318 }
319 
320 MPI_Comm
322 {
323  return EnvData::instance().m_parallelComm;
324 }
325 
326 MPI_Comm
328 {
329  return EnvData::instance().m_worldComm;
330 }
331 
333  return EnvData::instance().m_execMap[EXEC_TYPE_LAG].m_master;
334 }
335 
337  return EnvData::instance().m_execMap[EXEC_TYPE_FLUID].m_master;
338 }
339 
340 int peer_group() {
341  return EnvData::instance().m_execMap[EXEC_TYPE_PEER].m_master;
342 }
343 
344 std::string
345 get_program_path(const char *program)
346 {
347  // If we already have the full path, just return it
348  if (program[0] == '/')
349  return program;
350 
351  char full_path[PATH_MAX];
352  if (strchr(program, '/') != NULL) {
353  realpath(program, full_path);
354  return full_path;
355  }
356 
357  char *PATH = getenv("PATH");
358  while (PATH && *PATH) {
359  // Get the character past the end of the next directory in PATH, i.e.
360  // either the '/' or the '\0'
361  char *end = strchr(PATH, ':');
362  if (!end) {
363  end = PATH+strlen(PATH);
364  }
365 
366  // Set current = directory + '/' + program
367  strncpy(full_path, PATH, end-PATH);
368  full_path[end-PATH] = '/';
369  strcpy(&full_path[end-PATH+1], program);
370 
371  // Check whether possible exists
372  if (access(full_path, X_OK) == 0)
373  return full_path;
374 
375  // Advance to the next directory
376  PATH = *end ? end+1 : end;
377  }
378 
379  // Not found; this shouldn't happen, but maybe the executable got deleted
380  // after it was invoked before we got here -- or we have some crazy
381  // parallel machine where the executable is inaccessible on the compute
382  // nodes despite it somehow having been loaded. No big deal, just return
383  // the non-absolute path.
384  return program;
385 }
386 
387 void parse_options(MPI_Comm comm, int *argc, char ***argv);
388 void startup_multi_exec(MPI_Comm world_comm, ExecType my_executable_type, const std::vector<int> *peer_sizes);
389 
390 
391 
392 bool StartupSierra(int * argc,
393  char *** argv,
394  const char * product_name,
395  const char * build_time,
396  ExecType mpi_key,
397  const std::vector<int> *peer_sizes) {
398  bool returnValue = false;
399 
401 
402  EnvData &env_data = EnvData::instance();
403 
404  env_data.m_executablePath = get_program_path(*argv[0]);
405  env_data.m_productName = product_name;
406 
407  ProductRegistry::instance().setProductName(product_name);
408 
409  ProductRegistry::AttributeMap &product_attributes = ProductRegistry::instance().getProductAttributeMap(product_name);
410  product_attributes[ProductRegistry::BUILD_TIME] = build_time;
411  product_attributes[ProductRegistry::EXECUTABLE] = env_data.m_executablePath;
412 
413  // Add Utility runtime library to the product registry
414  sierra::register_product();
415 
416  // Add mpih to the product registry
417  sierra::mpih::register_product();
418 
419  // Add operating system information to the product registry.
420  ProductRegistry::AttributeMap &attr_map = ProductRegistry::instance().addProduct(osname().c_str());
421  attr_map[ProductRegistry::VERSION] = osversion().c_str();
422 
423  // Process the broadcast command line arguments
424  namespace opt = boost::program_options;
425 
426  opt::variables_map &vm = stk::get_variables_map();
427  opt::options_description &od = stk::get_options_description();
428  {
429  boost::program_options::options_description desc("Diagnostic writers", 120);
430 
431  for (Diag::WriterRegistry::iterator it = Diag::getWriterRegistry().begin(); it != Diag::getWriterRegistry().end(); ++it) {
432  std::ostringstream str;
433  str << "Diagnostic writer " << (*it).first << std::endl;
434  (*it).second.second->describe(str);
435  desc.add_options()((*it).first.c_str(), boost::program_options::value<std::string>(), str.str().c_str());
436  }
437 
438  std::ostringstream str;
439  str << "Wall and CPU time options" << std::endl;
440  Diag::theTimerParser().describe(str);
441  desc.add_options()("timer", boost::program_options::value<std::string>(), str.str().c_str());
442 
443  od.add(desc);
444  }
445 
446  for (int i = 0; i < *argc; ++i) {
447  const std::string s((*argv)[i]);
448  if (s == "-h" || s == "-help" || s == "--help") {
449  std::cout << std::endl
450  << "Sierra Usage: sierra " << lower(product_name) << " [sierra-options...] -O \"[" << lower(product_name) << "-options...]\"" << std::endl << std::endl
451 // << "Usage: (MPI run) " << env_data.m_executablePath << " [options...]" << std::endl
452  << "For example:" << std::endl
453  << "" << std::endl
454  << " sierra " << lower(product_name) << " -i input_deck.i -o sierra.log" << std::endl
455  << " This creates the normal output file sierra.log" << std::endl
456  << "" << std::endl
457  << " sierra " << lower(product_name) << " -i input_deck.i -o sierra.log -O \"--pout=pp.log\"" << std::endl
458  << " The per-processor output is written to pp.log.n.r for each rank, r, of n processors." << std::endl
459  << "" << std::endl
460  << " sierra " << lower(product_name) << " -i input_deck.i -o sierra.log -O \"--fmwkout=field,parameters\"" << std::endl
461  << " Enable the framework field and parameter diagnostics" << std::endl
462  << "" << std::endl
463  << " sierra " << lower(product_name) << " -i input_deck.i -o sierra.log -O \"--timer=all\"" << std::endl
464  << " Enable the all timers" << std::endl
465  << std::endl
466  << " For additional information see:" << std::endl
467  << " http://sierra-dev.sandia.gov/stk/group__stk__util__output__log__detail.html#stk_util_output_log_howto_use_in_sierra_app" << std::endl << std::endl
468  << product_name << " options are:" << std::endl
469  << stk::get_options_description() << std::endl;
470  std::exit(0);
471  }
472  }
473 
474  for (int i = 0; i < *argc; ++i) {
475  const std::string s((*argv)[i]);
476  if (s == "-jamsub" || s == "--jamsub") {
477  const char *t = (*argv)[i + 1];
478  const char **symbol = sierra::Plugin::Registry::getsym<const char **>(t);
479  if (symbol) {
480  std::cout << *symbol << std::endl;
481  std::exit(0);
482  }
483  else
484  std::exit(1);
485  }
486  }
487 
488  try {
490 
491  // Communicator has not been set, initialize MPI if not already initialized
492  int mpi_init_val = 0 ;
493  if ( MPI_SUCCESS != MPI_Initialized( &mpi_init_val ) ) {
494  throw RuntimeError() << "MPI_Initialized failed";
495  }
496 
497  // Default startup communicator
498  MPI_Comm startup_mpi_comm = MPI_COMM_WORLD;
499 
500  // If we are initializing the comm, see if there are differing
501  // executables running. If there are, find our partition and the
502  // leads of the other partitions.
503  if ( mpi_init_val == 0 ) {
504  if ( MPI_SUCCESS != MPI_Init( argc , argv ) ) {
505  throw RuntimeError() << "MPI_Init failed";
506  }
507 
508  returnValue = true ;
509 
510  if (mpi_key != EXEC_TYPE_WORLD) startup_multi_exec(startup_mpi_comm, mpi_key, peer_sizes);
511  }
512 
513  // Ready to reset the environment from NULL, we are the Lagrangian application at this point.
514  MPI_Comm new_comm = mpi_key != EXEC_TYPE_WORLD ? env_data.m_execMap[mpi_key].m_groupComm : MPI_COMM_WORLD;
515  reset(new_comm);
516  }
517  catch (const std::exception &x) {
518  std::cerr << "SIERRA execution failed during mpi initialization with the following exception:" << std::endl
519  << x.what() << std::endl;
520  MPI_Abort(env_data.m_parallelComm , MPI_ERR_OTHER);
521  }
522  catch (...) {
523  std::cerr << "SIERRA execution failed during mpi initialization with unknown exception:" << std::endl;
524 
525  MPI_Abort(env_data.m_parallelComm, MPI_ERR_OTHER);
526  }
527 
528  parse_options(env_data.m_parallelComm, argc, argv);
529 
530  {
531  std::ostringstream output_description;
532 
533  // On processor 0:
534  // [outfile=path] [poutfile=path.n.r] [doutfile=path.n.r] out>{-|cout|cerr|outfile}+pout pout>{null|poutfile} dout>{out|doutfile}
535 
536  // On processor 1..n:
537  // [poutfile=path.n.r] [doutfile=path.n.r] out>pout pout>{null|poutfile} dout>{out|doutfile}
538 
539  std::string out_path1 = vm["output-log"].as<std::string>();
540  std::string out_path2 = vm["logfile"].as<std::string>();
541 
542 
543 
544  std::string originalFileName = Env::get_param("input-deck");
545  std::string modifiedFileName = originalFileName;
546 
547  if(originalFileName == "") {
548  //
549  // If no input file specified, error out (unless just running the --version or --help option)
550  //
551  if ( get_param("version").empty() && get_param("help").empty() ) {
552  if (env_data.m_inputFileRequired) {
553  throw RuntimeError() << "No input file specified. An input file must be specified with the '-i' option";
554  } else {
555  std::cerr << "WARNING: No input file specified. An input file should be specified with the '-i' option!" << std::endl;
556  }
557  }
558  } else if ( env_data.m_checkSubCycle ) {
559  // Alter input-deck if subcycle present
560  bool debugSubCycleSplit = false;
561  std::string subCycleRegexp("^\\s*subcycle\\s+blocks\\s*=");
562  bool subCycleSet = CaseInSensitiveRegexInFile(subCycleRegexp, originalFileName, debugSubCycleSplit);
563  std::string coarseRegionRegexp("^\\s*begin\\s+presto\\s+region\\s+\\w+_AutoCoarseRegion\\>");
564  bool coarseRegionMade = CaseInSensitiveRegexInFile( coarseRegionRegexp, originalFileName, debugSubCycleSplit);
565  std::string fineRegionRegexp("^\\s*begin\\s+presto\\s+region\\s+\\w+_AutoFineRegion\\>");
566  bool fineRegionMade = CaseInSensitiveRegexInFile( fineRegionRegexp, originalFileName, debugSubCycleSplit);
567  if ( subCycleSet ) {
568  if ( !coarseRegionMade && !fineRegionMade ) {
569  modifiedFileName = CreateSubCycleInputFile( originalFileName );
570  } else {
571  if(Env::parallel_rank() == 0) {
572  std::cout<<"Input File: " << originalFileName << " Appears to have already been converted for subcycling. ";
573  std::cout<<"Skipping input conversion " << std::endl;
574  }
575  }
576  }
577  }
578 
579  setInputFileName(modifiedFileName);
580 
581 
582  std::string trueOut;
583  if(out_path2 != "") {
584  trueOut = out_path2;
585  } else if(out_path1 != "") {
586  //
587  // Old syntax compatibility, access the old output-file executable option if the logfile is not defined
588  //
589  trueOut = out_path1;
590  } else {
591  //
592  // If log file name is unspecified, default it to (Base Input File Name).log
593  // Use the following logic:
594  // If the input file has an extension, replace the last ".extension" with ".log"
595  // If the input file has no extension, append ".log" to the input file name
596  // If the input file contains the word '.aprepro', assume aprepro was used to convert and strip out the aprepro
597  // If the input file contains any directory movement (like ../) strip them out so log file is written to current director
598  //
599 
600  int dotPos = originalFileName.rfind(".");
601 
602  if(dotPos == -1) { //No extension
603  trueOut = originalFileName + ".log";
604  } else { //Extension found
605  trueOut = originalFileName.substr(0, dotPos) + ".log";
606  }
607  //
608  // If the output path contains a ".aprepro" tag get rid of it
609  //
610  int apreproPos = trueOut.rfind(".aprepro");
611  if(apreproPos != -1) {
612  trueOut.erase(apreproPos, 8);
613  }
614  //
615  // If the output path contains a "aaa/input.i" pull off the initial directory redirects so that the log file is written int the current directory
616  //
617  int lastSlashPos = trueOut.rfind("/");
618 
619  if(lastSlashPos != -1) {
620  trueOut.erase(0,lastSlashPos+1);
621  }
622 
623 
624  }
625 
626  std::string out_path = trueOut;
627 
628  if (out_path == "-")
629  out_path = "cout";
630 
631  std::string out_ostream;
632 
633  if (!stk::get_log_ostream(out_path))
634  if (out_path.size() && out_path[0] != '/')
635  out_path = working_directory() + out_path;
636 
637  if (parallel_rank() == 0) {
638  if (!stk::get_log_ostream(out_path)) {
639  output_description << "outfile=\"" << out_path << "\"";
640  out_ostream = "outfile";
641  }
642  else {
643  out_ostream = out_path;
644  }
645  }
646  else
647  out_ostream = "null";
648 
649  std::string pout_ostream = "null";
650  if (vm.count("pout")) {
651  std::string pout_path = vm["pout"].as<std::string>();
652  if (pout_path == "-") {
653  std::ostringstream s;
654 
655  if (stk::get_log_ostream(out_path))
656  s << working_directory() << "sierra.log." << parallel_size() << "." << parallel_rank();
657  else
658  s << out_path << "." << parallel_size() << "." << parallel_rank();
659  pout_path = s.str();
660  }
661  else if (pout_path.find("/") == std::string::npos && !stk::get_log_ostream(pout_path)) {
662  std::ostringstream s;
663 
664  s << working_directory() << pout_path << "." << parallel_size() << "." << parallel_rank();
665  pout_path = s.str();
666  }
667 
668  if (!stk::get_log_ostream(pout_path)) {
669  output_description << " poutfile=\"" << pout_path << "\"";
670  pout_ostream = "poutfile";
671  }
672  else
673  pout_ostream = pout_path;
674  }
675 
676 
677  std::string dout_ostream;
678  if (vm.count("dout")) {
679  std::string dout_path = vm["dout"].as<std::string>();
680  if (!dout_path.empty() && stk::is_registered_ostream(dout_path))
681  dout_ostream = dout_path;
682  else {
683  std::ostringstream s;
684  if (dout_path.size() && dout_path[0] != '/')
685  s << working_directory() << dout_path << "." << parallel_size() << "." << parallel_rank();
686  else
687  s << dout_path << parallel_size() << "." << parallel_rank();;
688  dout_path = s.str();
689  output_description << " doutfile=\"" << dout_path << "\"";
690  dout_ostream = "doutfile";
691  }
692  }
693  else
694  dout_ostream = "out";
695 
696  if (parallel_rank() == 0)
697  output_description << " out>" << out_ostream << "+pout";
698  else
699  output_description << " out>pout";
700 
701  output_description << " pout>" << pout_ostream << " dout>" << dout_ostream;
702 
703 
704  stk::bind_output_streams(output_description.str());
705  }
706 
707  env_data.m_outputP0 = &sierra::out();
708 
709 #ifdef SIERRA_EXPORT_CONTROL_EAR99
710  // If you are using an EAR99 export controlled version of Sierra,
711  // any attempt to modify or bypass this section of code is a
712  // violation of U.S. Export Control Regulations and subject to
713  // criminal prosecution.
714  if (parallel_size() > SIERRA_EXPORT_CONTROL_EAR99) {
715  if (parallel_rank() == 0) {
716  std::cerr << "ERROR: You are running an EAR99 export controlled version of\n";
717  std::cerr << " Sierra. For this export control level, a maximum of\n";
718  std::cerr << " "<<SIERRA_EXPORT_CONTROL_EAR99<<" processors is permitted\n";
719  }
720  MPI_Abort(env_data.m_parallelComm, MPI_ERR_OTHER);
721  }
722 #endif
723 
724  try {
725  // Create pid file if runtest command line option specified
726  if ( !get_param("runtest").empty() ) {
727 
728  mpi_filebuf mpi_buf;
729 
730  mpi_buf.open(env_data.m_parallelComm, 0, std::ios::out, get_param("runtest").c_str());
731 
732  if ( ! mpi_buf.is_open() )
733  throw RuntimeError() << "failed to open pid file " << get_param("runtest");
734 
735  std::ostream s( &mpi_buf );
736  s << parallel_rank() << ":" << hostname() << domainname() << ":" << pid() << ":" << pgrp() << std::endl;
737  }
738 
739  // Enable the timers
740  if (!get_param("timer").empty()) {
741  Diag::TimerParser parser;
742 
743  Diag::sierraTimerSet().setEnabledTimerMask(parser.parse(get_param("timer").c_str()));
744  }
745 
746  // Enable parallel exception handling, waited until now because it needs the Env output streams
748  }
749  catch (const std::exception &x) {
750  std::cerr << "SIERRA execution failed during diagnostic and timer initialization with the following exception:" << std::endl
751  << x.what() << std::endl;
752  abort();
753  }
754  catch (...) {
755  std::cerr << "SIERRA execution failed during diagnostic and timer initialization with unknown exception:" << std::endl;
756  abort();
757  }
758 
759 // Setup the hangup, segmentation violation, illegal instruction, bus error and
760 // terminate signal handlers.
761  if (get_param("nosignal").empty())
763 
764 
765  return returnValue;
766 }
767 
768 
769 
770 
771 void
772 Startup::startup(
773  int * argc,
774  char *** argv,
775  const char * product_name,
776  const char * build_time,
777  ExecType mpi_key,
778  const std::vector<int> *peer_sizes) {
779  m_mpiInitFlag = StartupSierra(argc, argv, product_name, build_time, mpi_key, peer_sizes);
780 }
781 
782 
784  int * argc,
785  char *** argv,
786  const char * product_name,
787  const char * build_date_time,
788  ExecType mpi_key,
789  const std::vector<int> *peer_sizes)
790  : m_mpiInitFlag(false)
791 {
792  startup(argc, argv, product_name, build_date_time, mpi_key, peer_sizes);
793 }
794 
795 
796 void ShutDownSierra(bool mpiInitFlag) {
797  if (get_param("nosignal").empty())
799 
800  mpih::Delete_Handles();
801 
802  EnvData &env_data = EnvData::instance();
803  mpih::Keyval_delete(env_data.m_parallelComm);
804 
805  reset(MPI_COMM_NULL);
806 
807  if (mpiInitFlag)
808  MPI_Finalize();
809 }
810 
811 
812 
814  ShutDownSierra(m_mpiInitFlag);
815 }
816 
817 
818 void parse_options(MPI_Comm comm,
819  int * argc,
820  char *** argv)
821 {
822  try {
823  char ** argv2 = new char *[*argc];
824  for (int i = 0; i < *argc; ++i) {
825  if (std::strlen((*argv)[i]) > 2 && (*argv)[i][0] == '-' && (*argv)[i][1] != '-') {
826  argv2[i] = new char[std::strlen((*argv)[i]) + 2];
827  argv2[i][0] = '-';
828  std::strcpy(&argv2[i][1], (*argv)[i]);
829  }
830  else {
831  argv2[i] = new char[std::strlen((*argv)[i]) + 1];
832  std::strcpy(argv2[i], (*argv)[i]);
833  }
834  }
835 
836  // Broadcast argc and argv to all processors.
837  stk::BroadcastArg b_arg(comm, *argc, argv2);
838 
839  for (int i = 0; i < *argc; ++i)
840  delete[] argv2[i];
841  delete[] argv2;
842 
843  namespace opt = boost::program_options;
844  opt::variables_map &vm = stk::get_variables_map();
845  opt::options_description &od = stk::get_options_description();
846  opt::store(opt::parse_command_line(b_arg.m_argc, b_arg.m_argv, od, opt::command_line_style::unix_style), vm);
847  opt::notify(vm);
848 
849  for (Diag::WriterRegistry::iterator it = Diag::getWriterRegistry().begin(); it != Diag::getWriterRegistry().end(); ++it)
850  if (vm.count((*it).first.c_str()))
851  (*it).second.second->parse(vm[(*it).first.c_str()].as<std::string>().c_str());
852 
853 
854  // Must have a working directory
855  const std::string &working_dir = get_param("directory");
856  if ( working_dir.empty() || working_dir == PARAM_ON )
857  throw RuntimeError() << "working directory must be specified";
858  if (working_dir[working_dir.length() - 1] != '/')
859  const_cast<std::string &>(working_dir) += '/';
860 
861  }
862  catch (const std::exception &x) {
863  std::cerr << "SIERRA execution failed during command line processing with the following exception:" << std::endl
864  << x.what() << std::endl;
865  MPI_Abort(comm, MPI_ERR_OTHER);
866  }
867  catch (...) {
868  std::cerr << "SIERRA execution failed during command line processing with unknown exception:" << std::endl;
869 
870  MPI_Abort(comm, MPI_ERR_OTHER);
871  }
872 }
873 
874 void
875 startup_multi_exec(MPI_Comm world_comm,
876  ExecType my_executable_type,
877  const std::vector<int> *peer_sizes) // can be NULL.
878 {
879  EnvData &env_data = EnvData::instance();
880 
881  // MPI interface construction
882  int world_size = -1 ;
883  int world_rank = -1 ;
884 
885  if ( MPI_Comm_size(world_comm, &world_size) != MPI_SUCCESS)
886  throw RuntimeError() << "MPI_Comm_size failed";
887 
888  if ( MPI_Comm_rank(world_comm, &world_rank) != MPI_SUCCESS || -1 == world_rank )
889  throw RuntimeError() << "MPI_Comm_rank failed";
890 
891  if (my_executable_type == EXEC_TYPE_FLUID || my_executable_type == EXEC_TYPE_LAG) {
892  // This is specific for gemini. Gemini performs three broadcasts, one for the
893  // EXEC_TYPE_FLUID and one for the EXEC_TYPE_LAG. Also note that the ranks of processors must
894  // be ordered such that all gemini processors come first. Gemini mandates that it;s master is
895  // processor 0 and use ranks through its size.
896  int lag_master = 0;
897  int lag_rank_size = -1;
898  int fluid_master = 0;
899 
900  if (world_rank == 0) {
901  typedef std::map<ExecType, std::vector<int> > ExecTypeRanks;
902 
903  ExecTypeRanks exec_type_ranks;
904 
905  exec_type_ranks[my_executable_type].push_back(0);
906 
907  for (int i = 1; i < world_size; ++i) {
908  MPI_Status status;
909  int proc_stat[2]; // rank, ExecType
910  if (MPI_Recv(proc_stat, 2, MPI_INTEGER, i, MPI_ANY_TAG, world_comm, &status) != MPI_SUCCESS)
911  throw RuntimeError() << "MPI_Recv failed";
912 
913  exec_type_ranks[(ExecType) proc_stat[1]].push_back(proc_stat[0]);
914  }
915 
916  std::vector<int> &fluid_ranks = exec_type_ranks[EXEC_TYPE_FLUID];
917  if (fluid_ranks.size())
918  fluid_master = fluid_ranks.front();
919 
920  if (MPI_Bcast(&fluid_master, 1, MPI_INTEGER, 0, world_comm) != MPI_SUCCESS)
921  throw RuntimeError() << "MPI_Bcast failed";
922 
923  std::vector<int> &lag_ranks = exec_type_ranks[EXEC_TYPE_LAG];
924  if (lag_ranks.size())
925  lag_master = lag_ranks.front();
926 
927  if (MPI_Bcast(&lag_master, 1, MPI_INTEGER, 0, world_comm) != MPI_SUCCESS)
928  throw RuntimeError() << "MPI_Bcast failed";
929 
930  lag_rank_size = lag_ranks.size();
931  if (MPI_Bcast(&lag_rank_size, 1, MPI_INTEGER, 0, world_comm) != MPI_SUCCESS)
932  throw RuntimeError() << "MPI_Bcast failed";
933  }
934  else {
935  int proc_stat[2];
936  proc_stat[0] = world_rank;
937  proc_stat[1] = my_executable_type;
938 
939  if (MPI_Send(proc_stat, 2, MPI_INTEGER, 0, 0, world_comm) != MPI_SUCCESS)
940  throw RuntimeError() << "MPI_Send failed";
941 
942  if (MPI_Bcast(&fluid_master, 1, MPI_INTEGER, 0, world_comm) != MPI_SUCCESS)
943  throw RuntimeError() << "MPI_Bcast failed";
944 
945  if (MPI_Bcast(&lag_master, 1, MPI_INTEGER, 0, world_comm) != MPI_SUCCESS)
946  throw RuntimeError() << "MPI_Bcast failed";
947 
948  if (MPI_Bcast(&lag_rank_size, 1, MPI_INTEGER, 0, world_comm) != MPI_SUCCESS)
949  throw RuntimeError() << "MPI_Bcast failed";
950  }
951 
952  MPI_Comm lag_comm = world_comm;
953  MPI_Comm fluid_comm = MPI_COMM_NULL;
954  const int fluid_rank_size = world_size - lag_rank_size;
955  if (fluid_rank_size) {
956 
957  MPI_Group world_group;
958  MPI_Group lag_group;
959  MPI_Group fluid_group;
960 
961  if (MPI_Comm_group(world_comm, &world_group) != MPI_SUCCESS)
962  throw RuntimeError() << "MPI_Comm_group failed";
963 
964  std::vector<int> lag_ranks;
965  for (int i = 0; i < lag_rank_size; ++i)
966  lag_ranks.push_back(lag_master + i);
967 
968  if (MPI_Group_incl(world_group, lag_ranks.size(), &lag_ranks[0], &lag_group) != MPI_SUCCESS)
969  throw RuntimeError() << "MPI_Group_incl failed";
970  if (MPI_Comm_create(world_comm, lag_group, &lag_comm) != MPI_SUCCESS)
971  throw RuntimeError() << "MPI_Comm_create failed";
972 
973  std::vector<int> fluid_ranks;
974  for (int i = 0; i < fluid_rank_size; ++i)
975  fluid_ranks.push_back(fluid_master + i);
976 
977  if (MPI_Group_incl(world_group, fluid_ranks.size(), &fluid_ranks[0], &fluid_group) != MPI_SUCCESS)
978  throw RuntimeError() << "MPI_Group_incl failed";
979  if (MPI_Comm_create(world_comm, fluid_group, &fluid_comm) != MPI_SUCCESS)
980  throw RuntimeError() << "MPI_Comm_create failed";
981  }
982 
983  env_data.m_worldComm = world_comm;
984  env_data.m_execMap[EXEC_TYPE_LAG].m_master = lag_master;
985  env_data.m_execMap[EXEC_TYPE_LAG].m_groupComm = lag_comm;
986  env_data.m_execMap[EXEC_TYPE_FLUID].m_master = fluid_master;
987  env_data.m_execMap[EXEC_TYPE_FLUID].m_groupComm = fluid_comm;
988  }
989  else if (my_executable_type == EXEC_TYPE_PEER) {
990  // This executable will run on 2 or more communicators.
991 
992  // NOTE: Only 2 communicators is currently supported...
993 
994  // If peer_sizes is NULL, then split world_comm into two equal
995  // size communicators (peer(1) is larger if world_comm size is
996  // odd)
997  // If peer_sizes is not NULL, then split world_comm into
998  // peer_sizes.size() sub communicators with peer(i) of size
999  // peer_sizes(i).
1000 
1001  // Sync 'peer_sizes' across all processors if non-null
1002  // For now, we limit the number of peer applications to 2.
1003 
1004  if (peer_sizes != NULL && peer_sizes->size() > 2) {
1005  throw RuntimeError() << "The total number of peer application processor sizes specfied is "
1006  << peer_sizes->size()
1007  << ", but the current limit is 2.";
1008  }
1009 
1010  // Peer sizes is only set correctly on processor 0 since it was passed in by the
1011  // main routine prior to MPI_Init being called. Broadcast the values to all processors.
1012  int peers[2];
1013  if (world_rank == 0) {
1014  if (peer_sizes != NULL) {
1015  peers[0] = (*peer_sizes)[0];
1016  peers[1] = (*peer_sizes)[1];
1017  } else {
1018  peers[0] = world_size / 2;
1019  peers[1] = world_size - world_size/2;
1020  }
1021  }
1022  if (MPI_Bcast(peers, 2, MPI_INTEGER, 0, world_comm) != MPI_SUCCESS)
1023  throw RuntimeError() << "MPI_Broadcast -- peers failed";
1024 
1025  // Check that the number of processes specified is equal to the
1026  // total number of processes
1027  int peer_proc_count = peers[0] + peers[1];
1028  if (peer_proc_count != world_size) {
1029  throw RuntimeError() << "The total number of peer processors specfied is " << peer_proc_count
1030  << " which is not equal to the total number of processors (" << world_size << ").";
1031  }
1032 
1033  int my_peer_group = MPI_UNDEFINED;
1034  int sum = 0;
1035  for (size_t i=0; i < 2; i++) {
1036  sum += peers[i];
1037  if (world_rank < sum) {
1038  my_peer_group = i;
1039  break;
1040  }
1041  }
1042 
1043  MPI_Comm peer_comm;
1044  if (MPI_Comm_split(world_comm, my_peer_group, world_rank, &peer_comm) != MPI_SUCCESS) {
1045  throw RuntimeError() << "MPI_Comm_split failed";
1046  }
1047  env_data.m_worldComm = world_comm;
1048  env_data.m_execMap[EXEC_TYPE_PEER].m_groupComm = peer_comm;
1049  env_data.m_execMap[EXEC_TYPE_PEER].m_master = my_peer_group; // Overloading meaning to peer group.
1050  }
1051 }
1052 
1053 bool
1054 is_comm_valid()
1055 {
1056  EnvData &env_data = EnvData::instance();
1057  if (env_data.m_parallelComm == MPI_COMM_NULL) {
1058  return false;
1059  } else {
1060  return true;
1061  }
1062 }
1063 
1064 void
1066  MPI_Comm new_comm)
1067 {
1068  EnvData &env_data = EnvData::instance();
1069 
1070  // Destroy old comm
1071  if (env_data.m_parallelComm != MPI_COMM_NULL) {
1072 
1073  if (new_comm != MPI_COMM_NULL) {
1074  mpih::Sub_Communicator(env_data.m_parallelComm, new_comm);
1075  }
1076 
1077  env_data.m_parallelComm = MPI_COMM_NULL ;
1078  env_data.m_parallelSize = -1;
1079  env_data.m_parallelRank = -1 ;
1080  }
1081 
1082  setMpiCommunicator(new_comm);
1083 }
1084 
1085 void setMpiCommunicator(MPI_Comm communicator)
1086 {
1087  EnvData &env_data = EnvData::instance();
1088  if(communicator != MPI_COMM_NULL)
1089  {
1090  env_data.m_parallelComm = communicator;
1091 
1092  if(MPI_Comm_size(env_data.m_parallelComm, &env_data.m_parallelSize) != MPI_SUCCESS
1093  || MPI_Comm_rank(env_data.m_parallelComm, &env_data.m_parallelRank) != MPI_SUCCESS
1094  || env_data.m_parallelSize == -1
1095  || env_data.m_parallelRank == -1)
1096  {
1097  throw RuntimeError() << "reset given bad MPI communicator";
1098  }
1099  }
1100 }
1101 
1102 void
1104 {
1105  EnvData &env_data = EnvData::instance();
1106 
1108 
1109  stk::all_write_string(Env::parallel_comm(), *env_data.m_outputP0, env_data.m_output.str());
1110  env_data.m_output.str("");
1111 }
1112 
1113 
1114 void
1115 request_shutdown(bool shutdown)
1116 {
1117  EnvData::instance().m_shutdownRequested = shutdown;
1118 }
1119 
1120 
1121 bool
1122 is_shutdown_requested()
1123 {
1124  int shutdown_requested_in = EnvData::instance().m_shutdownRequested || Env::HUP_received();
1125  int shutdown_requested;
1126 
1127  MPI_Allreduce(&shutdown_requested_in, &shutdown_requested, 1, MPI_INT, MPI_SUM, Env::parallel_comm());
1128 
1129  return shutdown_requested != 0;
1130 }
1131 
1132 
1133 void abort() {
1134  EnvData &env_data = EnvData::instance();
1135 
1136  // Cannot be sure of parallel synchronization status; therefore, no communications can
1137  // occur. Grab and dump all pending output buffers to 'std::cerr'.
1138  std::cerr << std::endl
1139  << "*** SIERRA ABORT on P" << EnvData::instance().m_parallelRank << " ***"
1140  << std::endl
1141  << "*** check " << get_param("output-log")
1142  << " file for more information ***"
1143  << std::endl ;
1144 
1145  if (!env_data.m_output.str().empty()) {
1146  std::cerr << "Buffer contents of deferred output stream on processor " << parallel_rank()
1147  << std::endl ;
1148  std::cerr << env_data.m_output.str();
1149  }
1150 
1151  std::cerr.flush();
1152  std::cout.flush();
1153 
1154  ::sleep(1); // Give the other processors a chance at
1155  // catching up, seems to help hanging problems.
1156  MPI_Abort(env_data.m_parallelComm, MPI_ERR_OTHER); // First try to die
1157  std::exit( EXIT_FAILURE ); // Second try to die
1158 }
1159 
1160 
1161 const std::string &
1163  const char * const option)
1164 {
1165  if (EnvData::instance().m_vm.count(option)) {
1166  if (EnvData::instance().m_vm[option].as<std::string>().empty())
1167  return EnvData::instance().m_onString;
1168  else
1169  return EnvData::instance().m_vm[option].as<std::string>();
1170  }
1171  else
1172  return EnvData::instance().m_emptyString;
1173 }
1174 
1175 
1176 void
1178  const char * option,
1179  const std::string & value) {
1180 
1181 
1182  namespace opt = boost::program_options;
1183 
1184  opt::variables_map &vm = stk::get_variables_map();
1185  opt::options_description &od = stk::get_options_description();
1186 
1187  int argc = 1;
1188  char *s = std::strcpy(new char[std::strlen(option) + 1], option);
1189 
1190  opt::store(opt::parse_command_line(argc, &s, od), vm);
1191  opt::notify(vm);
1192 
1193  delete [] s;
1194 }
1195 
1196 } // namespace Env
1197 } // namespace sierra
std::ostream & dout()
Diagnostic output stream.
Definition: OutputLog.cpp:674
std::ostream & output()
Function output returns the processor output log stream. This stream is connected via an mpi_filebuf ...
Definition: Env.cpp:262
std::string title(const std::string &s)
Function title returns a first letter of each word capitalized of the string.
Definition: StringUtil.cpp:107
std::ostream & dwout()
Diagnostic writer stream.
Definition: OutputLog.cpp:690
const std::string & startup_date()
Function startup_date returns the startup date of this application execution.
Definition: Env.cpp:198
std::string osversion()
Function osversion returns the hardware type of the host running the application. ...
Definition: Platform.cpp:541
void set_param(const char *option, const std::string &value)
Member function set_param assigns the value to the parameter option.
Definition: Env.cpp:1177
void set_check_subcycle(bool value)
Function set_check_subcycle sets whether to check input file for subcycling. The default behavior cor...
Definition: Env.cpp:236
Class TimerParser implements the bit mask parser for the timer&#39;s bit masks.
Definition: Timer.hpp:790
Generic application using entire communicator (MPI_COMM_WORLD)
Definition: Env.hpp:63
~Startup()
Destroys a Startup instance. IT closes all logging output streams and will finalize MPI only if the S...
Definition: Env.cpp:813
double wall_now()
Member function wall_now returns the epoch as a double precision value in seconds to &quot;millisecond&quot; ac...
Definition: Platform.cpp:261
std::ostream & outputP0()
Function outputP0 returns the processor output log stream on processor 0 and the null log stream on a...
Definition: Env.cpp:269
Split communicator application; non-Gemini.
Definition: Env.hpp:66
const std::string working_directory()
Function working_directory returns the current working directory of this application execution...
Definition: Env.cpp:250
std::ostream & pout()
Per-processor output stream (See RuntimeDeferredx)
Definition: OutputLog.cpp:666
void unregister_log_ostream(std::ostream &os)
Function register_log_ostream takes an existing std::ostream and makes it available for output redire...
Definition: OutputLog.cpp:228
const std::string & executable_file()
Function executable_file returns the path of this executable file. information.
Definition: Env.cpp:179
int pid()
Function pid returns the process id of the process running the application.
Definition: Platform.cpp:557
bool shutdown_requested()
Function shutdown_requested returns true if an application shutdown has requested via the request_shu...
boost::program_options::options_description & get_options_description()
Function get_options_description is a singleton used to store the command line option descriptions fo...
std::ostream & outputNull()
Function outputNull returns the null output stream. All data is simply discarded by the buffer associ...
Definition: Env.cpp:276
const std::string & architecture()
Function architecture returns the platform executing this product. This is obtained during startup by...
Definition: Env.cpp:243
std::ostream & out()
Normal output stream.
Definition: OutputLog.cpp:658
void abort()
Function abort aborts the execution of the sierra application.
Definition: Env.cpp:1133
String lower(const String &s)
Function lower returns a lower case version of the string.
Definition: StringUtil.hpp:281
void startup_preparallel_platform()
Function startup_preparallel_platform ...
Definition: Platform.cpp:255
static const std::string PARAM_ON
Option value when command line option specified without a parameter.
Definition: Env.hpp:45
static void bootstrap()
Member function bootstrap runs through the stored bootstrap function pointers and executes each funct...
Definition: Bootstrap.cpp:21
Class Bootstrap serves as a bootstrapping mechanism for products in the sierra toolkit and elsewhere...
Definition: Bootstrap.hpp:35
void bind_output_streams(const std::string &output_description)
Function bind_output_streams parses the output_description and opens and registers the log streams an...
Definition: OutputLog.cpp:644
std::string section_title(const std::string &title)
Function section_title returns a section title. The title has date and time concatenated and right ju...
Definition: Env.cpp:300
Class basic_indent_streambuf implements a output streambuf that performs indentation, blank line removal and outline bracing, sending the result character stream to another output stream buffer.
Mask parse(const char *mask_string) const
Member function parse parses the mask string and generates the corresponding bit mask.
Definition: Timer.cpp:1151
int parallel_rank()
function parallel_rank returns the rank of this processor in the current mpi communicator.
Definition: Env.cpp:316
ExecType
Enumeration ExecutableType defines the known types of coordinated executables that operate with a sie...
Definition: Env.hpp:62
double start_time()
Function start_time returns the start time of this application execution.
Definition: Env.cpp:210
bool is_registered_ostream(const std::string &name)
Function is_registered_ostream returns true if an output stream of the specified name is registered...
Definition: OutputLog.cpp:356
void all_write_string(ParallelMachine arg_comm, std::ostream &arg_root_os, const std::string &arg_msg)
Write string from any or all processors to the ostream on the root processor.
ExTemp1< std::runtime_error > RuntimeError
Defined in &lt;stdexcept&gt;
Definition: Exception.hpp:775
MPI_Comm parallel_world_comm()
Function parallel_world_comm returns the MPI_COMM_WORLD communicator used by the sierra environment i...
Definition: Env.cpp:327
bool HUP_received()
Function request_shutdown sets the shutdown requested flag so that future calls to shutdown_requested...
Definition: Signal.cpp:278
void report_deferred_messages(ParallelMachine comm)
Function report_deferred_messages aggregates and reports the message on the root processor.
const char * subsection_separator()
Function subsection_separator returns a c-style string to be used as a output subsection separator...
Definition: Env.cpp:291
Class BroadcastArg creates a copy of argc and argv after broadcasting them from processor 0...
bool StartupSierra(int *argc, char ***argv, const char *product_name, const char *build_time, ExecType mpi_key, const std::vector< int > *peer_sizes)
Initialize MPI related operations for sierra, outputs banner, etc. returns 1 if MPI was initialized...
Definition: Env.cpp:392
std::string format_time(double t, const char *format)
Function format_time encodes the time using the format specified. The format is described in stdftime...
Definition: StringUtil.cpp:173
void deactivate_signals()
Function deactivate_signals disables the signal handlers.
Definition: Signal.cpp:250
int peer_group()
Function peer_group returns the peer group rank for an application of type EXEC_TYPE_PEER.
Definition: Env.cpp:340
void register_stl_parallel_exceptions()
Member function register_stl_parallel_exceptions registers the stl exceptions with the parallel excep...
Definition: Exception.cpp:156
std::string domainname()
Function domainname returns the domainname of the domain running the application. ...
Definition: Platform.cpp:463
int parallel_lag_master()
Function parallel_lag_master returns the global rank of the Sierra lagrangian application.
Definition: Env.cpp:332
WriterRegistry & getWriterRegistry()
Function getWriterRegistry returns a reference to the diagnostic writer registry. ...
Gemini Euler application.
Definition: Env.hpp:64
std::ostream & tout()
Regression test textual output stream.
Definition: OutputLog.cpp:682
MPI_Comm parallel_comm()
Function parallel_comm returns the current MPI communicator used by the sierra environment.
Definition: Env.cpp:321
boost::program_options::variables_map & get_variables_map()
Function get_variabel_map is a singleton used to store the variables parsed from the line option desc...
int parallel_fluid_master()
Function parallel_lag_master returns the global rank of the Gemini Euler application.
Definition: Env.cpp:336
const std::string & executable_date()
Function executable_date returns the build date of the executable file as a string in the form Mmm dd...
Definition: Env.cpp:186
bool developer_mode()
Function developer_mode returns true if the –developer option was specified on the application comman...
Definition: Env.cpp:217
void register_log_ostream(std::ostream &os, const std::string &name)
Function register_log_ostream takes an existing std::ostream and makes it available for output redire...
Definition: OutputLog.cpp:205
void reset(MPI_Comm new_comm)
Function reset determines new parallel_size and parallel_rank. Flushes, closes, and reopens log files...
Definition: Env.cpp:1065
const std::string & get_param(const char *const option)
Function query_env_param searches the command line options for the specified option. If not found, a const reference to an empty string is returned.
Definition: Env.cpp:1162
int parallel_size()
function parallel_size returns the number of processors in the current mpi communicator.
Definition: Env.cpp:312
void register_ostream(std::ostream &os, const std::string &name)
Function register_ostream registers an output stream with the output stream registry. The registration process creates an intermediate tee streambuf.
Definition: OutputLog.cpp:275
void activate_signals()
Function activate_signals enables the signal handlers.
Definition: Signal.cpp:243
Sierra Lagrangian application.
Definition: Env.hpp:65
void set_input_file_required(bool value)
Function set_input_file_required sets whether lack of an input file specification will automatically ...
Definition: Env.cpp:231
Startup(int *argc, char ***argv, const char *product_name, const char *build_date_time, ExecType mpi_key=EXEC_TYPE_WORLD, const std::vector< int > *peer_sizes=NULL)
Creates a new Startup instance.
Definition: Env.cpp:783
int pgrp()
Function pgrp returns the process group id of the process running the application.
Definition: Platform.cpp:564
std::string osname()
Function osname returns the operating system nameof the host running the application.
Definition: Platform.cpp:525
std::string hostname()
Function hostname returns the hostname of the host running the application.
Definition: Platform.cpp:454
void output_flush()
Function output_flush flushes all output on all currently open synchronous outptu files which were op...
Definition: Env.cpp:1103
_setw setw(int width)
Function setw sets the width for the next field as a manipulator.
Definition: WriterManip.hpp:44
void unregister_ostream(std::ostream &os)
Function unregister_ostream unregisters an output stream.
Definition: OutputLog.cpp:300
std::ostream * get_log_ostream(const std::string &name)
Function get_log_file_ostream return the output stream of the log file with the specified name from t...
Definition: OutputLog.cpp:263
const char * section_separator()
Function output_open opens an output file on processor zero for synchronous data output from all proc...
Definition: Env.cpp:282
const std::string & product_name()
Function product_name returns the product&#39;s name. This name is used to query the product registry for...
Definition: Env.cpp:172