From: Christophe ThiƩry Date: Thu, 10 Nov 2011 14:54:02 +0000 (+0100) Subject: Lua: garbage collect the simgrid module (remove simgrid.clean()) X-Git-Tag: exp_20120216~344 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/d2ba533b2ba779dc85b3faf0d297dc6f13c7e7c1 Lua: garbage collect the simgrid module (remove simgrid.clean()) --- diff --git a/examples/lua/console/master_slave_bypass.lua b/examples/lua/console/master_slave_bypass.lua index a1c9759483..37338f1a1e 100644 --- a/examples/lua/console/master_slave_bypass.lua +++ b/examples/lua/console/master_slave_bypass.lua @@ -4,5 +4,4 @@ dofile 'deploy.lua' --Rutform.lua' simgrid.run() simgrid.info("Simulation's over.See you.") - simgrid.clean() diff --git a/examples/lua/masterslave/master_slave.lua b/examples/lua/masterslave/master_slave.lua index b2b0f60c72..7057c2fbc9 100644 --- a/examples/lua/masterslave/master_slave.lua +++ b/examples/lua/masterslave/master_slave.lua @@ -13,5 +13,4 @@ else 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 index 45506c63d0..0000000000 --- a/examples/lua/mult_matrix.lua +++ /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() - - diff --git a/examples/lua/multi_matrix/mult_matrix.lua b/examples/lua/multi_matrix/mult_matrix.lua index 2aea25d0cb..9700b76984 100644 --- a/examples/lua/multi_matrix/mult_matrix.lua +++ b/examples/lua/multi_matrix/mult_matrix.lua @@ -6,5 +6,4 @@ simgrid.platform("quicksort_platform.xml") simgrid.application("quicksort_deployment.xml") simgrid.run() simgrid.info("Simulation's over.See you.") -simgrid.clean() diff --git a/examples/lua/state_cloner/duplicated_globals.lua b/examples/lua/state_cloner/duplicated_globals.lua index 0675f8ec2b..70366bb8da 100644 --- a/examples/lua/state_cloner/duplicated_globals.lua +++ b/examples/lua/state_cloner/duplicated_globals.lua @@ -40,5 +40,4 @@ print_global() simgrid.platform("../../msg/small_platform.xml") simgrid.application("deployment_duplicated_globals.xml") simgrid.run() -simgrid.clean() diff --git a/examples/lua/tracing/master_slave_trace.lua b/examples/lua/tracing/master_slave_trace.lua index e51b7d1ded..f3ca3f4701 100644 --- a/examples/lua/tracing/master_slave_trace.lua +++ b/examples/lua/tracing/master_slave_trace.lua @@ -19,6 +19,5 @@ end simgrid.run() simgrid.info("Simulation's over.See you.") -simgrid.clean() simgrid.Trace.finish() diff --git a/src/bindings/lua/simgrid_lua.c b/src/bindings/lua/simgrid_lua.c index 3496588228..b2f57d5109 100644 --- a/src/bindings/lua/simgrid_lua.c +++ b/src/bindings/lua/simgrid_lua.c @@ -661,7 +661,7 @@ static int run(lua_State * L) * \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; @@ -730,7 +730,6 @@ static const luaL_Reg simgrid_functions[] = { {"debug", debug}, {"info", info}, {"run", run}, - {"clean", clean}, /* short names */ {"platform", create_environment}, {"application", launch_application}, @@ -835,8 +834,8 @@ lua_State* sglua_get_maestro(void) { * * \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 */ @@ -869,8 +868,8 @@ static void register_task_functions(lua_State* L) { * * \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 */ @@ -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 */ -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); } /** - * \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 */ -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 */ + + /* 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); /* -- */ +} + +/** + * \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); diff --git a/src/msg/msg_global.c b/src/msg/msg_global.c index a6356c9ed1..7ac93dd4f9 100644 --- a/src/msg/msg_global.c +++ b/src/msg/msg_global.c @@ -178,6 +178,7 @@ int MSG_process_killall(int reset_PIDs) */ MSG_error_t MSG_clean(void) { + XBT_DEBUG("Closing MSG"); #ifdef HAVE_TRACING TRACE_surf_release();