X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/114b09ec24846920da14854ba06cf48d1d7d6dba..45c3f1cfee86fb48c96d53f8267f99b6db6e3d7a:/examples/lua/masterslave/master.lua diff --git a/examples/lua/masterslave/master.lua b/examples/lua/masterslave/master.lua index 8a081c1cfe..0cd88bc1c1 100644 --- a/examples/lua/masterslave/master.lua +++ b/examples/lua/masterslave/master.lua @@ -1,40 +1,40 @@ -function Master(...) +-- Copyright (c) 2011-2012, 2014. The SimGrid Team. +-- All rights reserved. - simgrid.info("Hello from lua, I'm the master") - for i, v in ipairs(arg) do - simgrid.info("Got "..v) - end +-- 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. - local nb_task = arg[1] - local comp_size = arg[2] - local comm_size = arg[3] - local slave_count = arg[4] +function Master(...) if #arg ~= 4 then - error("Argc should be 4") + error("Wrong number of arguments (got " .. #arg .. + ", expected 4: nb_tasks comp_size comm_size slave_count)") end - simgrid.info("Argc=" .. (#arg) .. " (should be 4)") + + simgrid.info("Hello from lua, I'm the master") + + local nb_task, comp_size, comm_size, slave_count = unpack(arg) -- Dispatch the tasks for i = 1, nb_task do - local tk = simgrid.Task.new("Task "..i, comp_size, comm_size) - local task_name = simgrid.Task.name(tk) + local task = simgrid.task.new("Task " .. i, comp_size, comm_size) + local task_name = task:get_name() local 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 .."'") + simgrid.info("Sending '" .. task_name .. "' to '" .. alias .."'") + task:send(alias) -- C user data set to NULL + simgrid.info("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.") + simgrid.info("All tasks have been dispatched. Let's tell everybody the computation is over.") for i = 0, slave_count - 1 do local alias = "slave " .. i - simgrid.info("Master: sending finalize to " .. alias) - local finalize = simgrid.Task.new("finalize", comp_size, comm_size) - simgrid.Task.send(finalize, alias) + simgrid.info("Sending finalize to '" .. alias .. "'") + local finalize = simgrid.task.new("finalize", comp_size, comm_size) + finalize:send(alias) end - simgrid.info("Master: Everything's done.") -end -- Master + simgrid.info("Everything's done.") +end -- end_of_master