PlasCom2  1.0
XPACC Multi-physics simluation application
PerfPlot.C
Go to the documentation of this file.
1 #include "PerfPlot.H"
2 
3 
4 void SetupOptions(CommandLineType &inComLine)
5 {
6  inComLine.AddOption('c',"config",2,"configfile");
7  inComLine.AddOption('d',"display");
8  inComLine.AddOption('e',"efficiency");
9  inComLine.AddOption('f',"files");
10  inComLine.AddOption('g',"gnuplot",2,"batfile");
11  inComLine.AddOption('h',"help");
12  inComLine.AddOption('o',"outfile",2,"outfile");
13  inComLine.AddOption('p',"plot",2,"batfile");
14  inComLine.AddOption('s',"scalability",2,"outfile");
15  inComLine.AddOption('m',"gridmode");
16  inComLine.AddOption('w',"weak");
17  inComLine.AddOption('l',"linear");
18  inComLine.AddArgument("timing_output_list",1);
19  inComLine.AddHelp('c',"Set configuration file name to <configfile>.");
20  inComLine.AddHelp('d',"Use GNUPlot to display plots to screen.");
21  inComLine.AddHelp('e',"Set efficiency mode for plotting parallel efficiency.");
22  inComLine.AddHelp('f',"Use GNUPlot to create plot image files.");
23  inComLine.AddHelp('g',"Set output gnuplot bat file root name to <batfile>.");
24  inComLine.AddHelp('h',"This long, detailed help message.");
25  inComLine.AddHelp('l',"Sets linear scale on scalability plots.");
26  inComLine.AddHelp('m',"Sets \"grid mode\"; performance based on number of points in grid.");
27  inComLine.AddHelp('o',"Set output data file name to <outfile>.");
28  inComLine.AddHelp('p',"Set output gnuplot scalability bat file root name to <batfile>.");
29  inComLine.AddHelp('s',"Set output scalability data file name to <outfile>.");
30  inComLine.AddHelp('w',"Sets weak mode for scalability plots.");
31  inComLine.AddArgHelp("timing_output_list","Space-delimited list of PlasComCM timer outputs.");
32  inComLine.SetDescription("Utility for creating performance data and plots for parallel applications.");
33 }
34 
35 int main(int argc,char *argv[])
36 {
37  CommandLineType timingCommandLine((const char **)argv);
38  SetupOptions(timingCommandLine);
39  int comLineError = timingCommandLine.ProcessOptions();
40 
41  if(!argv[1]){
42  std::cout << timingCommandLine.ShortUsage() << std::endl;
43  return(1);
44  } else if(!timingCommandLine.GetOption("help").empty()){
45  std::cout << timingCommandLine.LongUsage() << std::endl;
46  return(0);
47  } else if (comLineError){
48  std::cout << timingCommandLine.ErrorReport() << std::endl
49  << timingCommandLine.ShortUsage() << std::endl;
50  return(1);
51  }
52 
53  bool displayPlots = !timingCommandLine.GetOption("display").empty();
54  bool createPlotFiles = !timingCommandLine.GetOption("files").empty();
55  bool linearScale = !timingCommandLine.GetOption("linear").empty();
56  bool weakMode = !timingCommandLine.GetOption("weak").empty();
57  bool gridMode = !timingCommandLine.GetOption("gridmode").empty();
58  bool effMode = !timingCommandLine.GetOption("efficiency").empty();
59 
60  std::string configFileName(timingCommandLine.GetOption("config"));
61  ConfigType timingConfig;
62  // SetConfigurationDefaults(timingConfig);
63  if(!configFileName.empty()){
64  std::ifstream configFile;
65  if(OpenFile(configFile,configFileName)){
66  std::cerr << "Could not open configuration file, "
67  << configFileName << "." << std::endl;
68  return(1);
69  }
70  configFile >> timingConfig;
71  configFile.close();
72  }
73  std::string platformName(timingConfig.GetValue("PlatformName"));
74 
75  std::string outFileName(timingCommandLine.GetOption("outfile"));
76  if(outFileName.empty())
77  outFileName = "TimingData.txt";
78 
79  std::string scalaFileName(timingCommandLine.GetOption("scalability"));
80  if(scalaFileName.empty())
81  scalaFileName = "ScalabilityData.txt";
82 
83  std::string batFileName(timingCommandLine.GetOption("gnuplot"));
84  if(batFileName.empty())
85  batFileName = "plottiming.gp";
86 
87  std::string scalaBatFileName(timingCommandLine.GetOption("plot"));
88  if(scalaBatFileName.empty())
89  scalaBatFileName = "plotscalability.gp";
90 
91  std::vector<std::string> timingFileNames(timingCommandLine.GetArgs());
92  int numRuns = timingFileNames.size();
93 
94  derivedtimers derivedTimers;
95  SetupDerivedTimers(derivedTimers,timingConfig);
96  int numDerivedTimers = derivedTimers.size();
97 
98  timerlist excludedTimers;
99  SetupExcludedTimers(excludedTimers,timingConfig);
100 
101  timersettings timerSettings;
102  SetupTimerSettings(timerSettings,timingConfig);
103  int dataColumn = timerSettings.dataColumn;
104  if(weakMode)
105  timerSettings.weakMode = true;
106  if(gridMode)
107  timerSettings.gridMode = true;
108  if(effMode)
109  timerSettings.effMode = true;
110 
111  std::vector<struct pcrun> pcRuns(numRuns);
112  timerlist allRoutineNames;
113 
114  // Loop through all input timing file names
115  std::vector<std::string>::iterator timingFileIterator = timingFileNames.begin();
116  while(timingFileIterator != timingFileNames.end()){
117 
118  int runIndex = timingFileIterator - timingFileNames.begin();
119  std::string &timingFileName(*timingFileIterator++);
120 
121  // open timing file
122  std::ifstream timingFile;
123  if(OpenFile(timingFile,timingFileName)){
124  std::cerr << "Could not open timing file, "
125  << timingFileName << "." << std::endl;
126  return(1);
127  }
128 
129  // get info about the specific run in the timing file
130  PopulateRunInfo(pcRuns[runIndex].pcRunInfo,timingFile);
131  // if(pcRuns[runIndex].pcRunInfo.platformName.empty())
132  // pcRuns[runIndex].pcRunInfo.platformName = platformName;
133 
134  // populate the timer values
135  pcruntimes runTimes;
136  ReadTimers(runTimes,timingFile,dataColumn);
137  timingFile.close();
138 
139  // massage the timers according to the derived/excluded
140  // timers and settings
141  pctimervalue timingDelta;
142  pcRuns[runIndex].pcRunTimes = ProcessRun(pcRuns[runIndex].pcRunInfo,runTimes,derivedTimers,
143  excludedTimers,timerSettings,timingDelta);
144 
145  // Keep track of all important routine names across all runs
146  pcruntimes::iterator runIt = pcRuns[runIndex].pcRunTimes.begin();
147  while(runIt != pcRuns[runIndex].pcRunTimes.end())
148  allRoutineNames.push_back(runIt++->first);
149  allRoutineNames.sort();
150  allRoutineNames.unique();
151 
152  // report the difference between the tracked timers
153  // and the application runtime
154  std::cout << "Timing delta for " << timingFileName
155  << " = (" << timingDelta.min << ","
156  << timingDelta.max << ","
157  << timingDelta.mean << ")" << std::endl;
158  }
159 
160  std::ofstream outFile;
161  outFile.open(outFileName.c_str());
162  std::ostringstream outStream;
163  SummarizeTimingData(outStream,pcRuns,allRoutineNames,timerSettings);
164  outFile << outStream.str();
165  outFile.close();
166 
167  if(pcRuns.size() > 1){
168 
169  outStream.clear();
170  outStream.str("");
171  std::ofstream scalaFile;
172  scalaFile.open(scalaFileName.c_str());
173  SummarizeScalabilityData(outStream,pcRuns,allRoutineNames,timerSettings);
174  scalaFile << outStream.str();
175  scalaFile.close();
176 
177  outStream.clear();
178  outStream.str("");
179  MultiRunPlotCommands(outStream,outFileName,pcRuns,timerSettings);
180  outFile.open(batFileName.c_str());
181  outFile << outStream.str();
182  outFile.close();
183 
184  if(createPlotFiles)
185  apptools::GNUPlot(outStream.str());
186 
187  if(displayPlots){
188  outStream.clear();
189  outStream.str("");
190  MultiRunPlotCommands(outStream,outFileName,pcRuns,timerSettings,true);
191  apptools::GNUPlot(outStream.str());
192  }
193 
194  std::ofstream scalaBatFile;
195  scalaBatFile.open(scalaBatFileName.c_str());
196  outStream.clear();
197  outStream.str("");
198  SpeedUpPlotCommands(outStream,scalaFileName,allRoutineNames,pcRuns,timerSettings,false,linearScale);
199  scalaBatFile << outStream.str();
200  scalaBatFile.close();
201 
202  if(createPlotFiles)
203  apptools::GNUPlot(outStream.str());
204 
205  if(displayPlots){
206  outStream.clear();
207  outStream.str("");
208  SpeedUpPlotCommands(outStream,scalaFileName,allRoutineNames,pcRuns,timerSettings,true,linearScale);
209  apptools::GNUPlot(outStream.str());
210  }
211  } else {
212 
213  outStream.clear();
214  outStream.str("");
215  SingleRunPlotCommands(outStream,outFileName,pcRuns,0,timerSettings);
216  outFile.open(batFileName.c_str());
217  outFile << outStream.str();
218  outFile.close();
219 
220  if(createPlotFiles)
221  apptools::GNUPlot(outStream.str());
222 
223  if(displayPlots){
224  outStream.clear();
225  outStream.str("");
226  SingleRunPlotCommands(outStream,outFileName,pcRuns,0,timerSettings,true);
227  apptools::GNUPlot(outStream.str());
228  }
229 
230  }
231 
232  return(0);
233 }
void AddOption(char s, const std::string &l, int=0)
User interface to describe simple option.
Definition: AppTools.H:1025
std::string ShortUsage()
Generate short usage string.
Definition: AppTools.H:974
double max
Definition: PerfPlot.H:34
void AddHelp(char s, const std::string &help)
Specify usage for an option.
Definition: AppTools.H:576
bool weakMode
Definition: PerfPlot.H:17
void SingleRunPlotCommands(std::ostream &outStream, const std::string &dataFileName, const std::vector< struct pcrun > &pcRuns, int runIndex, const timersettings &timerSettings, bool toDisplay=false)
Definition: PerfPlot.H:149
std::vector< std::string > GetArgs() const
Argument access.
Definition: AppTools.H:663
int main(int argc, char *argv[])
Definition: PerfPlot.C:35
int dataColumn
Definition: PerfPlot.H:18
std::string GetOption(const char &s)
Get the value of an option.
Definition: AppTools.H:640
std::string LongUsage()
Generate long usage string.
Definition: AppTools.H:918
int ProcessOptions()
Processes all command line tokens.
Definition: AppTools.H:1060
void MultiRunPlotCommands(std::ostream &outStream, const std::string &dataFileName, const std::vector< struct pcrun > &pcRuns, const timersettings &timerSettings, bool toDisplay=false)
Definition: PerfPlot.H:167
bool gridMode
Definition: PerfPlot.H:20
void SetDescription(const std::string &desc)
Set description string.
Definition: AppTools.H:667
void PopulateRunInfo(pcruninfo &pcRunInfo, std::ifstream &inFile)
Definition: PerfPlot.H:551
std::map< std::string, timerlist > derivedtimers
Definition: PerfPlot.H:61
void ReadTimers(pcruntimes &routineTimes, std::ifstream &inFile, int dataColumn)
Definition: PerfPlot.H:515
int OpenFile(std::ifstream &Inf, const std::string &filename)
File opener.
Definition: AppTools.H:144
void SetupTimerSettings(timersettings &timerSettings, const ConfigType &inConfig)
Definition: PerfPlot.H:614
void SummarizeScalabilityData(std::ostream &outStream, const std::vector< struct pcrun > &pcRuns, const timerlist &timerList, const timersettings &timerSettings)
Definition: PerfPlot.H:275
std::map< std::string, struct pctimervalue > pcruntimes
Definition: PerfPlot.H:54
std::list< std::string > timerlist
Definition: PerfPlot.H:60
void SpeedUpPlotCommands(std::ostream &outStream, const std::string &dataFileName, const timerlist &timerList, const std::vector< struct pcrun > &pcRuns, const timersettings &timerSettings, bool toDisplay=false, bool linScale=false)
Definition: PerfPlot.H:198
double min
Definition: PerfPlot.H:33
double mean
Definition: PerfPlot.H:35
std::string ErrorReport()
Error reporting.
Definition: AppTools.H:1203
bool effMode
Definition: PerfPlot.H:21
void SetupDerivedTimers(derivedtimers &derivedTimers, const ConfigType &inConfig)
Definition: PerfPlot.H:661
void SummarizeTimingData(std::ostream &outStream, const std::vector< struct pcrun > &pcRuns, const timerlist &timerList, const timersettings &timerSettings)
Definition: PerfPlot.H:350
void AddArgHelp(const std::string &a, const std::string &help)
Specify the usage info for application argument.
Definition: AppTools.H:546
void SetupExcludedTimers(timerlist &excludedTimers, const ConfigType &inConfig)
Definition: PerfPlot.H:655
pcruntimes ProcessRun(const pcruninfo &pcRunInfo, const pcruntimes &rawRunTimes, const derivedtimers &derivedTimers, const timerlist &excludedTimers, const timersettings &timerSettings, pctimervalue &timingDelta)
Definition: PerfPlot.H:442
void AddArgument(const std::string &a, int reqd=0)
User interface to describe an application argument.
Definition: AppTools.H:532
Command line processing.
Definition: AppTools.H:411
int GNUPlot(const std::string &commands)
Simple GnuPlot plotter util.
Definition: AppTools.H:18
void SetupOptions(CommandLineType &inComLine)
Definition: PerfPlot.C:4