crown  1.0.0
src/CrownMapping.cpp
Go to the documentation of this file.
00001 /*
00002  Copyright 2015 Nicolas Melot
00003 
00004  This file is part of Pelib.
00005 
00006  Pelib 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  Pelib 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 Pelib. If not, see <http://www.gnu.org/licenses/>.
00018 */
00019 
00020 #include <pelib/Vector.hpp>
00021 
00022 #include <pelib/Scalar.hpp>
00023 #include <pelib/Vector.hpp>
00024 #include <pelib/Set.hpp>
00025 
00026 #include <crown/CrownException.hpp>
00027 #include <crown/CrownAllocationFastest.hpp>
00028 #include <crown/CrownMapping.hpp>
00029 
00030 #ifdef debug
00031 #undef debug
00032 #endif
00033 
00034 #define debug(var) cout << "[" << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "] " << #var << " = \"" << (var) << "\"" << endl;
00035 
00036 using namespace pelib;
00037 using namespace crown;
00038 using namespace std;
00039 
00040 void
00041 CrownMapping::initialize(const CrownAllocation *alloc)
00042 {
00043         if(alloc == NULL)
00044         {
00045                 this->alloc = new CrownAllocationFastest(0, showOutput, showError);
00046         }
00047         else
00048         {
00049                 this->alloc = alloc->clone();
00050         }
00051 }
00052 
00053 CrownMapping::CrownMapping(const CrownConfig *config, const CrownAllocation *alloc, bool showOutput, bool showError): CrownScheduler(config, showOutput, showError)
00054 {
00055         initialize(alloc);
00056 }
00057 
00058 CrownMapping::CrownMapping(const Algebra &param, const CrownConfig *config, const CrownAllocation *alloc, bool showOutput, bool showError): CrownScheduler(param, config, showOutput, showError)
00059 {
00060         initialize(alloc);
00061 }
00062 
00063 CrownMapping::CrownMapping(const Taskgraph &tg, const Platform &pt, const Algebra &param, const CrownConfig *config, const CrownAllocation *alloc, bool showOutput, bool showError): CrownScheduler(tg, pt, param, config, showOutput, showError)
00064 {
00065         initialize(alloc);
00066 }
00067 
00068 CrownMapping::CrownMapping(const CrownMapping &src) : CrownScheduler(src.tg, src.pt, src.param, src.config, src.showOutput, src.showError)
00069 {
00070         initialize(src.alloc);
00071 }
00072 
00073 CrownMapping::~CrownMapping()
00074 {
00075         delete this->alloc;
00076 }
00077 
00078 Schedule
00079 CrownMapping::schedule(const Taskgraph &tg, const Platform &pt, std::map<const string, double> &statistics) const
00080 {
00081         return schedule(tg, pt, param, statistics);
00082 }
00083 
00084 Schedule
00085 CrownMapping::schedule(const Taskgraph &tg, const Platform &pt, const Algebra &param, std::map<const string, double> &statistics) const
00086 {
00087         // Take task names apart
00088         Algebra taskgraph = tg.buildAlgebra(pt);
00089         Vector<int, string> name = *taskgraph.find<Vector<int, string> >("name");
00090         taskgraph.remove("name");
00091 
00092         Algebra p = param.merge(config->configure(tg, pt, param, statistics));
00093         p = solve(taskgraph, pt.buildAlgebra(), p, statistics);
00094 
00095         // Put back task names
00096         p.insert(new Vector<int, string>(name));
00097 
00098         p = crownToSchedule(p);
00099         p = Schedule::addStartTime(p, tg, pt);
00100         Schedule sched(getShortDescription(), tg.getName(), p);
00101         return sched;
00102 }
00103 
00104 Algebra
00105 CrownMapping::solve(const Algebra &tg, const Algebra &pt, const pelib::Algebra &param, std::map<const std::basic_string<char>, double> &stats) const
00106 {
00107         Algebra input = tg;
00108         input = input.merge(pt);
00109         input = input.merge(param);
00110 
00111         input = this->alloc->allocate(input, stats);
00112         input = this->map(input, stats);
00113 
00114         // Make up a frequency vector with minimal frequency
00115         std::map<int, float> freq;
00116         for(int i = 1; i <= tg.find<Scalar<float> >("n")->getValue(); i++)
00117         {
00118                 freq.insert(pair<int, float>(i, *pt.find<Set<float> >("F")->getValues().begin()));
00119         }
00120         Vector<int, float> frequency("frequency", freq);
00121         input.insert(&frequency);
00122 
00123         return input;
00124 }
00125