1 #ifndef __EXAMPLE_PROGRAM_H__
8 #define __EXAMPLE_PROGRAM_H__
9 #ifdef _ELMERMODULEDRIVER_PARALLEL_
15 namespace ElmerModuleDriver {
37 namespace ExampleProgram {
53 typedef IRAD::Global::GlobalObj<StackType,int,ProfilerType>
GlobalType;
54 #ifdef _ELMERMODULEDRIVER_PARALLEL_
55 typedef IRAD::Comm::CommunicatorObject
CommType;
62 typedef IRAD::Global::ParallelGlobalObj<CommType,StackType,int,ProfilerType>
PGlobalType;
76 : IRAD::Util::ComLineObject()
79 : IRAD::Util::ComLineObject(args)
88 AddOption(
'h',
"help");
89 AddOption(
'v',
"verbosity",1);
90 AddOption(
'o',
"output",2,
"filename");
91 AddArgument(
"input",1);
92 AddHelp(
"help",
"Prints this long version of help.");
93 AddHelp(
"output",
"Specifies the name of the output file.");
94 std::ostringstream Ostr;
95 Ostr <<
"Mode-dependent input: Input <filename> for serial example"
96 <<
"\n\t\tprogram, or <number of divisions> for parallel example.";
97 AddArgHelp(
"input",Ostr.str());
106 Ostr <<
"Example ElmerModuleDriver program.";
107 _description.assign(Ostr.str());
122 #ifdef _ELMERMODULEDRIVER_PARALLEL_
123 typedef IRAD::Global::Program<PGlobalType,ComLineType> ParallelProgramType;
189 int retval = SerialProgramType::Initialize();
190 if(!_command_line.GetOption(
"help").empty()){
191 std::ostringstream Ostr;
192 Ostr << _command_line.LongUsage() << std::endl;
197 std::ostringstream Ostr;
198 Ostr << _command_line.ErrorReport() << std::endl
199 << std::endl << _command_line.ShortUsage() << std::endl;
208 std::vector<std::string> args(_command_line.GetArgs());
212 std::string sverb(_command_line.GetOption(
"verbosity"));
213 if(sverb.empty() || sverb ==
".true.")
216 std::istringstream Vin(sverb);
224 std::ostringstream Ostr;
225 Ostr <<
"Configuration:" << std::endl
226 <<
"verbosity = " <<
verblevel << std::endl
227 <<
"input_name = " << input_name << std::endl;
229 Ostr <<
"output file = " <<
output_name << std::endl;
246 SetOutStream(std::cout);
256 #ifdef _ELMERMODULEDRIVER_PARALLEL_
257 class ParallelProgram :
public ParallelProgramType
329 std::string output_name;
341 ParallelProgramType()
346 ParallelProgram(
int nargs,
char **args) :
347 ParallelProgramType(nargs,args)
354 this->_command_line.Copy(comline);
355 this->Init(_command_line.ProgramName(),incomm);
361 virtual int Initialize()
363 int retval = ParallelProgramType::Initialize();
365 if(!_command_line.GetOption(
"help").empty()){
366 std::ostringstream Ostr;
367 Ostr << _command_line.LongUsage() << std::endl;
372 std::ostringstream Ostr;
373 Ostr << _command_line.ErrorReport() << std::endl
374 << std::endl << _command_line.ShortUsage() << std::endl;
380 output_name = _command_line.GetOption(
"output");
383 std::vector<std::string> args(_command_line.GetArgs());
384 std::istringstream Istr(args[0]);
388 std::string sverb(_command_line.GetOption(
"verbosity"));
389 if(sverb.empty() || sverb ==
".true.")
392 std::istringstream Vin(sverb);
400 std::ostringstream Ostr;
401 Ostr <<
"Configuration:" << std::endl
402 <<
"verbosity = " << verblevel << std::endl
403 <<
"number of divisions = " << ndiv << std::endl;
404 if(!output_name.empty())
405 Ostr <<
"output file = " << output_name << std::endl;
415 int VerbLevel()
const {
return verblevel;};
419 virtual ~ParallelProgram() {
422 SetOutStream(std::cout);
443 template<
typename ProgramType>
450 MyProgram.ErrOut(
"Error in Program Initialization.\n");
456 MyProgram.StdOut(
"Calling RUN.\n");
458 MyProgram.ErrOut(
"Error in Program RUN method.\n");
462 std::ostringstream Ostr;
463 MyProgram.Report(Ostr);
464 MyProgram.StdOut(Ostr.str());
465 MyProgram.StdOut(
"Calling Finalize.\n");
467 if(MyProgram.Finalize()){
468 MyProgram.ErrOut(
"Error in Program Finalization.\n");
472 MyProgram.StdOut(
"All done.\n");
481 #ifdef _ELMERMODULEDRIVER_PARALLEL_
482 inline double f(
double x)
494 return (4.0 / (1.0 + x*x));
499 typedef ElmerModuleDriver::ExampleProgram::ParallelProgram PEProgramType;
std::string StackType
Convenience type definition for program stack.
std::ifstream Inf
Infile stream for input.
IRAD::Global::Program< GlobalType, ComLineType > SerialProgramType
Convenience type definition for the serial program.
std::string input_name
Name of input file.
virtual int Run()
This function implements the main function executed by the program.
SerialProgram(int nargs, char **args)
Constructor designed to take the commandline args.
std::string output_name
Name of file for output.
int VerbLevel() const
Returns verbosity level.
void Initialize()
This is where the actual options and arguments are described.
int verblevel
Verbosity level.
std::ofstream Ouf
Outfile stream for output.
SerialProgram()
Default constructor.
IRAD::Profiler::ProfilerObj ProfilerType
Convenience type definition for Profiler object.
virtual ~SerialProgram()
Destructor.
int Driver(int argc, char *argv[])
Unified driver for the example programs.
IRAD::Global::GlobalObj< StackType, int, ProfilerType > GlobalType
Convenience type definition for the serial global object.
IRAD::Comm::CommunicatorObject CommType
Convenience typedef for CommunicatorObject.
virtual int Initialize()
Initializes native data structures from commandline args.
Implementation of the basic parts of the serial program example.
virtual int Initialize()
Initializes native data structures from commandline args.
ElmerModuleDriver::ExampleProgram::SerialProgram SEProgramType
Convenience definition for serial program type.
IRAD::Global::ParallelGlobalObj< CommTypeIrad, StackType, int, ProfilerType > PGlobalType
ExampleProgramComLine(const char *args[])
int VerbLevel() const
Returns verbosity level.
The ComLineObject for the example programs.
Implementation of the basic parts of the serial program example.
ExampleProgramComLine ComLineType
Convenience type definition for the example comline object.