pelib
2.0.0
|
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 00021 #include <iostream> 00022 00023 #include <pelib/parser.h> 00024 #include <pelib/output.h> 00025 00026 #include <pelib/AmplOutput.hpp> 00027 #include <pelib/AmplInput.hpp> 00028 #include <pelib/Matrix.hpp> 00029 #include <pelib/Task.hpp> 00030 #include <pelib/Link.hpp> 00031 #include <pelib/Taskgraph.hpp> 00032 00033 using namespace std; 00034 using namespace pelib; 00035 00036 #ifdef __cplusplus 00037 extern "C" { 00038 #endif 00039 00040 #ifndef debug 00041 #define debug(expr) cerr << "[" << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "] " << #expr << " = \"" << expr << "\"." << endl; 00042 #endif 00043 00044 // /!\ the content of argv is freed after this function is run 00045 pelib::Record* 00046 pelib_parse(std::istream& cin, size_t argc, char **argv) 00047 { 00048 using namespace std; 00049 using namespace pelib; 00050 00051 AmplOutput ampl_output(AmplOutput::intFloatHandlers()); 00052 AmplInput ai(AmplInput::floatHandlers()); 00053 00054 /* 00055 std::cout << std::setprecision(6) 00056 << std::setiosflags(std::ios::fixed) 00057 << std::setiosflags(std::ios::showpoint); 00058 */ 00059 00060 Algebra data = ai.parse(cin); 00061 const Matrix<int, int, float> *taskworkcomm = data.find<Matrix<int, int, float> >("taskworkcomm"); 00062 set<Task> tasks; 00063 set<Link> links; 00064 00065 for(map<int, map<int, float> >::const_iterator i = taskworkcomm->getValues().begin(); i != taskworkcomm->getValues().end(); i++) 00066 { 00067 stringstream estr; 00068 estr << "task_" << i->first; 00069 Task t(estr.str()); 00070 stringstream efficiency; 00071 00072 float work = i->second.find(1)->second; 00073 float comm = i->second.find(2)->second; 00074 00075 t.setWorkload(work); 00076 efficiency << "fml: p == 1 ? 1 : p <= W ? tau / (tau + p * "; 00077 if(isfinite(comm)) 00078 { 00079 t.setMaxWidth(std::numeric_limits<double>::infinity()); 00080 efficiency << comm; 00081 } 00082 else 00083 { 00084 t.setMaxWidth(1); 00085 efficiency << std::numeric_limits<float>::max(); 00086 } 00087 efficiency << ") : 1e-6"; 00088 t.setEfficiencyString(efficiency.str()); 00089 00090 tasks.insert(t); 00091 } 00092 00093 char* autname; 00094 if(argc > 1) 00095 { 00096 autname = argv[1]; 00097 } 00098 else 00099 { 00100 autname = (char*)string("converted_from_streamit").c_str(); 00101 } 00102 Taskgraph *tg = new Taskgraph(tasks, links); 00103 tg->setName(autname); 00104 tg->setDeadlineCalculator("class:synthetic"); 00105 00106 return tg; 00107 } 00108 00109 void 00110 pelib_delete(Record *rec) 00111 { 00112 delete rec; 00113 } 00114 00115 #ifdef __cplusplus 00116 } 00117 #endif 00118