Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
C++ify part of simdag
authorFrederic Suter <frederic.suter@cc.in2p3.fr>
Tue, 9 Aug 2016 09:16:59 +0000 (11:16 +0200)
committerFrederic Suter <frederic.suter@cc.in2p3.fr>
Tue, 9 Aug 2016 09:16:59 +0000 (11:16 +0200)
examples/simdag/test/sd_test.cpp
examples/simdag/test/sd_test.tesh
src/instr/jedule/jedule_sd_binding.cpp
src/simdag/sd_daxloader.cpp
src/simdag/sd_dotloader.cpp
src/simdag/sd_global.cpp
src/simdag/sd_task.cpp
src/simdag/sd_workstation.cpp
src/simdag/simdag_private.hpp [moved from src/simdag/simdag_private.h with 86% similarity]
tools/cmake/DefinePackages.cmake

index 73a4e74..f332f7a 100644 (file)
@@ -135,8 +135,8 @@ int main(int argc, char **argv)
           SD_task_get_start_time(task), SD_task_get_finish_time(task));
   }
 
-  xbt_dynar_get_cpy(changed_tasks, 0, &checkD);
-  xbt_dynar_get_cpy(changed_tasks, 1, &checkB);
+  xbt_dynar_get_cpy(changed_tasks, 0, &checkB);
+  xbt_dynar_get_cpy(changed_tasks, 1, &checkD);
 
   xbt_assert(checkD == taskD && checkB == taskB, "Unexpected simulation results");
 
index 911769c..09e2eed 100644 (file)
@@ -22,5 +22,5 @@ $ $SG_TEST_EXENV ./test/sd_test ${srcdir:=.}/../platforms/small_platform.xml
 > [0.000000] [sd_test/INFO] Communication time for 2000000.000000 bytes between Jacquelin and Fafard: 0.842756
 > [0.000000] [sd_test/INFO] Communication time for 3000000.000000 bytes between Fafard and Jacquelin: 1.229846
 > [0.000000] [sd_test/INFO] Estimated time for 'Task D': 1.242953
-> [4.008055] [sd_test/INFO] Task 'Task D' start time: 0.000000, finish time: 2.004027
 > [4.008055] [sd_test/INFO] Task 'Task B' start time: 2.004027, finish time: 4.008055
+> [4.008055] [sd_test/INFO] Task 'Task D' start time: 0.000000, finish time: 2.004027
index cf20f13..31ba789 100644 (file)
 #include "simgrid/jedule/jedule_output.h"
 
 #include "simgrid/simdag.h"
-#include "src/simdag/simdag_private.h"
-
 #include "simgrid/s4u/As.hpp"
 #include "simgrid/s4u/engine.hpp"
 
 #include <stdio.h>
+#include "../../simdag/simdag_private.hpp"
 
 #if HAVE_JEDULE
 
index 31f7e79..2c8ced7 100644 (file)
@@ -4,12 +4,12 @@
 /* This program is free software; you can redistribute it and/or modify it
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
-#include "src/simdag/simdag_private.h"
 #include "simgrid/simdag.h"
 #include "xbt/misc.h"
 #include "xbt/log.h"
 #include "xbt/str.h"
 #include "xbt/file.h" /* xbt_basename() */
+#include "simdag_private.hpp"
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(sd_daxparse, sd, "Parsing DAX files");
 
index 2acf99c..a3359d4 100644 (file)
@@ -5,10 +5,10 @@
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
 #include "src/internal_config.h"
-#include "src/simdag/simdag_private.h"
 #include "simgrid/simdag.h"
 #include "xbt/file.h"
 #include <string.h>
+#include "simdag_private.hpp"
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(sd_dotparse, sd, "Parsing DOT files");
 
index 01ce557..3ffd43c 100644 (file)
 
 #include "simgrid/sg_config.h"
 #include "simgrid/host.h"
-#include "src/simdag/simdag_private.h"
 #include "src/surf/surf_interface.hpp"
 #include "simgrid/s4u/engine.hpp"
+#include "simdag_private.hpp"
 
 XBT_LOG_NEW_CATEGORY(sd, "Logging specific to SimDag");
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(sd_kernel, sd, "Logging specific to SimDag (kernel)");
 
-SD_global_t sd_global = nullptr;
+simgrid::sd::Global *sd_global = nullptr;
 
-/**
- * \brief helper for pretty printing of task state
- * \param state the state of a task
- * \return the equivalent as a readable string
- */
-const char *__get_state_name(e_SD_task_state_t state){
-  std::string state_names[7] = { "not scheduled", "schedulable", "scheduled", "runnable","running", "done", "failed" };
-  return state_names[(int)log2(state)].data();
-}
-
-/**
- * \brief Initializes SD internal data
- *
- * This function must be called before any other SD function. Then you should call SD_create_environment().
- *
- * \param argc argument number
- * \param argv argument list
- * \see SD_create_environment(), SD_exit()
- */
-void SD_init(int *argc, char **argv)
-{
-  xbt_assert(sd_global == nullptr, "SD_init() already called");
-
-  sd_global = xbt_new(s_SD_global_t, 1);
-  sd_global->watch_point_reached = false;
-  sd_global->initial_tasks = new std::set<SD_task_t>();
-  sd_global->runnable_tasks = new std::set<SD_task_t>();
-  sd_global->completed_tasks = new std::set<SD_task_t>();
-  sd_global->return_set = xbt_dynar_new(sizeof(SD_task_t), nullptr);
-
-  surf_init(argc, argv);
-
-  xbt_cfg_setdefault_string("host/model", "ptask_L07");
-
-#if HAVE_JEDULE
-  jedule_sd_init();
-#endif
-
-  if (_sg_cfg_exit_asap) {
-    SD_exit();
-    exit(0);
-  }
+namespace simgrid{
+namespace sd{
+Global::Global(){
+  watch_point_reached = false;
+  initial_tasks = new std::set<SD_task_t>();
+  runnable_tasks = new std::set<SD_task_t>();
+  completed_tasks = new std::set<SD_task_t>();
+  return_set = new std::set<SD_task_t>();
 }
 
-/** \brief set a configuration variable
- *
- * Do --help on any simgrid binary to see the list of currently existing configuration variables, and
- * see Section @ref options.
- *
- * Example: SD_config("host/model","default");
- */
-void SD_config(const char *key, const char *value){
-  xbt_assert(sd_global,"ERROR: Please call SD_init() before using SD_config()");
-  xbt_cfg_set_as_string(key, value);
+Global::~Global(){
+  delete initial_tasks;
+  delete runnable_tasks;
+  delete completed_tasks;
+  delete return_set;
 }
 
-/**
- * \brief Creates the environment
- *
- * The environment (i.e. the \ref SD_host_api "hosts" and the \ref SD_link_api "links") is created with
- * the data stored in the given XML platform file.
- *
- * \param platform_file name of an XML file describing the environment to create
- * \see SD_host_api, SD_link_api
- *
- * The XML file follows this DTD:
- *
- *     \include simgrid.dtd
- *
- * Here is a small example of such a platform:
- *
- *     \include small_platform.xml
- */
-void SD_create_environment(const char *platform_file)
-{
-  simgrid::s4u::Engine::instance()->loadPlatform(platform_file);
-
-  XBT_DEBUG("Workstation number: %zu, link number: %d", sg_host_count(), sg_link_count());
-#if HAVE_JEDULE
-  jedule_setup_platform();
-#endif
-  XBT_VERB("Starting simulation...");
-  surf_presolve();            /* Takes traces into account */
-}
-
-/**
- * \brief Launches the simulation.
- *
- * The function will execute the \ref SD_RUNNABLE runnable tasks.
- * If \a how_long is positive, then the simulation will be stopped either when time reaches \a how_long or when a watch
- * point is reached.
- * A non-positive value for \a how_long means no time limit, in which case the simulation will be stopped either when a
- * watch point is reached or when no more task can be executed.
- * Then you can call SD_simulate() again.
- *
- * \param how_long maximum duration of the simulation (a negative value means no time limit)
- * \return a dynar of \ref SD_task_t whose state has changed.
- * \see SD_task_schedule(), SD_task_watch()
- */
-
-xbt_dynar_t SD_simulate(double how_long) {
+std::set<SD_task_t>* simulate(double how_long){
   XBT_VERB("Run simulation for %f seconds", how_long);
 
   sd_global->watch_point_reached = false;
-  xbt_dynar_reset(sd_global->return_set);
+  sd_global->return_set->clear();
 
   /* explore the runnable tasks */
   while(!sd_global->runnable_tasks->empty())
@@ -148,8 +65,8 @@ xbt_dynar_t SD_simulate(double how_long) {
         SD_task_set_state(task, SD_DONE);
 
         /* the state has changed. Add it only if it's the first change */
-        if (xbt_dynar_member(sd_global->return_set, &task) == 0)
-          xbt_dynar_push(sd_global->return_set, &task);
+        if (sd_global->return_set->find(task) == sd_global->return_set->end())
+          sd_global->return_set->insert(task);
 
         /* remove the dependencies after this task */
         for (auto succ : *task->successors) {
@@ -196,7 +113,7 @@ xbt_dynar_t SD_simulate(double how_long) {
         SD_task_t task = static_cast<SD_task_t>(action->getData());
         XBT_VERB("Task '%s' failed", SD_task_get_name(task));
         SD_task_set_state(task, SD_FAILED);
-        xbt_dynar_push(sd_global->return_set, &task);
+        sd_global->return_set->insert(task);
         action = surf_model_extract_failed_action_set(model);
       }
     }
@@ -214,6 +131,111 @@ xbt_dynar_t SD_simulate(double how_long) {
 
   return sd_global->return_set;
 }
+}
+}
+
+/**
+ * \brief helper for pretty printing of task state
+ * \param state the state of a task
+ * \return the equivalent as a readable string
+ */
+const char *__get_state_name(e_SD_task_state_t state){
+  std::string state_names[7] = { "not scheduled", "schedulable", "scheduled", "runnable","running", "done", "failed" };
+  return state_names[(int)log2(state)].data();
+}
+
+/**
+ * \brief Initializes SD internal data
+ *
+ * This function must be called before any other SD function. Then you should call SD_create_environment().
+ *
+ * \param argc argument number
+ * \param argv argument list
+ * \see SD_create_environment(), SD_exit()
+ */
+void SD_init(int *argc, char **argv)
+{
+  xbt_assert(sd_global == nullptr, "SD_init() already called");
+
+  sd_global = new simgrid::sd::Global();
+
+  surf_init(argc, argv);
+
+  xbt_cfg_setdefault_string("host/model", "ptask_L07");
+
+#if HAVE_JEDULE
+  jedule_sd_init();
+#endif
+
+  if (_sg_cfg_exit_asap) {
+    SD_exit();
+    exit(0);
+  }
+}
+
+/** \brief set a configuration variable
+ *
+ * Do --help on any simgrid binary to see the list of currently existing configuration variables, and
+ * see Section @ref options.
+ *
+ * Example: SD_config("host/model","default");
+ */
+void SD_config(const char *key, const char *value){
+  xbt_assert(sd_global,"ERROR: Please call SD_init() before using SD_config()");
+  xbt_cfg_set_as_string(key, value);
+}
+
+/**
+ * \brief Creates the environment
+ *
+ * The environment (i.e. the \ref SD_host_api "hosts" and the \ref SD_link_api "links") is created with
+ * the data stored in the given XML platform file.
+ *
+ * \param platform_file name of an XML file describing the environment to create
+ * \see SD_host_api, SD_link_api
+ *
+ * The XML file follows this DTD:
+ *
+ *     \include simgrid.dtd
+ *
+ * Here is a small example of such a platform:
+ *
+ *     \include small_platform.xml
+ */
+void SD_create_environment(const char *platform_file)
+{
+  simgrid::s4u::Engine::instance()->loadPlatform(platform_file);
+
+  XBT_DEBUG("Host number: %zu, link number: %d", sg_host_count(), sg_link_count());
+#if HAVE_JEDULE
+  jedule_setup_platform();
+#endif
+  XBT_VERB("Starting simulation...");
+  surf_presolve();            /* Takes traces into account */
+}
+
+/**
+ * \brief Launches the simulation.
+ *
+ * The function will execute the \ref SD_RUNNABLE runnable tasks.
+ * If \a how_long is positive, then the simulation will be stopped either when time reaches \a how_long or when a watch
+ * point is reached.
+ * A non-positive value for \a how_long means no time limit, in which case the simulation will be stopped either when a
+ * watch point is reached or when no more task can be executed.
+ * Then you can call SD_simulate() again.
+ *
+ * \param how_long maximum duration of the simulation (a negative value means no time limit)
+ * \return a dynar of \ref SD_task_t whose state has changed.
+ * \see SD_task_schedule(), SD_task_watch()
+ */
+
+xbt_dynar_t SD_simulate(double how_long) {
+  std::set<SD_task_t> *changed_tasks = simgrid::sd::simulate(how_long);
+  xbt_dynar_t changed_tasks_dynar = xbt_dynar_new(sizeof(SD_task_t), nullptr);
+  for (auto task: *changed_tasks)
+    xbt_dynar_push(changed_tasks_dynar, &task);
+  return changed_tasks_dynar;
+}
 
 /** @brief Returns the current clock, in seconds */
 double SD_get_clock() {
@@ -231,10 +253,5 @@ void SD_exit()
   jedule_sd_cleanup();
   jedule_sd_exit();
 #endif
-  delete sd_global->initial_tasks;
-  delete sd_global->runnable_tasks;
-  delete sd_global->completed_tasks;
-  xbt_dynar_free_container(&(sd_global->return_set));
-  xbt_free(sd_global);
-  sd_global = nullptr;
+  delete sd_global;
 }
index bb66feb..0006c32 100644 (file)
@@ -4,9 +4,9 @@
 /* This program is free software; you can redistribute it and/or modify it
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
+#include "simdag_private.hpp"
 #include "src/surf/HostImpl.hpp"
 #include "src/surf/surf_interface.hpp"
-#include "src/simdag/simdag_private.h"
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(sd_task, sd, "Logging specific to SimDag (task)");
 
@@ -821,7 +821,7 @@ void SD_task_run(SD_task_t task)
 
   __SD_task_destroy_scheduling_data(task);      /* now the scheduling data are not useful anymore */
   SD_task_set_state(task, SD_RUNNING);
-  xbt_dynar_push(sd_global->return_set, &task);
+  sd_global->return_set->insert(task);
 }
 
 /**
index 2973da0..44e2a0b 100644 (file)
@@ -4,8 +4,9 @@
 /* This program is free software; you can redistribute it and/or modify it
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
-#include "src/simdag/simdag_private.h"
 #include "simgrid/s4u/host.hpp"
+
+#include "simdag_private.hpp"
 #include "src/surf/HostImpl.hpp"
 #include "surf/surf.h"
 
similarity index 86%
rename from src/simdag/simdag_private.h
rename to src/simdag/simdag_private.hpp
index d2c66c3..9cd87ba 100644 (file)
@@ -4,35 +4,37 @@
 /* This program is free software; you can redistribute it and/or modify it
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
-#ifndef SIMDAG_PRIVATE_H
-#define SIMDAG_PRIVATE_H
 #include <set>
 #include <string>
 #include <vector>
-#include "xbt/dynar.h"
 #include "simgrid/simdag.h"
 #include "surf/surf.h"
-#include <stdbool.h>
+
+#ifndef SIMDAG_PRIVATE_HPP
+#define SIMDAG_PRIVATE_HPP
 #if HAVE_JEDULE
 #include "simgrid/jedule/jedule_sd_binding.h"
 #endif
 
-SG_BEGIN_DECL()
-
-/* Global variables */
-
-typedef struct SD_global {
+namespace simgrid{
+namespace sd{
+class Global {
+public:
+  explicit Global();
+  ~Global();
   bool watch_point_reached;      /* has a task just reached a watch point? */
   std::set<SD_task_t> *initial_tasks;
   std::set<SD_task_t> *runnable_tasks;
   std::set<SD_task_t> *completed_tasks;
+  std::set<SD_task_t> *return_set;
+};
 
-  xbt_dynar_t return_set;
-} s_SD_global_t;
+std::set<SD_task_t>* simulate (double how_long);
+}
+}
 
-typedef struct SD_global *SD_global_t;
-
-extern XBT_PRIVATE SD_global_t sd_global;
+SG_BEGIN_DECL()
+extern XBT_PRIVATE simgrid::sd::Global *sd_global;
 
 /* Task */
 typedef struct SD_task {
@@ -68,6 +70,5 @@ XBT_PRIVATE void SD_task_run(SD_task_t task);
 XBT_PRIVATE bool acyclic_graph_detail(xbt_dynar_t dag);
 XBT_PRIVATE void uniq_transfer_task_name(SD_task_t task);
 XBT_PRIVATE const char *__get_state_name(e_SD_task_state_t state);
-
 SG_END_DECL()
 #endif
index 61af940..702755d 100644 (file)
@@ -17,7 +17,7 @@ set(EXTRA_DIST
   src/simdag/dax.dtd
   src/simdag/dax_dtd.c
   src/simdag/dax_dtd.h
-  src/simdag/simdag_private.h
+  src/simdag/simdag_private.hpp
   src/simix/simcalls.in
   src/simix/simcalls.py
   src/simix/popping_private.h