crown  1.0.0
src/patmos2benchmark.cpp
Go to the documentation of this file.
00001 /*
00002  Copyright 2015 Nicolas Melot
00003 
00004  This file is part of Crown.
00005 
00006  Crown is free software: you can redistribute it and/or modify
00007  it under the terms of the GNU General Public License as published by
00008  the Free Software Foundation, either version 3 of the License, or
00009  (at your option) any later version.
00010 
00011  Crown is distributed in the hope that it will be useful,
00012  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00014  GNU General Public License for more details.
00015 
00016  You should have received a copy of the GNU General Public License
00017  along with Crown. If not, see <http://www.gnu.org/licenses/>.
00018 
00019 */
00020 
00021 
00022 #include <iostream>
00023 #include <cstdlib>
00024 #include <fstream>
00025 #include <string>
00026 #include <boost/regex.hpp>
00027 #include <iomanip>
00028 
00029 #include <pelib/AmplInput.hpp>
00030 #include <pelib/AmplOutput.hpp>
00031 
00032 #include <pelib/AmplInputData.hpp>
00033 #include <pelib/AmplInputScalar.hpp>
00034 #include <pelib/AmplInputVector.hpp>
00035 #include <pelib/AmplInputMatrix.hpp>
00036 
00037 #include <pelib/AmplOutputScalar.hpp>
00038 #include <pelib/AmplOutputVector.hpp>
00039 #include <pelib/AmplOutputMatrix.hpp>
00040 
00041 using namespace pelib;
00042 
00043 Algebra
00044 parse(AlgebraParser &parser, std::istream &input)
00045 {
00046         Algebra rec;
00047         
00048         try {
00049                 rec = parser.parse(input);
00050         } catch(ParseException &e)
00051         {
00052                 std::cerr << e.what() << std::endl;
00053         }
00054 
00055         return rec;
00056 }
00057 
00058 int
00059 main(int argc, char **argv)
00060 {
00061         AmplInput input(AmplInput::floatHandlers());
00062         AmplOutput output(AmplOutput::floatHandlers());
00063         Algebra rec;
00064 
00065         // We use an AMPL output, output format
00066         AlgebraOutput &out = input;
00067 
00068         // Set floating point var output format to fixed at 7 digits
00069         std::cout << std::setprecision(6)                                                                                                        
00070         << std::setiosflags(std::ios::fixed)                                                                                                     
00071         << std::setiosflags(std::ios::showpoint);
00072 
00073         // Open input file
00074         std::ifstream myfile;
00075         myfile.open (argv[1], std::ios::in);
00076 
00077         // Load input file
00078         rec = parse(input, myfile);
00079 
00080         // Close input file
00081         myfile.close();
00082 
00083         //out.dump(std::cout, rec);
00084         std::cout << "# Number of tasks" << std::endl;
00085         out.dump(std::cout, rec.find<Scalar<float> >("n"));
00086         std::cout << std::endl << "# Tasks max width" << std::endl;
00087         out.dump(std::cout, rec.find<Vector<int, float> >("Wi"));
00088         std::cout << std::endl << "# Tasks workload" << std::endl;
00089         out.dump(std::cout, rec.find<Vector<int, float> >("Tau"));
00090 
00091         // Scale max processors up to MAX_CORES
00092         std::cout << std::endl << "# Tasks efficiency" << std::endl;
00093         std::map<int, std::map<int, float> > map_e = rec.find<Matrix<int, int, float> >("e")->getValues();
00094 
00095         for(std::map<int, std::map<int, float> >::iterator i = map_e.begin(); i != map_e.end(); i++)
00096         {
00097                 for(int j = 1; j <= MAX_CORES; j++)
00098                 {
00099                         // Try to fetch e for j processors
00100                         std::map<int, float>::iterator e_iter = i->second.find(j);
00101 
00102                         // If there is no such value, then the iterator is end()
00103                         if(e_iter == i->second.end())
00104                         {
00105                                 i->second.insert(std::pair<int, float>(j, DEFAULT_E));
00106                         }
00107                 }
00108         }
00109         Matrix<int, int, float> e("e", map_e);
00110         out.dump(std::cout, &e);
00111 
00112 #if 0
00113         // Output one raw value in parameters b, Wi and e
00114         std::cout << rec.find<Scalar<float> >("b")->getValue() << std::endl;
00115         std::cout << rec.find<Vector<int, float> >("Wi")->getSize() << std::endl;
00116         std::cout << rec.find<Matrix<int, int, float> >("e")->getRowSize() << std::endl;
00117 
00118         // Extract, rename and output a few parameters
00119         Scalar<float> nn(rec.find<Scalar<float> >("n"));
00120         nn.setName("nn");
00121         out.dump(std::cout, &nn);
00122 
00123         Vector<int, float> yy(rec.find<Vector<int, float> >("Wi"));
00124         yy.setName("yy");
00125         out.dump(std::cout, &yy);
00126         
00127         Matrix<int, int, float> ee(rec.find<Matrix<int, int, float> >("e"));
00128         ee.setName("ee");
00129         out.dump(std::cout, &ee);
00130 #endif
00131 
00132         return EXIT_SUCCESS;
00133 }
00134