crown
1.0.0
|
00001 // The following definitions might be exchanged for others, 00002 // when integrating the following code into the framework. 00003 // The code implements a greedy heuristic to loadbalance the tasks 00004 // over cores such that the l2-norm of the load vector is minimized. 00005 // This should also minimize the l3-norm of the load vector. 00006 // J. Keller, July 14, 2014 00007 00008 #include <stdio.h> 00009 #include <stdlib.h> 00010 #include <string.h> 00011 #include <math.h> 00012 #include <iostream> 00013 #include <sstream> 00014 #include <fstream> 00015 #include <cstdlib> 00016 #include <set> 00017 #include <map> 00018 00019 #include <crown/allocation.h> 00020 #include <crown/mapping.h> 00021 #include <crown/CrownConfigBinary.hpp> 00022 #include <crown/CrownMappingILP.hpp> 00023 #include <crown/CrownException.hpp> 00024 00025 #include <pelib/AmplSolver.hpp> 00026 #include <pelib/Scalar.hpp> 00027 #include <pelib/Vector.hpp> 00028 #include <pelib/Matrix.hpp> 00029 #include <pelib/Set.hpp> 00030 #include <pelib/Schedule.hpp> 00031 #include <pelib/ParseException.hpp> 00032 #include <pelib/Algebra.hpp> 00033 00034 #ifdef debug 00035 #undef debug 00036 #endif 00037 00038 #if 01 00039 #define debug(var) cout << "[" << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "] " << #var << " = \"" << var << "\"" << endl; 00040 #else 00041 #define debug(var) 00042 #endif 00043 00044 using namespace std; 00045 using namespace pelib; 00046 using namespace pelib::crown; 00047 00048 extern char _binary_mapping_mod_start; 00049 extern char _binary_mapping_mod_end; 00050 extern char _binary_mapping_run_start; 00051 extern char _binary_mapping_run_end; 00052 00053 CrownMappingILP::CrownMappingILP(const CrownConfig *config, const CrownAllocation *alloc, bool showOutput, bool showError) : CrownMapping(config, alloc, showOutput, showError) 00054 { 00055 /* Do nothing else */ 00056 } 00057 00058 CrownMappingILP::CrownMappingILP(const Algebra ¶m, const CrownConfig *config, const CrownAllocation *alloc, bool showOutput, bool showError): CrownMapping(param, config, alloc, showOutput, showError) 00059 { 00060 /* Do nothing else */ 00061 } 00062 00063 CrownMappingILP::CrownMappingILP(const Taskgraph &tg, const Platform &pt, const Algebra ¶m, const CrownConfig *config, const CrownAllocation *alloc, bool showOutput, bool showError): CrownMapping(tg, pt, param, config, alloc, showOutput, showError) 00064 { 00065 /* Do nothing else */ 00066 } 00067 00068 Algebra 00069 CrownMappingILP::map(const Algebra &alg, std::map<const string, double> &stats) const 00070 { 00071 // Build input collection 00072 std::map<const string, const Algebra> data; 00073 data.insert(pair<const string, const Algebra>("parameters.dat", alg)); 00074 00075 // Build model and run scripts input streams 00076 stringstream model(string(&_binary_mapping_mod_start, &_binary_mapping_mod_end)); 00077 stringstream run(string(&_binary_mapping_run_start, &_binary_mapping_run_end)); 00078 00079 // Run the solver 00080 const Algebra *solution = AmplSolver(model, string("model.mod"), run, data, showOutput, showError).solve(stats); 00081 00082 // Insert back tasks' names 00083 std::map<const string, double>::iterator ii = stats.find("time"); 00084 if(ii != stats.end()) 00085 { 00086 double time = ii->second; 00087 stats.erase(ii); 00088 stats.insert(pair<const string, double>("time_mapping", time)); 00089 } 00090 00091 Algebra sol = *solution; 00092 delete solution; 00093 return sol; 00094 } 00095 00096 float 00097 CrownMappingILP::complexity(const Taskgraph &tg, const Platform &pt, const Algebra ¶m, const CrownConfig* config) const 00098 { 00099 return 0; 00100 } 00101 00102 float 00103 CrownMappingILP::complexity(const pelib::Algebra &input) const 00104 { 00105 return 0; 00106 } 00107 00108 std::string 00109 CrownMappingILP::getShortDescription() const 00110 { 00111 stringstream ss; 00112 std::streamsize p = ss.precision(); 00113 ss.precision(4); 00114 ss << "ILP"; 00115 ss.precision(p); 00116 00117 return ss.str(); 00118 } 00119 00120 CrownMapping* 00121 CrownMappingILP::clone() const 00122 { 00123 return new CrownMappingILP(*this); 00124 } 00125