X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/2f810149832a2d855c33d0df5b02d736c2081e41..bdaaac614d1bb0ee8e034fa76862068d57e362ee:/examples/lua/chord/chord.lua diff --git a/examples/lua/chord/chord.lua b/examples/lua/chord/chord.lua index bb763bde61..77e19d94dc 100644 --- a/examples/lua/chord/chord.lua +++ b/examples/lua/chord/chord.lua @@ -13,7 +13,7 @@ fix_fingers_delay = 120 check_predecessor_delay = 120 lookup_delay = 10 --- current node (don't worry, globals are duplicated in each process) +-- current node (don't worry, globals are duplicated in each simulated process) my_node = { id = my_id, next_finger_to_fix = 1, @@ -28,7 +28,7 @@ my_node = { -- - the id of a guy I know in the system (except for the first node) function node(...) - -- TODO simplify the parameters + -- TODO simplify the deployment file local known_id local args = {...} my_node.id = tonumber(args[1]) @@ -61,17 +61,17 @@ function node(...) local next_check_predecessor_date = now + check_predecessor_delay local next_lookup_date = now + lookup_delay - local task, success + local task, err while now < max_simulation_time do - task, success = simgrid.comm.test(my_node.comm_recv) + task, err = simgrid.comm.test(my_node.comm_recv) if task then -- I received a task: answer it my_node.comm_recv = simgrid.task.irecv(my_node.id) handle_task(task) - elseif failed then + elseif err then -- the communication has failed: nevermind my_node.comm_recv = simgrid.task.irecv(my_node.id) else @@ -87,6 +87,7 @@ function node(...) elseif now >= next_check_predecessor_date then check_predecessor() next_check_predecessor_date = simgrid.get_clock() + check_predecessor_delay + elseif now >= next_lookup_date then random_lookup() next_lookup_date = simgrid.get_clock() + lookup_delay @@ -129,28 +130,20 @@ function handle_task(task) task.answer_to .. ": the successor of " .. task.request_id .. " is " .. my_node.fingers[1]) - local ans_task = simgrid.task.new("", comp_size, comm_size) - ans_task.type = "find successor answer" - ans_task.request_id = task.request_id - ans_task.answer = my_node.fingers[1] - ans_task:dsend(task.answer_to) + task.type = "find successor answer" + task.answer = my_node.fingers[1] + task:dsend(task.answer_to) else -- forward the request to the closest preceding finger in my table simgrid.info("Forwarding the 'find successor' request to my closest preceding finger") - - local next_task = simgrid.task.new("", comp_size, comm_size) - next_task.type = "find successor" - next_task.request_id = task.request_id - next_task.answer_to = task.answer_to - next_task:dsend(closest_preceding_node(next_task.request_id)) + task:dsend(closest_preceding_node(task.request_id)) end elseif type == "get predecessor" then - local ans_task = simgrid.task.new("", comp_size, comm_size) - ans_task.type = "get predecessor answer" - ans_task.answer = my_node.predecessor - ans_task:dsend(task.answer_to) + task.type = "get predecessor answer" + task.answer = my_node.predecessor + task:dsend(task.answer_to) elseif type == "notify" then -- someone is telling me that he may be my new predecessor