]> AND Private Git Repository - loba.git/commitdiff
Logo AND Algorithmique Numérique Distribuée

Private GIT Repository
Wip...
authorArnaud Giersch <arnaud.giersch@iut-bm.univ-fcomte.fr>
Tue, 7 Dec 2010 15:20:25 +0000 (16:20 +0100)
committerArnaud Giersch <arnaud.giersch@iut-bm.univ-fcomte.fr>
Tue, 14 Dec 2010 23:22:38 +0000 (00:22 +0100)
* rename parameters -> options
* add cost_func
* add process::compute
* add core files in .gitignore

.gitignore
Makefile
cost_func.cpp [new file with mode: 0644]
cost_func.h [new file with mode: 0644]
main.cpp
options.cpp [new file with mode: 0644]
options.h [new file with mode: 0644]
parameters.cpp [deleted file]
parameters.h [deleted file]
process.cpp
process.h

index feed56878f8a5b9f6772b655584b43ed5550c93c..8d5a012c432401d8a9184ae85e5581e8df1130b3 100644 (file)
@@ -1,6 +1,8 @@
 *~
 *.d
 *.o
 *~
 *.d
 *.o
+core
+vgcore.*
 localversion
 loba
 simple_async
 localversion
 loba
 simple_async
index 0653492a4f039767de8d0dce83be1e008b8db2e7..4b0df0717267e86368085e4795d0f41bdf5d6c56 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -22,15 +22,17 @@ LDFLAGS += -Wl,-rpath,$(SIMGRID_INSTALL_DIR)/lib
 LINK.o = $(CXX) $(LDFLAGS) $(TARGET_ARCH)
 LDLIBS := -lsimgrid
 
 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        \
 
 LOCALVERSION := localversion
 SETLOCALVERSION := ./setlocalversion
 
 SRC.loba := main.cpp           \
        communicator.cpp        \
-       parameters.cpp          \
+       cost_func.cpp           \
+       options.cpp             \
        process.cpp             \
        version.cpp
 
        process.cpp             \
        version.cpp
 
diff --git a/cost_func.cpp b/cost_func.cpp
new file mode 100644 (file)
index 0000000..bdea62e
--- /dev/null
@@ -0,0 +1,60 @@
+#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:
diff --git a/cost_func.h b/cost_func.h
new file mode 100644 (file)
index 0000000..57d1188
--- /dev/null
@@ -0,0 +1,24 @@
+#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:
index df1126a9f04eccd3e465441b607690d9fe6489a9..dbc5b4306b7c7f98d222354391f9aeba883dc919 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -1,9 +1,9 @@
-#include <cstring>              // for strlen()
+#include <cstring>
 #include <iostream>
 #include <msg/msg.h>
 #include <xbt/log.h>
 #include "misc.h"
 #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"
 #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
     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
     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";
             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);
     }
         MSG_clean();
         exit(parse_res ? EXIT_NO_FAILURE : EXIT_FAILURE_ARGS);
     }
-    param::print();
+    opt::print();
 
     TRY {    
         exit_status = EXIT_FAILURE_INIT; // =====
 
     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_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();
         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);
         }
                 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; // =====
 
 
         exit_status = EXIT_FAILURE_SIMU; // =====
 
diff --git a/options.cpp b/options.cpp
new file mode 100644 (file)
index 0000000..aa3bede
--- /dev/null
@@ -0,0 +1,113 @@
+#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:
diff --git a/options.h b/options.h
new file mode 100644 (file)
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 (file)
index 307882b..0000000
+++ /dev/null
@@ -1,82 +0,0 @@
-#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:
diff --git a/parameters.h b/parameters.h
deleted file mode 100644 (file)
index cf301e2..0000000
+++ /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:
index 8ceb4692fd00c9e2c2e5a28b45555a7ec9b7efe5..76058180c01d7a4e08cd008b07eaa043e0575fbf 100644 (file)
@@ -5,6 +5,7 @@
 #include <sstream>
 #include <xbt/log.h>
 #include "misc.h"
 #include <sstream>
 #include <xbt/log.h>
 #include "misc.h"
+#include "options.h"
 #include "process.h"
 
 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(simu);
 #include "process.h"
 
 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(simu);
@@ -36,22 +37,6 @@ process::process(int argc, char *argv[])
     print_loads(logp);
 }
 
     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 !");
 int process::run()
 {
     INFO0("Coucou !");
@@ -76,6 +61,30 @@ int process::run()
     return 0;
 }
 
     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:
 // Local variables:
 // mode: c++
 // End:
index ea350038a168e92199ac5bb35ea90952596184a5..8711fca03a2d358d91af8e58f62f73b08e15f040 100644 (file)
--- a/process.h
+++ b/process.h
@@ -10,13 +10,15 @@ class process {
 public:
     process(int argc, char *argv[]);
     ~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<neighbor> neigh;
     double load;
     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
 };
 
 #endif // !PROCESS_H