From: Arnaud Giersch Date: Tue, 7 Dec 2010 15:20:25 +0000 (+0100) Subject: Wip... X-Git-Tag: v0.1~254 X-Git-Url: https://bilbo.iut-bm.univ-fcomte.fr/and/gitweb/loba.git/commitdiff_plain/d47d44b2ed067c834ef210ad544512e7581a1c8e Wip... * rename parameters -> options * add cost_func * add process::compute * add core files in .gitignore --- diff --git a/.gitignore b/.gitignore index feed568..8d5a012 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,8 @@ *~ *.d *.o +core +vgcore.* localversion loba simple_async diff --git a/Makefile b/Makefile index 0653492..4b0df07 100644 --- a/Makefile +++ b/Makefile @@ -22,15 +22,17 @@ LDFLAGS += -Wl,-rpath,$(SIMGRID_INSTALL_DIR)/lib LINK.o = $(CXX) $(LDFLAGS) $(TARGET_ARCH) LDLIBS := -lsimgrid -MAKEDEPEND.C = $(CC) $(CPPFLAGS) -MM -MF $@ $< -MAKEDEPEND.CXX = $(CXX) $(CPPFLAGS) -MM -MF $@ $< +MAKEDEPEND.FLAGS = $(CPPFLAGS) -MM -MF $@ $< +MAKEDEPEND.C = $(CC) $(MAKEDEPEND.FLAGS) +MAKEDEPEND.CXX = $(CXX) $(MAKEDEPEND.FLAGS) LOCALVERSION := localversion SETLOCALVERSION := ./setlocalversion SRC.loba := main.cpp \ communicator.cpp \ - parameters.cpp \ + cost_func.cpp \ + options.cpp \ process.cpp \ version.cpp diff --git a/cost_func.cpp b/cost_func.cpp new file mode 100644 index 0000000..bdea62e --- /dev/null +++ b/cost_func.cpp @@ -0,0 +1,60 @@ +#include +#include +#include +#include +#include +#include "cost_func.h" + +cost_func::cost_func(const char *param) +{ + int len = strlen(param); + char tmpbuf[len + 1]; + char *tmp = tmpbuf; + memcpy(tmp, param, len + 1); + degree = std::count(tmp, tmp + len, ','); + factor = new double[degree + 1]; + for (int i = degree ; i > 0 ; i--) { + char *next = strchr(tmp, ','); + *next++ = '\0'; + factor[i] = atof(tmp); + tmp = next; + } + factor[0] = atof(tmp); +} + +cost_func::~cost_func() +{ + delete[] factor; +} + +cost_func& cost_func::operator=(const cost_func& ref) +{ + if (&ref != this) { + degree = ref.degree; + delete[] factor; + factor = new double[degree + 1]; + memcpy(factor, ref.factor, (degree + 1) * sizeof *factor); + } + return *this; +} + +double cost_func::operator()(double amount) const +{ + double ret = factor[degree]; + for (int i = degree - 1; i >= 0 ; i--) + ret = amount * ret + factor[i]; + return ret; +} + +std::string cost_func::to_string() +{ + std::ostringstream oss; + std::reverse_copy(factor + 1, factor + degree + 1, + std::ostream_iterator(oss, ", ")); + oss << factor[0]; + return oss.str(); +} + +// Local Variables: +// mode: c++ +// End: diff --git a/cost_func.h b/cost_func.h new file mode 100644 index 0000000..57d1188 --- /dev/null +++ b/cost_func.h @@ -0,0 +1,24 @@ +#ifndef COST_FUNC_H +#define COST_FUNC_H + +#include +#include + +class cost_func { +public: + cost_func(const char *param); + ~cost_func(); + cost_func& operator=(const cost_func& ref); + + double operator()(double amount) const; + std::string to_string(); +private: + int degree; + double *factor; +}; + +#endif // !COST_FUNC_H + +// Local Variables: +// mode: c++ +// End: diff --git a/main.cpp b/main.cpp index df1126a..dbc5b43 100644 --- a/main.cpp +++ b/main.cpp @@ -1,9 +1,9 @@ -#include // for strlen() +#include #include #include #include #include "misc.h" -#include "parameters.h" +#include "options.h" #include "process.h" #include "timer.h" #include "version.h" @@ -46,19 +46,19 @@ int main(int argc, char *argv[]) MSG_global_init(&argc, argv); // Parse global parameters - int parse_res = param::parse_args(&argc, argv); + int parse_res = opt::parse_args(&argc, argv); if (!parse_res - || param::version_requested || param::help_requested) { - if (param::version_requested) + || opt::version_requested || opt::help_requested) { + if (opt::version_requested) std::clog << version::name << " version " << version::num << "\n" << version::copyright << "\n" "Compiled on " << version::date << "\n\n"; - if (!parse_res || param::help_requested) - param::usage(); + if (!parse_res || opt::help_requested) + opt::usage(); MSG_clean(); exit(parse_res ? EXIT_NO_FAILURE : EXIT_FAILURE_ARGS); } - param::print(); + opt::print(); TRY { exit_status = EXIT_FAILURE_INIT; // ===== @@ -69,7 +69,7 @@ int main(int argc, char *argv[]) MSG_function_register("Calculs", simulation_main); // Create the platform and the application. - MSG_create_environment(param::platform_file); + MSG_create_environment(opt::platform_file); if (LOG_ISENABLED(xbt_log_priority_verbose)) { int n = MSG_get_host_number(); m_host_t *h = MSG_get_host_table(); @@ -78,7 +78,7 @@ int main(int argc, char *argv[]) VERB2("Host #%d named \"%s\".", i, MSG_host_get_name(h[i])); xbt_free(h); } - MSG_launch_application(param::application_file); + MSG_launch_application(opt::application_file); exit_status = EXIT_FAILURE_SIMU; // ===== diff --git a/options.cpp b/options.cpp new file mode 100644 index 0000000..aa3bede --- /dev/null +++ b/options.cpp @@ -0,0 +1,113 @@ +#include +#include +#include +#include +#include "options.h" +#include "misc.h" + +XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(simu); + +namespace opt { + + const char* program_name; + + const char* platform_file; + const char* application_file; + + int help_requested = 0; + bool version_requested = false; + + cost_func comp_cost("1, 0"); + cost_func comm_cost("1, 0"); + +} // namespace opt + +int opt::parse_args(int* argc, char* argv[]) +{ + char *tmp = strrchr(argv[0], '/'); + opt::program_name = (tmp ? tmp + 1 : argv[0]); + + int c; + opterr = 0; + while ((c = getopt(*argc, argv, "hc:C:V")) != -1) { + switch (c) { + case 'h': + opt::help_requested++; + break; + case 'c': + opt::comp_cost = cost_func(optarg); + break; + case 'C': + opt::comm_cost = cost_func(optarg); + break; + case 'V': + opt::version_requested = true; + break; + case '?': + WARN1("invalid option -- '%c'", optopt); + break; + } + } + if (opt::version_requested || opt::help_requested) + return 1; + + switch (*argc - optind) { + case 0: + ERROR0("missing parameter -- "); + case 1: + ERROR0("missing parameter -- "); + return 0; + + default: + opt::platform_file = argv[optind]; + opt::application_file = argv[optind + 1]; + for (int i = optind + 2 ; i < *argc ; ++i) + WARN1("unused parameter -- \"%s\"", argv[i]); + break; + } + + return 1; +} + +void opt::print() +{ + INFO0(",----[ Simulation parameters ]"); + INFO1("| platform_file.......: \"%s\"", opt::platform_file); + INFO1("| application_file....: \"%s\"", opt::application_file); + INFO1("| comp. cost factors..: [%s]", opt::comp_cost.to_string().c_str()); + INFO1("| comm. cost factors..: [%s]", opt::comm_cost.to_string().c_str()); + INFO0("`----"); +} + +#include +void opt::usage() +{ + const int indent1 = 6; + const int indent2 = 12; + +#define oo(opt, arg) std::setw(indent1) << (opt) << " " \ + << std::setw(indent2) << std::left << (arg) << std::right +#define o(opt) oo(opt, "") + + std::clog << "Usage: " << opt::program_name + << " [options] \n"; + + std::clog << o("-h") + << "print help and exit (use -hh or -hhh for extended help)\n"; + if (opt::help_requested < 1) + return; + std::clog << o("-V") << "print version and exit\n"; + std::clog << oo("-c", "[fn,...]f0") + << "polynomial factors for computation cost (" + << opt::comp_cost.to_string() << ")\n"; + std::clog << oo("-C", "[fn,...]f0") + << "polynomial factors for communication cost (" + << opt::comm_cost.to_string() << ")\n"; + +#undef o +#undef oo +} + +// Local variables: +// mode: c++ +// End: diff --git a/options.h b/options.h new file mode 100644 index 0000000..8f09896 --- /dev/null +++ b/options.h @@ -0,0 +1,30 @@ +#ifndef OPTIONS_H +#define OPTIONS_H + +#include "cost_func.h" + +// Global parameters, shared by all the processes +namespace opt { + + extern const char* program_name; + + extern const char* platform_file; + extern const char* application_file; + + extern int help_requested; + extern bool version_requested; + + extern cost_func comp_cost; + extern cost_func comm_cost; + + int parse_args(int* argc, char* argv[]); + void print(); + void usage(); + +} // namespace opt + +#endif // !OPTIONS_H + +// Local variables: +// mode: c++ +// End: diff --git a/parameters.cpp b/parameters.cpp deleted file mode 100644 index 307882b..0000000 --- a/parameters.cpp +++ /dev/null @@ -1,82 +0,0 @@ -#include // for strrchr() -#include -#include // for getopt() -#include -#include "parameters.h" -#include "misc.h" - -XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(simu); - -namespace param { - - const char* program_name; - - const char* platform_file; - const char* application_file; - - int help_requested = 0; - bool version_requested = false; - - int parse_args(int* argc, char* argv[]) - { - program_name = strrchr(argv[0], '/'); - program_name = (program_name ? program_name + 1 : argv[0]); - - int c; - opterr = 0; - while ((c = getopt(*argc, argv, "hV")) != -1) { - switch (c) { - case 'h': - help_requested++; - break; - case 'V': - version_requested = true; - break; - case '?': - WARN1("invalid option -- '%c'", optopt); - break; - } - } - if (version_requested || help_requested) - return 1; - - switch (*argc - optind) { - case 0: - ERROR0("missing parameter -- "); - case 1: - ERROR0("missing parameter -- "); - return 0; - - default: - platform_file = argv[optind]; - application_file = argv[optind + 1]; - for (int i = optind + 2 ; i < *argc ; ++i) - WARN1("unused parameter -- \"%s\"", argv[i]); - break; - } - - return 1; - } - - void print() - { - INFO0(",----[ Simulation parameters ]"); - INFO1("| platform_file.....: \"%s\"", platform_file); - INFO1("| application_file..: \"%s\"", application_file); - INFO0("`----"); - } - - void usage() - { - std::clog << "Usage: " << program_name << " [options] \n"; - std::clog << " -h print help and exit (use -hh or -hhh for extended help)\n"; - if (help_requested < 1) - return; - std::clog << " -V print version and exit\n"; - } - -} // namespace param - -// Local variables: -// mode: c++ -// End: diff --git a/parameters.h b/parameters.h deleted file mode 100644 index cf301e2..0000000 --- a/parameters.h +++ /dev/null @@ -1,25 +0,0 @@ -#ifndef PARAMETERS_H -#define PARAMETERS_H - -// Global parameters, shared by all the processes -namespace param { - - extern const char* program_name; - - extern const char* platform_file; - extern const char* application_file; - - extern int help_requested; - extern bool version_requested; - - int parse_args(int* argc, char* argv[]); - void print(); - void usage(); - -} // namespace param - -#endif // !PARAMETERS_H - -// Local variables: -// mode: c++ -// End: diff --git a/process.cpp b/process.cpp index 8ceb469..7605818 100644 --- a/process.cpp +++ b/process.cpp @@ -5,6 +5,7 @@ #include #include #include "misc.h" +#include "options.h" #include "process.h" XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(simu); @@ -36,22 +37,6 @@ process::process(int argc, char *argv[]) print_loads(logp); } -void process::print_loads(e_xbt_log_priority_t logp) -{ - if (!LOG_ISENABLED(logp)) - return; - std::ostringstream oss; - if (neigh.empty()) { - oss << "no neighbor!"; - } else { - std::transform(neigh.begin(), neigh.end() - 1, - std::ostream_iterator(oss, ", "), - std::mem_fun_ref(&neighbor::getLoad)); - oss << neigh.back().getLoad(); - } - LOG1(logp, "Neighbor loads: %s", oss.str().c_str()); -} - int process::run() { INFO0("Coucou !"); @@ -76,6 +61,30 @@ int process::run() return 0; } +void process::compute() +{ + double duration = opt::comp_cost(load); + m_task_t task = MSG_task_create("computation", duration, 0.0, NULL); + MSG_task_execute(task); + MSG_task_destroy(task); +} + +void process::print_loads(e_xbt_log_priority_t logp) +{ + if (!LOG_ISENABLED(logp)) + return; + std::ostringstream oss; + if (neigh.empty()) { + oss << "no neighbor!"; + } else { + std::transform(neigh.begin(), neigh.end() - 1, + std::ostream_iterator(oss, ", "), + std::mem_fun_ref(&neighbor::getLoad)); + oss << neigh.back().getLoad(); + } + LOG1(logp, "Neighbor loads: %s", oss.str().c_str()); +} + // Local variables: // mode: c++ // End: diff --git a/process.h b/process.h index ea35003..8711fca 100644 --- a/process.h +++ b/process.h @@ -10,13 +10,15 @@ class process { public: process(int argc, char *argv[]); ~process() { }; - void print_loads(e_xbt_log_priority_t logp = xbt_log_priority_info); int run(); private: communicator comm; std::vector neigh; double load; + + void compute(); + void print_loads(e_xbt_log_priority_t logp = xbt_log_priority_info); }; #endif // !PROCESS_H