Skip to content

Commit

Permalink
added ability to set the output file path
Browse files Browse the repository at this point in the history
  • Loading branch information
Darrell A. Ross committed Jan 20, 2017
1 parent 91aca1d commit 077ce08
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 11 deletions.
35 changes: 28 additions & 7 deletions hwk1/hwk1/ProblemGroups.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ int GLOBAL_ARRAY_WIDTH = 1024;
int GLOBAL_ARRAY_HEIGHT = 1024;
bool SKIP_VERIFICATION = false;
bool PRINT_TO_FILE = false;
std::string RESULTS_FILE = "results.txt";

ResultsStruct::ResultsStruct()
: WindowsRunTime(0.0)
Expand All @@ -20,10 +21,21 @@ ResultsStruct::ResultsStruct()
{
}

void PrintToFile(const std::vector<ResultsStruct*>& results)
// Ensure memory is cleared
ResultsList::~ResultsList()
{
while (!empty())
{
ResultsStruct* s = this->back();
this->pop_back();
delete s;
}
}

void PrintToFile(const ResultsList& results)
{
std::ofstream outfile;
outfile.open("hw2_results.txt", std::ios_base::app); //<@TODO Change to take name of output file or allow providing it as input control
outfile.open(RESULTS_FILE, std::ios_base::app);
if (results.empty())
{
outfile << "No results";
Expand All @@ -36,7 +48,7 @@ void PrintToFile(const std::vector<ResultsStruct*>& results)
int num = 0;
outfile << results.front()->Annotation << std::endl;
outfile << "Run#, WindowsTime, OpenCLTime" << std::endl;
for (std::vector<ResultsStruct*>::const_iterator i = results.begin(), e = results.end(); i != e; ++i, ++num)
for (ResultsList::const_iterator i = results.begin(), e = results.end(); i != e; ++i, ++num)
{
totalWindowsTimes += (*i)->WindowsRunTime;
totalOpenCLTimes += (*i)->OpenCLRunTime;
Expand All @@ -48,15 +60,15 @@ void PrintToFile(const std::vector<ResultsStruct*>& results)
outfile << "Windows Average: " << WindowsAvg << "; OpenCL Average: " << OpenCLAvg << std::endl;
}

void PrintResults(const std::vector<ResultsStruct*>& results)
void PrintResults(const ResultsList& results)
{
if (results.empty())
return;

double totalWindowsTimes = 0.0;
double totalOpenCLTimes = 0.0;
int num = 0;
for (std::vector<ResultsStruct*>::const_iterator i = results.begin(), e = results.end(); i != e; ++i, ++num)
for (ResultsList::const_iterator i = results.begin(), e = results.end(); i != e; ++i, ++num)
{
totalWindowsTimes += (*i)->WindowsRunTime;
totalOpenCLTimes += (*i)->OpenCLRunTime;
Expand All @@ -83,7 +95,7 @@ int ProblemGroup::operator()(int problem)
return 0;
}

std::vector<ResultsStruct*> results;
ResultsList results;
int retVal = 0;
const size_t runCount = (GroupNum() == 0 ? 1 : dmath::RUN_COUNT);
for (int i = 0; i < runCount; i++)
Expand All @@ -101,7 +113,6 @@ int ProblemGroup::operator()(int problem)
PrintResults(results);
}

// @TODO verify that results vector destructing deletes members
return retVal;
}
GroupManager::GroupManager(const std::string& name)
Expand Down Expand Up @@ -168,6 +179,7 @@ int GroupManager::Run()
/////////// Input Gathering /////////////
ProblemGroup* GroupManagerInputControlFactory()
{
// @TODO Modify structure so that input control annotation can print current value - will need a way to fetch current value - maybe mini-IOC?
int num = 0;
ProblemGroup* InputControl = new ProblemGroup(0, "Input Control");
InputControl->problems_[++num] = new Problem(&SetValueM, "Set M Value (defaults to 1024)");
Expand All @@ -176,6 +188,7 @@ ProblemGroup* GroupManagerInputControlFactory()
InputControl->problems_[++num] = new Problem(&RunCount, "Set the number of runs (defaults to 1)");
InputControl->problems_[++num] = new Problem(&ComparisonThreshold, "Set minimum difference for verifications.");
InputControl->problems_[++num] = new Problem(&PrintResultsToFile, "Set times to print to file (defaults to 0).");
InputControl->problems_[++num] = new Problem(&SetResultsFile, "Set the file path for saving results.");
return InputControl;
}

Expand Down Expand Up @@ -221,3 +234,11 @@ int PrintResultsToFile(ResultsStruct* results)
PRINT_TO_FILE = (i == 1);
return 0;
}
int SetResultsFile(ResultsStruct* results)
{
std::cout << "Enter path to output file to (currently " << RESULTS_FILE << "): ";
std::string s(RESULTS_FILE);
std::cin >> s;
RESULTS_FILE = s;
return 0;
}
17 changes: 13 additions & 4 deletions hwk1/hwk1/ProblemGroups.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
extern int GLOBAL_ARRAY_WIDTH;
extern int GLOBAL_ARRAY_HEIGHT;
extern bool SKIP_VERIFICATION;

extern bool PRINT_TO_FILE;
extern std::string RESULTS_FILE;

struct ResultsStruct
{
Expand All @@ -15,8 +16,15 @@ struct ResultsStruct
bool HasOpenCLRunTime;
std::string Annotation;
};
void PrintToFile(const std::vector<ResultsStruct*>& results);
void PrintResults(const std::vector<ResultsStruct*>& results);

class ResultsList : public std::vector<ResultsStruct*>
{
public:
~ResultsList();
};

void PrintToFile(const ResultsList& results);
void PrintResults(const ResultsList& results);

////////////// PROBLEMS
class Problem
Expand Down Expand Up @@ -73,4 +81,5 @@ int SetValueN(ResultsStruct* results);
int SkipVerify(ResultsStruct* results);
int RunCount(ResultsStruct* results);
int ComparisonThreshold(ResultsStruct* results);
int PrintResultsToFile(ResultsStruct* results);
int PrintResultsToFile(ResultsStruct* results);
int SetResultsFile(ResultsStruct* results);

0 comments on commit 077ce08

Please sign in to comment.