*~
*.d
*.o
+core
+vgcore.*
localversion
loba
simple_async
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
--- /dev/null
+#include <algorithm>
+#include <cstdlib>
+#include <cstring>
+#include <iterator>
+#include <sstream>
+#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<double>(oss, ", "));
+ oss << factor[0];
+ return oss.str();
+}
+
+// Local Variables:
+// mode: c++
+// End:
--- /dev/null
+#ifndef COST_FUNC_H
+#define COST_FUNC_H
+
+#include <iostream>
+#include <string>
+
+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:
-#include <cstring> // for strlen()
+#include <cstring>
#include <iostream>
#include <msg/msg.h>
#include <xbt/log.h>
#include "misc.h"
-#include "parameters.h"
+#include "options.h"
#include "process.h"
#include "timer.h"
#include "version.h"
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; // =====
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();
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; // =====
--- /dev/null
+#include <cstring>
+#include <iostream>
+#include <unistd.h>
+#include <xbt/log.h>
+#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 -- <plaform_file>");
+ case 1:
+ ERROR0("missing parameter -- <application_file>");
+ 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 <iomanip>
+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] <platform_file> <application_file>\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:
--- /dev/null
+#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:
+++ /dev/null
-#include <cstring> // for strrchr()
-#include <iostream>
-#include <unistd.h> // for getopt()
-#include <xbt/log.h>
-#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 -- <plaform_file>");
- case 1:
- ERROR0("missing parameter -- <application_file>");
- 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] <platform_file> <application_file>\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:
+++ /dev/null
-#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:
#include <sstream>
#include <xbt/log.h>
#include "misc.h"
+#include "options.h"
#include "process.h"
XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(simu);
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<double>(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 !");
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<double>(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:
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<neighbor> neigh;
double load;
+
+ void compute();
+ void print_loads(e_xbt_log_priority_t logp = xbt_log_priority_info);
};
#endif // !PROCESS_H