Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Try to activate coverity for simgrid
[simgrid.git] / examples / lua / masterslave / master.lua
1 -- Copyright (c) 2011-2012, 2014. The SimGrid Team.
2 -- All rights reserved.
3
4 -- This program is free software; you can redistribute it and/or modify it
5 -- under the terms of the license (GNU LGPL) which comes with this package.
6
7 function Master(...)
8
9   if select("#", ...) ~= 4 then
10     error("Wrong number of arguments (got " .. #arg ..
11         ", expected 4: nb_tasks comp_size comm_size slave_count)")
12   end
13
14   local nb_task, comp_size, comm_size, slave_count = select(1, ...)
15   simgrid.info("Hello from lua, I'm the master")
16
17
18   -- Dispatch the tasks
19
20   for i = 1, nb_task do
21     local task = simgrid.task.new("Task " .. i, comp_size, comm_size)
22     local task_name = task:get_name()
23     local alias = "slave " .. string.format("%d", i % slave_count)
24     simgrid.info("Sending  '" .. task_name .. "' to '" .. alias .."'")
25     task:send(alias) -- C user data set to NULL
26     simgrid.info("Done sending '".. task_name .. "' to '" .. alias .."'")
27   end
28
29   -- Sending Finalize Message To Others
30
31   simgrid.info("All tasks have been dispatched. Let's tell everybody the computation is over.")
32   for i = 0, slave_count - 1 do
33     local alias = "slave " .. i
34     simgrid.info("Sending finalize to '" .. alias .. "'")
35     local finalize = simgrid.task.new("finalize", comp_size, comm_size)
36     finalize:send(alias)
37   end
38   simgrid.info("Everything's done.")
39 end -- end_of_master
40