Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add/update copyright notices.
[simgrid.git] / examples / lua / masterslave / slave.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 Slave(...)
8
9   if #arg ~= 1 then
10     error("Wrong number of arguments (got " .. #arg .. ", expected 1: slave_id)")
11   end
12
13   local my_mailbox = "slave " .. arg[1]
14   simgrid.info("Hello from lua, I'm a poor slave with mailbox: " .. my_mailbox)
15
16   while true do
17
18     local task = simgrid.task.recv(my_mailbox)
19     local task_name = task:get_name()
20     if (task_name == "finalize") then
21       simgrid.info("Got finalize message")
22       break
23     end
24     simgrid.info("Received task '" .. task_name .. "' on mailbox '" .. my_mailbox .. "'")
25     task:execute()
26     simgrid.info("Task '" .. task_name .. "' is done")
27   end
28
29   simgrid.info("I'm done. See you!")
30 end -- end_of_slave
31