1 #ifndef __PC2_PROGRAM_GLOBAL_H__ 9 #define __PC2_PROGRAM_GLOBAL_H__ 31 AddHelp(
'h',
"Produces this long help message");
32 AddHelp(
'd',
"Set the debugging level for the program.(default=1)");
33 AddHelp(
'p',std::string(
"Enable profiling. Profiling level > 1 enables profiling")+
34 std::string(
"\n\t\tbarriers, with the following settings available:\n\t\t\t")+
35 std::string(
"level=1 enables async profiling w/report on rank 0.\n\t\t\t")+
36 std::string(
"level=2 enables barrier sync w/report on rank 0.\n\t\t\t")+
37 std::string(
"level=3 enables async with output on all ranks.\n\t\t\t")+
38 std::string(
"level=4 enables sync with output on all ranks."));
39 AddHelp(
'v',std::string(
"Set the verbosity level for the program.")+
40 std::string(
" Anything\n\t\tlarger than 3 is debugging level.")+
41 std::string(
"\n\t\tExamples:\n\t\t\t-v (defaults to 1)\n\t\t\t")+
42 std::string(
"-v 0 (silence)\n\t\t\t")+
43 std::string(
"-v 1 (default: some normal output)\n\t\t\t")+
44 std::string(
"-v 2 (verbose: more than normal output)\n\t\t\t")+
45 std::string(
"-v 3 (verbose indeed: some control flow information)\n\t\t\t")+
46 std::string(
"-v 4 (ridiculously verbose debugging mode)\n\t\t\t")+
47 std::string(
"-v 10 (ranks other than 0 create output logs."));
48 SetDescription(std::string(
"This text should describe the program."));
60 SerialProgramType(narg,args){};
62 SerialProgramType(inglob){};
64 SerialProgramType(incom){};
66 SerialProgramType(incom,inglob){};
70 ErrOut(
"Failed to initialize.\n");
71 ErrOut(CommandLine().
ErrorReport()+std::string(
"\n"));
72 ErrOut(
"Use -h,--help for usage help.\n\n");
73 ErrOut(CommandLine().
ShortUsage()+std::string(
"\n"));
76 if(!CommandLine().
GetOption(
'h').empty()){
86 std::string sverb(CommandLine().
GetOption(
'v'));
91 std::istringstream Istr(sverb);
94 SetVerbLevel(verbLevel);
96 SetDebugStream(ErrStream());
97 SetDebugLevel(verbLevel - 1);
102 std::string sprof(CommandLine().
GetOption(
'p'));
104 if(sprof ==
".true.")
107 std::istringstream Istr(sprof);
119 virtual int Run(){
return(0);};
125 ErrOut(
"Failed to finalize.\n");
126 DumpErrors(ErrStream());
154 ParallelProgramType()
164 ParallelProgramType(nargs,args)
174 ParallelProgramType(nargs,args,inMPICommunicator)
185 this->_command_line.Copy(comline);
186 this->Init(_command_line.ProgramName(),incomm);
197 ErrOut(
"Failed to initialize.\n");
198 ErrOut(CommandLine().
ErrorReport()+std::string(
"\n"));
199 ErrOut(
"Use -h,--help for usage help.\n\n");
200 ErrOut(CommandLine().
ShortUsage()+std::string(
"\n"));
201 globalCommunicator.SetExit(1);
202 if(globalCommunicator.Check())
205 if(!CommandLine().GetOption(
'h').empty()){
207 globalCommunicator.SetExit(1);
208 if(globalCommunicator.Check())
211 std::string applicationName(CommandLine().
ProgramName());
220 std::string sverb(CommandLine().
GetOption(
'v'));
222 if(sverb ==
".true.")
227 int nZeros = std::log10((
double)nproc);
228 std::istringstream Istr(sverb);
231 SetVerbLevel(verbLevel);
234 SetVerbLevel(verbLevel - 9);
235 outFilePtr =
new std::ofstream;
236 std::ostringstream outFileNameStream;
237 outFileNameStream << applicationName <<
"_";
238 for(
int i = nZeros;i > 0;i--){
239 int numRanks = std::pow((
double)10,(
double)i);
241 outFileNameStream <<
"0";
243 if(!ErrStreamReady())
244 SetErrStream(std::cerr);
245 outFileNameStream << rank;
246 outFileNameStream <<
".out";
247 outFileName.assign(outFileNameStream.str());
248 outFilePtr->open(outFileNameStream.str().c_str());
250 globalCommunicator.SetErr(1);
254 if(globalCommunicator.Check()){
256 ErrOut(
"Unable to open output on all processors.\n");
258 }
else if(rank > 0) {
259 SetOutStream(*outFilePtr);
261 SetDebugStream(OutStream());
262 SetDebugLevel(verbLevel - 3);
264 SetDebugLevel(verbLevel - 12);
269 std::string sprof(CommandLine().
GetOption(
'p'));
271 DisableProfilingBarriers();
273 if(sprof ==
".true.")
276 std::istringstream Istr(sprof);
283 if(profLevel==2 || profLevel == 4)
284 EnableProfilingBarriers();
286 DisableProfilingBarriers();
293 std::string sdebug(CommandLine().
GetOption(
'd'));
295 if(sdebug ==
".true.")
298 std::istringstream Istr(sdebug);
302 SetDebugLevel(debugLevel);
318 SetOutStream(std::cout);
324 virtual int Run(){
return(0);};
329 ErrOut(
"Failed to finalize.\n");
331 DumpErrors(ErrStream());
338 template<
typename ProgramType>
342 if(mainProgram.Initialize()){
345 std::string programName(mainProgram.CommandLine().ProgramName());
347 if(mainProgram.Run()){
351 if(mainProgram.Finalize()){
parallelprogram()
Default constructor.
std::string outFileName
Name of file for output.
std::string ErrorReport()
Error reporting.
pcpp::ConfigType ConfigurationType
std::string GetOption(const char &s)
Get the value of an option.
ix::global::mpiprogram< commandline > ParallelProgramType
std::string ProgramName() const
Program name access.
virtual int Run()
This function implements the main function executed by the program.
ix::global::Program< GlobalType, commandline > SerialProgramType
virtual void Initialize()
defines PlasCom2-specific command-line arguments
int MainDriver(int argc, char *argv[])
virtual int Finalize()
Finalizes the global object, and it's profiler object.
pcpp::PartitionInfoType PartitionInfoType
int numProcessors
Number of processors.
std::ofstream * outFilePtr
Output file stream object for output.
parallelprogram(commandline &comline, CommunicatorType &incomm)
Constructor designed to take a commandline object, and communicator object.
serialprogram(GlobalType &inglob)
virtual ~parallelprogram()
Destructor.
void SetDescription(const std::string &desc)
Set description string.
int verblevel
Verbosity level.
commandline(commandline &inComLine)
Main encapsulation of MPI.
void AddOption(char s, const std::string &l, int=0)
User interface to describe simple option.
serialprogram(commandline &incom)
virtual int Finalize()
Finalizes the global object, and it's profiler object.
pcpp::CommunicatorType CommunicatorType
global::Program< Global, command_line > ProgramType
commandline(const char *args[])
std::string LongUsage()
Generate long usage string.
int ndiv
Number of partitions for domain.
parallelprogram(int nargs, char **args, MPI_Comm inMPICommunicator)
Constructor designed to take all commandline args and an MPI Communicator.
virtual int Initialize()
Populates native data structures from commandline.
serialprogram(commandline &incom, GlobalType &inglob)
void InitializeDefaults()
void AddHelp(char s, const std::string &help)
Specify usage for an option.
parallelprogram(int nargs, char **args)
Constructor designed to take all commandline args.
int numThreads
Number of threads.
serialprogram(int narg, char **args)
std::string ShortUsage()
Generate short usage string.