PlasCom2  1.0
XPACC Multi-physics simluation application
profane.C
Go to the documentation of this file.
1 #include <sstream>
7 #include <fstream>
8 #include <cassert>
9 #include <cmath>
10 #include <iomanip>
11 #include <cstdlib>
12 
13 //using namespace std;
14 
15 #include "Profiler.H"
16 #include "ComLine.H"
17 
18 
19 namespace ix {
20  namespace profiler {
21 
26  {
27  public:
28  ProfaneComLine(const char *args[])
29  : ComLineObject(args)
30  {};
31  void Initialize(){
32  AddOption('h',"help");
33  AddOption('s',"scalability");
34  AddOption('f',"fixed");
35  AddOption('v',"verb",1,"level");
36  AddOption('c',"config",2,"configfile");
37  AddOption('o',"out",2,"outputfile");
38  AddArgument("input_files",1);
39  AddHelp("help","Prints this long version of help.");
40  AddHelp("verb","Makes the test more verbose. Default level is 1.");
41  AddHelp("config","Specifies the name of the configuration file.");
42  AddHelp("out","Specifies the name of the output file.");
43  AddArgHelp("input_files","Space delimited list of input profiles.");
44  std::ostringstream Ostr;
45  Ostr << "Use fixed problem size in scalability analysis. Only makes"
46  << "\n\t\tsense when scalability mode is enabled.";
47  AddHelp("fixed",Ostr.str());
48  AddHelp("scalability","Enable scalability mode.");
49  Ostr.str("");
50  Ostr << "Performance analysis tool for analyzing profiles produced"
51  << "\nby the Profiler utility.";
52  _description.assign(Ostr.str());
53  };
54  };
55 
56 
62  int Profane(int argc,char *argv[]){
63  ProfaneComLine comline((const char **)argv);
64  comline.Initialize();
65  int clerr = comline.ProcessOptions();
66  std::string cfname = comline.GetOption("config");
67  std::string sverb = comline.GetOption("verb");
68  bool scalamode = !comline.GetOption("scalability").empty();
69  std::string stat_summary_name = comline.GetOption("out");
70  bool write_summary_outfile = !stat_summary_name.empty();
71  bool is_fixed = !comline.GetOption("fixed").empty();
72  if(!comline.GetOption("help").empty()){
73  std::cout << comline.LongUsage() << std::endl;
74  return(0);
75  }
76  if(clerr){
77  std::cerr << comline.ErrorReport() << std::endl
78  << std::endl << comline.ShortUsage() << std::endl;
79  return(1);
80  }
81  int verblevel = 0;
82  if(!sverb.empty() && sverb != ".true."){
83  std::istringstream Istr(sverb);
84  Istr >> verblevel;
85  }
86  std::ofstream Ouf;
87  if(write_summary_outfile){
88  Ouf.open(stat_summary_name.c_str());
89  if(!Ouf){
90  std::cerr << comline.ProgramName() << "::Error: Could not"
91  << " open output file, " << stat_summary_name
92  << ", for output. Continuing with stdout."
93  << std::endl;
94  }
95  }
96  std::vector<std::string> infiles = comline.GetArgs();
97  if(infiles.size()==0) {
98  std::cerr << "Profane::Error: No input files specified." << std::endl
99  << std::endl << comline.ShortUsage() << std::endl;
100  return(1);
101  }
102  profiler::ProfilerObj profiler;
103  if(verblevel > 1){
104  profiler.SetOut(&std::cout);
105  profiler.SetErr(&std::cerr);
106  }
107  if(cfname.empty()){
108  std::string::size_type x = infiles[0].find("prof_");
109  cfname.assign(infiles[0].substr(0,x));
110  cfname += "rpconfig";
111  std::ifstream Inf;
112  Inf.open(cfname.c_str());
113  if(!Inf)
114  cfname.assign("profiler.rpconfig");
115  else
116  Inf.close();
117  }
118  if(profiler.ReadConfig(cfname) && !cfname.empty())
119  std::cerr << comline.ProgramName()
120  << "::Warning: unable to read config file, " << cfname
121  << ". Continuing without configuration." << std::endl;
122  if(!scalamode){
123  if(infiles.size() == 1){
124  if(profiler.ReadEventsFromFile(infiles[0]))
125  exit(1);
126  profiler.SummarizeSerialExecution(std::cout);
127  }
128  else{
129  profiler::PEventList parallel_event_list;
130  if(profiler.ReadParallelEventFiles(infiles,parallel_event_list))
131  exit(1);
132  profiler.SummarizeParallelExecution(std::cout,Ouf,parallel_event_list);
133  }
134  }
135  else{
136  // if(infiles.size() == 1){
137  // if(!read_scalability_from_file(*ai))
138  // exit(1);
139  // scalability_summary();
140  // }
141  // else{
142  profiler::ScalaMap scala_map;
143  if(profiler.ReadSummaryFiles(infiles,scala_map)){
144  std::cerr << comline.ProgramName() << ": Error: Could not process "
145  << "summary files." << std::endl;
146  return(1);
147  }
148  profiler::ScalaStatMap scala_statmap;
149  if(profiler.PopulateScalaMap(scala_map,scala_statmap,!is_fixed)){
150  std::cerr << comline.ProgramName()
151  << ": Error: Unable to calculate scalability information."
152  << std::endl;
153  return(1);
154  }
155  if(profiler.ScalabilitySummary(scala_statmap,std::cout)){
156  std::cerr << comline.ProgramName()
157  << ": Error: Unabled to perform scalability summary."
158  << std::endl;
159  return(1);
160  }
161  // }
162  }
163  return(0);
164  }
165  };
166 };
167 
168 int
169 main(int argc,char *argv[])
170 {
171  return(ix::profiler::Profane(argc,argv));
172 }
int ProcessOptions()
Processes all command line tokens.
Definition: ComLine.C:330
std::string ErrorReport()
Error reporting.
Definition: ComLine.C:473
std::string GetOption(const char &s)
Get the value of an option.
Definition: ComLine.H:291
int ReadEventsFromFile(const std::string &filename)
Read serial event file.
Definition: Profiler.C:540
std::string ProgramName() const
Program name access.
Definition: ComLine.H:310
Performance profiling object.
Definition: Profiler.H:398
int ReadParallelEventFiles(const std::vector< std::string > &infiles, PEventList &par_event_list)
Read event files from parallel run.
Definition: Profiler.C:558
int ScalabilitySummary(ScalaStatMap &scala_statmap, std::ostream &Out)
Scalability analysis output for multiple parallel runs.
Definition: Profiler.C:1043
void SetErr(std::ostream *Oe)
Set errstream.
Definition: Profiler.H:496
Defines MPI-specific parallel global and program classes.
void SetOut(std::ostream *Os)
Set outstream.
Definition: Profiler.H:491
void const size_t const size_t const size_t const double const double * x
Performance Profiling interface definition.
void SummarizeSerialExecution(std::ostream &Ostr)
Profiling output for serial application.
Definition: Profiler.C:393
std::vector< std::string > GetArgs() const
Argument access.
Definition: ComLine.H:314
std::string _description
application description.
Definition: ComLine.H:73
void Initialize()
virtual function for program specific Initialization.
Definition: profane.C:31
int PopulateScalaMap(ScalaMap &scala_map, ScalaStatMap &scala_statmap, bool is_scaled)
Build scalability stats for multiple parallel runs.
Definition: Profiler.C:902
int main(int argc, char *argv[])
Definition: profane.C:169
std::map< unsigned int, scalability_stats > ScalaStatMap
Definition: Profiler.H:370
void AddOption(char s, const std::string &l, int=0)
User interface to describe simple option.
Definition: ComLine.C:295
ComLineObject for profane.
Definition: profane.C:25
ComLineObject header.
ProfaneComLine(const char *args[])
Definition: profane.C:28
int Profane(int argc, char *argv[])
The performance analysis post processor.
Definition: profane.C:62
std::string LongUsage()
Generate long usage string.
Definition: ComLine.C:188
Command line processing.
Definition: ComLine.H:62
std::list< std::pair< unsigned int, std::list< Event > > > PEventList
Definition: Profiler.H:368
int SummarizeParallelExecution(std::ostream &Ostr, std::ostream &Ouf, PEventList &parallel_event_list)
Profiling output for single parallel run.
Definition: Profiler.C:593
void AddArgument(const std::string &a, int reqd=0)
User interface to describe an application argument.
Definition: ComLine.H:183
int ReadConfig(const std::string &fname)
Read configuration from file.
Definition: Profiler.C:364
std::map< unsigned int, PStatMap > ScalaMap
Definition: Profiler.H:367
ComLineObject()
Default constructor.
Definition: ComLine.H:102
void AddHelp(char s, const std::string &help)
Specify usage for an option.
Definition: ComLine.H:227
void AddArgHelp(const std::string &a, const std::string &help)
Specify the usage info for application argument.
Definition: ComLine.H:197
int ReadSummaryFiles(const std::vector< std::string > &input_files, ScalaMap &scala_map)
Read summary files from multiple parallel runs.
Definition: Profiler.C:819
std::string ShortUsage()
Generate short usage string.
Definition: ComLine.C:244