Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[Doc] Added description for the boost context factory
[simgrid.git] / examples / lua / console / master.lua
1 -- Copyright (c) 2011, 2013-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 --Master Function
8 function Master(...)
9
10   if select("#", ...) ~= 4 then
11     error("Wrong number of arguments (got " .. select("#", ...) ..
12         ", expected 4: nb_tasks comp_size comm_size slave_count)")
13   end
14
15   simgrid.info("Hello from lua, I'm the master")
16   for i,v in ipairs({...}) do
17       simgrid.info("Got " .. v)
18   end
19
20   local nb_task, comp_size, comm_size, slave_count = select(1, ...)
21
22   simgrid.info("Argc=" .. select("#", ...) .. " (should be 4)")
23
24   -- Dispatch the tasks
25
26   for i = 1, nb_task do
27     task = simgrid.task.new("Task " .. i, comp_size, comm_size);
28     local task_name = simgrid.task.get_name(task)
29     alias = "slave " .. string.format("%d",i%slave_count);
30     simgrid.info("Master sending  '" .. task_name .. "' To '" .. alias .. "'");
31     simgrid.task.send(task, alias); -- C user data set to NULL
32     simgrid.info("Master done sending '" .. task_name .. "' To '" .. alias .. "'");
33   end
34
35   -- Sending Finalize Message To Others
36
37   simgrid.info("Master: All tasks have been dispatched. Let's tell everybody the computation is over.");
38   for i = 0, slave_count-1 do
39     alias = "slave " .. i;
40     simgrid.info("Master: sending finalize to " .. alias);
41     finalize = simgrid.task.new("finalize", comp_size, comm_size);
42     simgrid.task.send(finalize, alias)
43   end
44   simgrid.info("Master: Everything's done.");
45 end
46 --end_of_master