crown
1.0.0
|
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 #include <pelib/Scalar.hpp> 00022 #include <pelib/argument_parsing.hpp> 00023 #include <pelib/dl.h> 00024 00025 #include <crown/crown-scheduler.hpp> 00026 #include <crown/CrownMappingILPBalanced.hpp> 00027 00028 #ifdef debug 00029 #undef debug 00030 #endif 00031 00032 #define debug(var) cout << "[" << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "] " << #var << " = \"" << (var) << "\"" << endl; 00033 00034 using namespace std; 00035 using namespace pelib; 00036 using namespace crown; 00037 00038 #ifdef __cplusplus 00039 extern "C" { 00040 #endif 00041 00042 struct args 00043 { 00044 double alpha, eta, zeta, kappa; 00045 bool showError, showOutput; 00046 pelib_argument_stream alloc, config; 00047 00048 }; 00049 typedef struct args args_t; 00050 00051 static args_t 00052 parse(char **args) 00053 { 00054 args_t out; 00055 out.showError = false; 00056 out.showOutput = false; 00057 out.alpha = 3; 00058 out.zeta = 0.649; 00059 out.eta = 0.018611; 00060 out.kappa = 52.639161335; 00061 pelib_argument_stream_init(&out.alloc); 00062 pelib_argument_stream_init(&out.config); 00063 00064 for(; args[0] != NULL; args++) 00065 { 00066 if(strcmp(args[0], "--show-stdout") == 0) 00067 { 00068 out.showOutput = true; 00069 continue; 00070 } 00071 if(strcmp(args[0], "--show-stderr") == 0) 00072 { 00073 out.showError = true; 00074 continue; 00075 } 00076 if(strcmp(args[0], "--alpha") == 0) 00077 { 00078 args++; 00079 stringstream str(args[0]); 00080 str >> out.alpha; 00081 continue; 00082 } 00083 if(strcmp(args[0], "--eta") == 0) 00084 { 00085 args++; 00086 stringstream str(args[0]); 00087 str >> out.eta; 00088 continue; 00089 } 00090 if(strcmp(args[0], "--zeta") == 0) 00091 { 00092 args++; 00093 stringstream str(args[0]); 00094 str >> out.zeta; 00095 continue; 00096 } 00097 if(strcmp(args[0], "--kappa") == 0) 00098 { 00099 args++; 00100 stringstream str(args[0]); 00101 str >> out.kappa; 00102 continue; 00103 } 00104 if(strcmp(args[0], "--allocation") == 0) 00105 { 00106 args++; 00107 args += pelib_argument_stream_parse(args, &out.alloc) - 1; 00108 continue; 00109 } 00110 if(strcmp(args[0], "--config") == 0) 00111 { 00112 args++; 00113 args += pelib_argument_stream_parse(args, &out.config) - 1; 00114 continue; 00115 } 00116 } 00117 00118 return out; 00119 } 00120 00121 const CrownMapping* 00122 crown_mapping(size_t argc, char **argv) 00123 { 00124 args_t args = parse(argv); 00125 void *libAlloc = load_lib(args.alloc.library); 00126 void *libConfig = load_lib(args.config.library); 00127 CrownAllocation* (*allocate)(size_t argc, char **argv); 00128 CrownConfig* (*conf)(size_t argc, char **argv); 00129 CrownAllocation* alloc = NULL; 00130 CrownConfig *config = NULL; 00131 00132 // Load crown allocation 00133 if(args.alloc.library != NULL) 00134 { 00135 void *libConfig = load_lib(args.alloc.library); 00136 allocate = (CrownAllocation* (*)(size_t argc, char **argv))load_function(libConfig, "crown_allocation"); 00137 alloc = allocate(args.alloc.argc, args.alloc.argv); 00138 } 00139 00140 // Load crown config 00141 if(args.config.library != NULL) 00142 { 00143 void *libConfig = load_lib(args.config.library); 00144 conf = (CrownConfig* (*)(size_t argc, char **argv))load_function(libConfig, "crown_config"); 00145 config = conf(args.config.argc, args.config.argv); 00146 } 00147 00148 // Convert solver output to general schedule 00149 CrownMapping *map = new CrownMappingILPBalanced(config, alloc, args.showOutput, args.showError); 00150 00151 // Destroy object instances by libraries 00152 if(args.alloc.library != NULL) 00153 { 00154 void (*del)(CrownAllocation *) = (void (*)(CrownAllocation*))load_function(libAlloc, "crown_delete_algebra"); 00155 del(alloc); 00156 destroy_lib(libAlloc); 00157 } 00158 00159 // Destroy object instances by libraries 00160 if(args.config.library != NULL) 00161 { 00162 void (*del)(CrownConfig *) = (void (*)(CrownConfig*))load_function(libConfig, "crown_delete_config"); 00163 del(config); 00164 destroy_lib(libConfig); 00165 } 00166 00167 return map; 00168 } 00169 00170 const CrownScheduler* 00171 crown_scheduler(size_t argc, char **argv, const CrownScheduler *composite) 00172 { 00173 return crown_mapping(argc, argv); 00174 } 00175 00176 void 00177 crown_delete_algebra(pelib::Algebra *alg) 00178 { 00179 delete alg; 00180 } 00181 00182 #ifdef __cplusplus 00183 } 00184 #endif