1 # Debug it with this command:
2 # make -C ../.. && valgrind ruby MasterSlave.rb --log=ruby.thres:debug 2>&1 | less
7 #################################################
9 #################################################
11 class Master < MsgProcess
12 # main : that function that will be executed when Running Simulation
13 def main(args) # args is an array containing arguments for function master
16 info("args["+String(i)+"]="+args[i])
19 raise "Master needs 3 arguments" if size < 3
20 numberOfTask = Integer(args[0])
21 taskComputeSize = Float(args[1])
22 taskCommunicationSize = Float(args[2])
23 slaveCount = Integer(args[3])
25 # Creates and sends the tasks
26 for i in 0..numberOfTask-1
27 task = Task.new("Task_"+ i.to_s, taskComputeSize , taskCommunicationSize);
28 mailbox = "slave " + (i%slaveCount).to_s
29 info("Master Sending "+ Task.name(task) + " to " + mailbox + " with Comput Size " +
30 Task.compSize(task).to_s)
31 # task.compSize.to_s) # FIXME: This version creates a deadlock. Interesting
32 Task.send(task,mailbox)
33 info("Master Done Sending " +Task.name(task) + " to " + mailbox)
36 # Sending Finalize Tasks
37 info ("Master: All tasks have been dispatched. Let's tell everybody the computation is over.")
38 for i in 0..slaveCount-1
39 mailbox = "slave " + i.to_s
40 info ("Master Sending Finalize to " + mailbox)
41 Task.send(Task.new("finalize",0,0),mailbox)
43 info("Master : Everything's Done")
47 #################################################
49 #################################################
50 class Slave < MsgProcess
52 mailbox = "slave " + args[0]
55 info("Ready to Receive Task")
56 task = Task.receive(mailbox)
57 task_name = Task.name(task)
58 info ("Task Received : " + task.name)
59 if (task_name == "finalize")
60 info("Slave" + s_mailbox + "got finalize msg")
63 info("Slave " + s_mailbox + " ...Processing" + Task.name(task))
66 info("Slave " + s_mailbox + "I'm Done , See You !!")
71 #################################################
73 #################################################
76 MSG.createEnvironment(ARGV[0])
77 MSG.deployApplication(ARGV[1])
79 MSG.createEnvironment("platform.xml")
80 MSG.deployApplication("deploy.xml")
81 #Thread.list.each {|t| p t}
84 # Thread.list.each {|t| p t}