X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/d2e821780d4e656ef56a50cd334893799c660a05..7ce752524bd815bb66b262e4288903c6a9ebfc93:/examples/lua/masterslave/master.lua diff --git a/examples/lua/masterslave/master.lua b/examples/lua/masterslave/master.lua index 63b900c755..31ee9c5731 100644 --- a/examples/lua/masterslave/master.lua +++ b/examples/lua/masterslave/master.lua @@ -1,41 +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); - alias = "slave "..(i%slave_count); - simgrid.info("Master sending '" .. simgrid.Task.name(tk) .."' To '" .. alias .."'"); - simgrid.Task.send(tk,alias); -- C user data set to NULL - simgrid.info("Master done sending '".. simgrid.Task.name(tk) .."' 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 +-- Copyright (c) 2011-2012, 2014. The SimGrid Team. +-- All rights reserved. + +-- 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. + +function Master(...) + + if select("#", ...) ~= 4 then + error("Wrong number of arguments (got " .. #arg .. + ", expected 4: nb_tasks comp_size comm_size slave_count)") + end + + local nb_task, comp_size, comm_size, slave_count = select(1, ...) + simgrid.info("Hello from lua, I'm the master") + + + -- Dispatch the tasks + + for i = 1, nb_task do + local task = simgrid.task.new("Task " .. i, comp_size, comm_size) + local task_name = task:get_name() + local alias = "slave " .. string.format("%d", i % slave_count) + 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("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("Sending finalize to '" .. alias .. "'") + local finalize = simgrid.task.new("finalize", comp_size, comm_size) + finalize:send(alias) + end + simgrid.info("Everything's done.") +end -- end_of_master +