From d947ff7466b473eeec602007934f8336a9b17f3c Mon Sep 17 00:00:00 2001 From: =?utf8?q?Paul=20B=C3=A9daride?= Date: Fri, 4 Jan 2013 10:36:45 +0100 Subject: [PATCH 1/1] Fix lua platform script --- examples/lua/console/master.lua | 70 ++++++++++---------- examples/lua/console/master_slave_bypass.lua | 7 +- examples/lua/console/slave.lua | 34 ++++++---- src/bindings/lua/lua_platf.c | 51 ++++++-------- 4 files changed, 80 insertions(+), 82 deletions(-) diff --git a/examples/lua/console/master.lua b/examples/lua/console/master.lua index 849b18b787..2ce311816e 100644 --- a/examples/lua/console/master.lua +++ b/examples/lua/console/master.lua @@ -1,42 +1,40 @@ --Master Function function Master(...) -simgrid.info("Hello from lua, I'm the master") -for i,v in ipairs(arg) do - simgrid.info("Got "..v) -end - -nb_task = arg[1]; -comp_size = arg[2]; -comm_size = arg[3]; -slave_count = arg[4]; - -if (#arg ~= 4) then - error("Argc should be 4"); -end -simgrid.info("Argc="..(#arg).." (should be 4)") - --- Dispatch the tasks - -for i=1,nb_task do - tk = simgrid.task.new("Task "..i,comp_size,comm_size); - local task_name = simgrid.task.get_name(tk) - alias = "slave "..(i%slave_count); - simgrid.info("Master sending '" .. task_name .."' To '" .. alias .."'"); - simgrid.task.send(tk,alias); -- C user data set to NULL - simgrid.info("Master done sending '".. task_name .."' To '" .. alias .."'"); -end - --- Sending Finalize Message To Others - -simgrid.info("Master: All tasks have been dispatched. Let's tell everybody the computation is over."); -for i=0,slave_count-1 do - alias = "slave "..i; - simgrid.info("Master: sending finalize to "..alias); - finalize = simgrid.task.new("finalize",comp_size,comm_size); - simgrid.task.send(finalize,alias) -end + if #arg ~= 4 then + error("Wrong number of arguments (got " .. #arg .. + ", expected 4: nb_tasks comp_size comm_size slave_count)") + end + + simgrid.info("Hello from lua, I'm the master") + for i,v in ipairs(arg) do + simgrid.info("Got " .. v) + end + + local nb_task, comp_size, comm_size, slave_count = unpack(arg) + + simgrid.info("Argc=" .. (#arg) .. " (should be 4)") + + -- Dispatch the tasks + + for i = 1, nb_task do + task = simgrid.task.new("Task " .. i, comp_size, comm_size); + local task_name = simgrid.task.get_name(task) + alias = "slave " .. (i%slave_count); + simgrid.info("Master sending '" .. task_name .. "' To '" .. alias .. "'"); + simgrid.task.send(task, alias); -- C user data set to NULL + simgrid.info("Master done sending '" .. task_name .. "' To '" .. alias .. "'"); + end + + -- Sending Finalize Message To Others + + simgrid.info("Master: All tasks have been dispatched. Let's tell everybody the computation is over."); + for i = 0, slave_count-1 do + alias = "slave " .. i; + simgrid.info("Master: sending finalize to " .. alias); + finalize = simgrid.task.new("finalize", comp_size, comm_size); + simgrid.task.send(finalize, alias) + end simgrid.info("Master: Everything's done."); end - --end_of_master diff --git a/examples/lua/console/master_slave_bypass.lua b/examples/lua/console/master_slave_bypass.lua index 37338f1a1e..3f3fd9c191 100644 --- a/examples/lua/console/master_slave_bypass.lua +++ b/examples/lua/console/master_slave_bypass.lua @@ -1,7 +1,10 @@ require "simgrid" dofile 'platform.lua' -dofile 'deploy.lua' +--dofile 'deploy.lua' --Rutform.lua' +dofile 'master.lua' +dofile 'slave.lua' + --dofile 'deploy.lua' + simgrid.application("deployb.xml") simgrid.run() simgrid.info("Simulation's over.See you.") - diff --git a/examples/lua/console/slave.lua b/examples/lua/console/slave.lua index 1c77467105..2073530c4c 100644 --- a/examples/lua/console/slave.lua +++ b/examples/lua/console/slave.lua @@ -3,23 +3,29 @@ -- Slave Function --------------------------------------------------------- function Slave(...) -local my_mailbox="slave "..arg[1] -simgrid.info("Hello from lua, I'm a poor slave with mbox: "..my_mailbox) + if #arg ~= 1 then + error("Wrong number of arguments (got " .. #arg .. ", expected 1: slave_id)") + end -while true do + local my_mailbox = "slave " .. arg[1] + simgrid.info("Hello from lua, I'm a poor slave with mbox: " .. my_mailbox) - local tk = simgrid.task.recv(my_mailbox); - if (simgrid.task.get_name(tk) == "finalize") then - simgrid.info("Slave '" ..my_mailbox.."' got finalize msg"); - break - end - --local tk_name = simgrid.task.get_name(tk) - simgrid.info("Slave '" ..my_mailbox.."' processing "..simgrid.task.get_name(tk)) - simgrid.task.execute(tk) - simgrid.info("Slave '" ..my_mailbox.."': task "..simgrid.task.get_name(tk) .. " done") -end -- while + while true do + + local task = simgrid.task.recv(my_mailbox); + --print(task) + local task_name = task:get_name() + if (task_name == "finalize") then + simgrid.info("Slave '" .. my_mailbox .. "' got finalize msg"); + break + end + --local tk_name = simgrid.task.get_name(tk) + simgrid.info("Slave '" .. my_mailbox .. "' processing " .. task_name) + simgrid.task.execute(task) + simgrid.info("Slave '" .. my_mailbox .. "': task " .. task_name .. " done") + end -- while -simgrid.info("Slave '" ..my_mailbox.."': I'm Done . See You !!"); + simgrid.info("Slave '" .. my_mailbox .. "': I'm Done . See You !!"); end -- end_of_slave diff --git a/src/bindings/lua/lua_platf.c b/src/bindings/lua/lua_platf.c index 4625c7846e..7514c7121d 100644 --- a/src/bindings/lua/lua_platf.c +++ b/src/bindings/lua/lua_platf.c @@ -42,8 +42,12 @@ int console_open(lua_State *L) { sg_platf_init(); sg_platf_begin(); surf_parse_init_callbacks(); + + storage_register_callbacks(); routing_register_callbacks(); + gpu_register_callbacks(); + return 0; } @@ -104,7 +108,8 @@ int console_add_host(lua_State *L) { //get power_scale lua_pushstring(L, "power_scale"); lua_gettable(L, -2); - host.power_scale = lua_tonumber(L, -1); + if(!lua_isnumber(L,-1)) host.power_scale = 1;// Default value + else host.power_scale = lua_tonumber(L, -1); lua_pop(L, 1); //get power_trace @@ -188,7 +193,7 @@ int console_add_link(lua_State *L) { //get state_initial value lua_pushstring(L, "state_initial"); lua_gettable(L, -2); - if (lua_tonumber(L, -1)) + if (!lua_isnumber(L,-1) || lua_tonumber(L, -1)) link.state = SURF_RESOURCE_ON; else link.state = SURF_RESOURCE_OFF; @@ -241,18 +246,13 @@ int console_add_router(lua_State* L) { #include "surf/surfxml_parse.h" /* to override surf_parse and bypass the parser */ int console_add_route(lua_State *L) { - static int AX_ptr = 0; - static int surfxml_bufferstack_size = 2048; + s_sg_platf_route_cbarg_t route; + memset(&route,0,sizeof(route)); /* allocating memory for the buffer, I think 2kB should be enough */ surfxml_bufferstack = xbt_new0(char, surfxml_bufferstack_size); - const char*src; - const char*dst; int is_symmetrical; - xbt_dynar_t links; - unsigned int cursor; - char *link_id; if (! lua_istable(L, -1)) { XBT_ERROR("Bad Arguments to create a route, Should be a table with named arguments"); @@ -261,19 +261,19 @@ int console_add_route(lua_State *L) { lua_pushstring(L,"src"); lua_gettable(L,-2); - src = lua_tostring(L, -1); + route.src = lua_tostring(L, -1); lua_pop(L,1); lua_pushstring(L,"dest"); lua_gettable(L,-2); - dst = lua_tostring(L, -1); + route.dst = lua_tostring(L, -1); lua_pop(L,1); lua_pushstring(L,"links"); lua_gettable(L,-2); - links = xbt_str_split(lua_tostring(L, -1), ", \t\r\n"); - if (xbt_dynar_is_empty(links)) - xbt_dynar_push_as(links,char*,xbt_strdup(lua_tostring(L, -1))); + route.link_list = xbt_str_split(lua_tostring(L, -1), ", \t\r\n"); + if (xbt_dynar_is_empty(route.link_list)) + xbt_dynar_push_as(route.link_list,char*,xbt_strdup(lua_tostring(L, -1))); lua_pop(L,1); lua_pushstring(L,"symmetrical"); @@ -281,28 +281,19 @@ int console_add_route(lua_State *L) { is_symmetrical = lua_tointeger(L, -1); lua_pop(L,1); + route.gw_src = NULL; + route.gw_dst = NULL; + /* We are relying on the XML bypassing mechanism since the corresponding sg_platf does not exist yet. * Et ouais mon pote. That's the way it goes. F34R. */ - SURFXML_BUFFER_SET(route_src, src); - SURFXML_BUFFER_SET(route_dst, dst); if (is_symmetrical) - A_surfxml_route_symmetrical = A_surfxml_route_symmetrical_YES; + route.symmetrical = TRUE; else - A_surfxml_route_symmetrical = A_surfxml_route_symmetrical_NO; - SURFXML_START_TAG(route); - - xbt_dynar_foreach(links,cursor,link_id) { - SURFXML_BUFFER_SET(link___ctn_id, link_id); - A_surfxml_link___ctn_direction = A_surfxml_link___ctn_direction_NONE; - SURFXML_START_TAG(link___ctn); - SURFXML_END_TAG(link___ctn); - } - SURFXML_END_TAG(route); - - xbt_dynar_free(&links); - free(surfxml_bufferstack); + route.symmetrical = FALSE; + sg_platf_new_route(&route); + return 0; } -- 2.20.1