Sierra Toolkit  Version of the Day
Env.hpp
1 /*--------------------------------------------------------------------*/
2 /* Copyright 2003 - 2010 Sandia Corporation. */
3 /* Under the terms of Contract DE-AC04-94AL85000, there is a */
4 /* non-exclusive license for use of this work by or on behalf */
5 /* of the U.S. Government. Export of this program may require */
6 /* a license from the United States Government. */
7 /*--------------------------------------------------------------------*/
8 
9 #ifndef STK_UTIL_DIAG_Env_h
10 #define STK_UTIL_DIAG_Env_h
11 
12 #include <ios> // #include <iosfwd> // ios_base is not defined in the forward file
13 #include <string>
14 
15 #include <stk_util/stk_config.h>
16 #if defined( STK_HAS_MPI )
17 #include <mpi.h>
18 #endif
19 #include <stk_util/parallel/Parallel.hpp>
20 
21 #include <stk_util/environment/ProgramOptions.hpp>
22 #include <stk_util/util/Bootstrap.hpp>
23 
24 #include <stk_util/util/FeatureTest.hpp>
25 #include <stk_util/diag/Option.hpp>
26 #include <stk_util/diag/Writer_fwd.hpp>
27 
28 namespace sierra {
29 
43 namespace Env {
44 
45 static const std::string PARAM_ON = "on";
46 
51 
62 enum ExecType {
67 };
68 
69 struct ExecInfo
70 {
71  MPI_Comm m_groupComm;
72  int m_master;
73 };
74 
75 
76 
105  bool StartupSierra(int *argc, char ***argv, const char *product_name, const char *build_date_time,
106  ExecType mpi_key = EXEC_TYPE_WORLD, const std::vector<int> *peer_sizes = NULL);
107 
108  //
109  // Cleanup any MPI stuff that was created from the startup sierra call, pass in the MPI initialization flag
110  // that StartupSierra generated
111  //
112  void ShutDownSierra(bool mpiInitFlag);
113 
114 
122 class Startup
123 {
124 public:
125 
153  Startup(int *argc, char ***argv, const char *product_name, const char *build_date_time,
154  ExecType mpi_key = EXEC_TYPE_WORLD, const std::vector<int> *peer_sizes = NULL);
155 
161  ~Startup();
162 
163 private:
185  void startup(int *argc, char ***argv, const char *product_name, const char *build_time,
186  ExecType mpi_key, const std::vector<int> *peer_sizes);
187 
188 private:
189  bool m_mpiInitFlag;
190 };
191 
192 
212 void reset(MPI_Comm mpi_comm); // , const char * const work_dir = NULL);
213 void setMpiCommunicator(MPI_Comm communicator);
214 bool is_comm_valid();
215 
216 
228 const std::string &get_param(const char * const option);
229 
230 
241 void set_param(const char *option, const std::string &value);
242 
250 const std::string &product_name();
251 
252 
261 bool developer_mode();
262 
268 void set_input_file_required(bool value);
269 
270 void setInputFileName(std::string value);
271 std::string getInputFileName();
272 
273 
278 void set_check_subcycle(bool value);
279 
289 const std::string &architecture();
290 
291 
300 const std::string &executable_file();
301 
302 
311 const std::string &executable_date();
312 
321 const std::string &startup_date();
322 
323 
332 double start_time();
333 
334 
342 double wall_now();
343 
344 
352 double cpu_now();
353 
354 
363 double vm_now();
364 
365 
374 const std::string working_directory();
375 
376 
387 std::ostream &output();
388 
389 
399 std::ostream &outputP0();
400 
401 
410 std::ostream &outputNull();
411 
412 
429 //std::ostream &output_open(const char * const filename);
430 
431 
439 const char *section_separator();
440 
441 
448 const char *subsection_separator();
449 
450 
461 std::string section_title(const std::string &title);
462 
463 
473 void output_flush();
474 
475 
487 void output_flush(std::ostream &stream);
488 
489 void request_shutdown(bool shutdown = true);
490 
491 bool is_shutdown_requested();
492 
498 void abort();
499 
500 
508 MPI_Comm parallel_comm();
509 
517 MPI_Comm parallel_world_comm();
518 
519 
526 int peer_group();
527 
528 
536 
537 
544 int parallel_lag_master();
545 
546 
555 int parallel_size();
556 
557 
566 int parallel_rank();
567 
568 // /**
569 // * @brief Function <b>set_current_diag_stream</b> set the diagnostic writer current out
570 // * put stream. The special names - and cout attach the diag stream to the std::cout
571 // * stream. The special name cerr attaches the stream to the std::cerr stream, output
572 // * attaches to the stream Env::output() and outputp0 to the stream outputP0(). Otherwise,
573 // * the file is opened with <b>mode</b> ios mode flags and attached to the diagnostic
574 // * stream.
575 // *
576 // * @param path a <b>char</b> const pointer to the file path to
577 // * open.
578 // *
579 // * @param mode a <b>std::ios::openmode</b> value of the ios mode to
580 // * open the file.
581 // *
582 // */
583 // void set_current_diag_stream(const char *path, std::ios_base::openmode mode = std::ios_base::out);
584 
585 // /**
586 // * @brief Function <b>getCurrentStream</b> returns the current diagnostic stream.
587 // *
588 // * @return a <b>std::ostream</b> reference to the current diagnostic
589 // * stream.
590 // */
591 // // Diag::Stream &get_current_diag_stream();
592 // std::ostream &get_current_diag_stream();
593 
597 
598 } // namespace Env
599 } // namespace sierra
600 
601 #endif // STK_UTIL_DIAG_Env_h
double cpu_now()
Member function cpu_now returns the accumlated cpu time for the process as a double precision value i...
Definition: Platform.cpp:271
std::ostream & output()
Function output returns the processor output log stream. This stream is connected via an mpi_filebuf ...
Definition: Env.cpp:264
std::string title(const std::string &s)
Function title returns a first letter of each word capitalized of the string.
Definition: StringUtil.cpp:107
const std::string & startup_date()
Function startup_date returns the startup date of this application execution.
Definition: Env.cpp:200
Definition: Env.cpp:53
void set_param(const char *option, const std::string &value)
Member function set_param assigns the value to the parameter option.
Definition: Env.cpp:1179
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:238
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:815
double wall_now()
Member function wall_now returns the epoch as a double precision value in seconds to "millisecond" 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:271
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:252
const std::string & executable_file()
Function executable_file returns the path of this executable file. information.
Definition: Env.cpp:181
std::ostream & outputNull()
Function outputNull returns the null output stream. All data is simply discarded by the buffer associ...
Definition: Env.cpp:278
const std::string & architecture()
Function architecture returns the platform executing this product. This is obtained during startup by...
Definition: Env.cpp:245
void abort()
Function abort aborts the execution of the sierra application.
Definition: Env.cpp:1135
static const std::string PARAM_ON
Option value when command line option specified without a parameter.
Definition: Env.hpp:45
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:302
int parallel_rank()
function parallel_rank returns the rank of this processor in the current mpi communicator.
Definition: Env.cpp:318
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:212
Class Startup is a sentry class for starting the application. It ensures that the command line argume...
Definition: Env.hpp:122
MPI_Comm parallel_world_comm()
Function parallel_world_comm returns the MPI_COMM_WORLD communicator used by the sierra environment i...
Definition: Env.cpp:329
const char * subsection_separator()
Function subsection_separator returns a c-style string to be used as a output subsection separator...
Definition: Env.cpp:293
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:394
double vm_now()
Member function vm_now returns the virtual memory in use for the process as a double precision value ...
Definition: Platform.cpp:442
int peer_group()
Function peer_group returns the peer group rank for an application of type EXEC_TYPE_PEER.
Definition: Env.cpp:342
int parallel_lag_master()
Function parallel_lag_master returns the global rank of the Sierra lagrangian application.
Definition: Env.cpp:334
Gemini Euler application.
Definition: Env.hpp:64
MPI_Comm parallel_comm()
Function parallel_comm returns the current MPI communicator used by the sierra environment.
Definition: Env.cpp:323
int parallel_fluid_master()
Function parallel_lag_master returns the global rank of the Gemini Euler application.
Definition: Env.cpp:338
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:188
bool developer_mode()
Function developer_mode returns true if the –developer option was specified on the application comm...
Definition: Env.cpp:219
void reset(MPI_Comm new_comm)
Function reset determines new parallel_size and parallel_rank. Flushes, closes, and reopens log files...
Definition: Env.cpp:1067
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:1164
int parallel_size()
function parallel_size returns the number of processors in the current mpi communicator.
Definition: Env.cpp:314
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:233
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:785
void output_flush()
Function output_flush flushes all output on all currently open synchronous outptu files which were op...
Definition: Env.cpp:1105
const char * section_separator()
Function output_open opens an output file on processor zero for synchronous data output from all proc...
Definition: Env.cpp:284
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:174