Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Lua: garbage collect the simgrid module (remove simgrid.clean())
authorChristophe Thiéry <christopho128@gmail.com>
Thu, 10 Nov 2011 14:54:02 +0000 (15:54 +0100)
committerChristophe Thiéry <christopho128@gmail.com>
Thu, 10 Nov 2011 16:00:16 +0000 (17:00 +0100)
examples/lua/console/master_slave_bypass.lua
examples/lua/masterslave/master_slave.lua
examples/lua/mult_matrix.lua [deleted file]
examples/lua/multi_matrix/mult_matrix.lua
examples/lua/state_cloner/duplicated_globals.lua
examples/lua/tracing/master_slave_trace.lua
src/bindings/lua/simgrid_lua.c
src/msg/msg_global.c

index a1c9759..37338f1 100644 (file)
@@ -4,5 +4,4 @@ dofile 'deploy.lua'
 --Rutform.lua'
    simgrid.run()
    simgrid.info("Simulation's over.See you.")
 --Rutform.lua'
    simgrid.run()
    simgrid.info("Simulation's over.See you.")
-   simgrid.clean()
 
 
index b2b0f60..7057c2f 100644 (file)
@@ -13,5 +13,4 @@ else
 end
 simgrid.run()
 simgrid.info("Simulation's over.See you.")
 end
 simgrid.run()
 simgrid.info("Simulation's over.See you.")
-simgrid.clean()
 
 
diff --git a/examples/lua/mult_matrix.lua b/examples/lua/mult_matrix.lua
deleted file mode 100644 (file)
index 45506c6..0000000
+++ /dev/null
@@ -1,99 +0,0 @@
-function Sender(...) 
-
-       simgrid.info("Hello From Sender")
-       receiver = simgrid.host.get_by_name(arg[1])
-       task_comp = arg[2]
-       task_comm = arg[3]
-       rec_alias = arg[4]
-       
-       size = 4
-       m1 = mkmatrix(size, size)
-        m2 = mkmatrix(size, size)      
-
-       if (#arg ~= 4) then
-           error("Argc should be 4");
-       end
-       simgrid.info("Argc="..(#arg).." (should be 4)")
-
-       -- Sending Task
-       task = simgrid.task.new("matrix_task",task_comp,task_comm);
-       task['matrix_1'] = m1;
-       task['matrix_2'] = m2;
-       task['size'] = size;
-       simgrid.info("Sending "..simgrid.task.name(task).." to "..simgrid.host.name(receiver));
-       simgrid.task.send(task,rec_alias);
-       -- Read The Result 
-       mm = task['matrix_res']
-       simgrid.info("Got the Multiplication result ...Bye");
-       --mprint(size,size,mm);
-
-end
-------------------------------------------------------
-function Receiver(...)
-       
-       simgrid.info("Hello From Receiver")
-       sender = simgrid.host.get_by_name(arg[1])
-       send_alias = arg[2]
-       recv_alias = "Receiver";
-       simgrid.info("Receiving Task from "..simgrid.host.name(sender));
-       task = simgrid.task.recv(recv_alias);
-       mm = mmult(task['size'],task['size'],task['matrix_1'],task['matrix_2']);
-       --mprint(task['size'],task['size'],mm)
-       task['matrix_res'] = mm;
-       simgrid.info("Calcul is done ... Bye");
-
-
-end
------------------------------------------------------
-
-local n = tonumber((arg and arg[1]) or 1)
-
-
-
-function mkmatrix(rows, cols)
-    local count = 1
-    local mx = {}
-    for i=0,(rows - 1) do
-    local row = {}
-    for j=0,(cols - 1) do
-        row[j] = count
-        count = count + 1
-    end
-    mx[i] = row
-    end
-    return(mx)
-end
-
-function mmult(rows, cols, m1, m2)
-    local m3 = {}
-    for i=0,(rows-1) do
-        m3[i] = {}
-        for j=0,(cols-1) do
-            local rowj = 0
-            for k=0,(cols-1) do
-                rowj = rowj + m1[i][k] * m2[k][j]
-            end
-            m3[i][j] = rowj
-        end
-    end
-    return(m3)
-end
-
-function mprint(rows,cols,m)
- for i=0,(cols-1)do
-       for j=0,(rows-1)do
-               print (m[i][j])
-       end
- end
-end
-
-
---end
-require "simgrid"
-simgrid.platform("quicksort_platform.xml")
-simgrid.application("quicksort_deployment.xml")
-simgrid.run()
-simgrid.info("Simulation's over.See you.")
-simgrid.clean()
-
-
index 2aea25d..9700b76 100644 (file)
@@ -6,5 +6,4 @@ simgrid.platform("quicksort_platform.xml")
 simgrid.application("quicksort_deployment.xml")
 simgrid.run()
 simgrid.info("Simulation's over.See you.")
 simgrid.application("quicksort_deployment.xml")
 simgrid.run()
 simgrid.info("Simulation's over.See you.")
-simgrid.clean()
 
 
index 0675f8e..70366bb 100644 (file)
@@ -40,5 +40,4 @@ print_global()
 simgrid.platform("../../msg/small_platform.xml")
 simgrid.application("deployment_duplicated_globals.xml")
 simgrid.run()
 simgrid.platform("../../msg/small_platform.xml")
 simgrid.application("deployment_duplicated_globals.xml")
 simgrid.run()
-simgrid.clean()
 
 
index e51b7d1..f3ca3f4 100644 (file)
@@ -19,6 +19,5 @@ end
 
 simgrid.run()
 simgrid.info("Simulation's over.See you.")
 
 simgrid.run()
 simgrid.info("Simulation's over.See you.")
-simgrid.clean()
 simgrid.Trace.finish()
 
 simgrid.Trace.finish()
 
index 3496588..b2f57d5 100644 (file)
@@ -661,7 +661,7 @@ static int run(lua_State * L)
  * \param L a Lua state
  * \return number of values returned to Lua
  */
  * \param L a Lua state
  * \return number of values returned to Lua
  */
-static int clean(lua_State * L)
+static int simgrid_gc(lua_State * L)
 {
   MSG_clean();
   return 0;
 {
   MSG_clean();
   return 0;
@@ -730,7 +730,6 @@ static const luaL_Reg simgrid_functions[] = {
   {"debug", debug},
   {"info", info},
   {"run", run},
   {"debug", debug},
   {"info", info},
   {"run", run},
-  {"clean", clean},
   /* short names */
   {"platform", create_environment},
   {"application", launch_application},
   /* short names */
   {"platform", create_environment},
   {"application", launch_application},
@@ -835,8 +834,8 @@ lua_State* sglua_get_maestro(void) {
  *
  * \param L a lua state
  */
  *
  * \param L a lua state
  */
-static void register_task_functions(lua_State* L) {
-
+static void register_task_functions(lua_State* L)
+{
   /* create a table simgrid.task and fill it with task functions */
   luaL_openlib(L, TASK_MODULE_NAME, task_functions, 0);
                                   /* simgrid.task */
   /* create a table simgrid.task and fill it with task functions */
   luaL_openlib(L, TASK_MODULE_NAME, task_functions, 0);
                                   /* simgrid.task */
@@ -869,8 +868,8 @@ static void register_task_functions(lua_State* L) {
  *
  * \param L a lua state
  */
  *
  * \param L a lua state
  */
-static void register_host_functions(lua_State* L) {
-
+static void register_host_functions(lua_State* L)
+{
   /* create a table simgrid.host and fill it with host functions */
   luaL_openlib(L, HOST_MODULE_NAME, host_functions, 0);
                                   /* simgrid.host */
   /* create a table simgrid.host and fill it with host functions */
   luaL_openlib(L, HOST_MODULE_NAME, host_functions, 0);
                                   /* simgrid.host */
@@ -898,24 +897,48 @@ static void register_host_functions(lua_State* L) {
  * \brief Registers the platform functions into the table simgrid.platf.
  * \param L a lua state
  */
  * \brief Registers the platform functions into the table simgrid.platf.
  * \param L a lua state
  */
-static void register_platf_functions(lua_State* L) {
-
+static void register_platf_functions(lua_State* L)
+{
   luaL_openlib(L, PLATF_MODULE_NAME, platf_functions, 0);
                                   /* simgrid.platf */
   lua_pop(L, 1);
 }
 
 /**
   luaL_openlib(L, PLATF_MODULE_NAME, platf_functions, 0);
                                   /* simgrid.platf */
   lua_pop(L, 1);
 }
 
 /**
- * \brief Makes the Simgrid functions available to the Lua world.
+ * \brief Makes the core functions available to the Lua world.
  * \param L a Lua world
  */
  * \param L a Lua world
  */
-static void register_c_functions(lua_State *L) {
-
+static void register_core_functions(lua_State *L)
+{
   /* register the core C functions to lua */
   luaL_register(L, "simgrid", simgrid_functions);
                                   /* simgrid */
   /* register the core C functions to lua */
   luaL_register(L, "simgrid", simgrid_functions);
                                   /* simgrid */
+
+  /* set a finalizer that cleans simgrid, by adding to the simgrid module a
+   * dummy userdata whose __gc metamethod calls MSG_clean() */
+  lua_newuserdata(L, sizeof(void*));
+                                  /* simgrid udata */
+  lua_newtable(L);
+                                  /* simgrid udata mt */
+  lua_pushcfunction(L, simgrid_gc);
+                                  /* simgrid udata mt simgrid_gc */
+  lua_setfield(L, -2, "__gc");
+                                  /* simgrid udata mt */
+  lua_setmetatable(L, -2);
+                                  /* simgrid udata */
+  lua_setfield(L, -2, "__simgrid_loaded");
+                                  /* simgrid */
   lua_pop(L, 1);
                                   /* -- */
   lua_pop(L, 1);
                                   /* -- */
+}
+
+/**
+ * \brief Creates the simgrid module and make it available to Lua.
+ * \param L a Lua world
+ */
+static void register_c_functions(lua_State *L)
+{
+  register_core_functions(L);
   register_task_functions(L);
   register_host_functions(L);
   register_platf_functions(L);
   register_task_functions(L);
   register_host_functions(L);
   register_platf_functions(L);
index a6356c9..7ac93dd 100644 (file)
@@ -178,6 +178,7 @@ int MSG_process_killall(int reset_PIDs)
  */
 MSG_error_t MSG_clean(void)
 {
  */
 MSG_error_t MSG_clean(void)
 {
+  XBT_DEBUG("Closing MSG");
 
 #ifdef HAVE_TRACING
   TRACE_surf_release();
 
 #ifdef HAVE_TRACING
   TRACE_surf_release();