1 # Debug it with this command:
2 # make -C ../.. && valgrind ruby MasterSlave.rb --log=ruby.thres:debug 2>&1 | less
5 #################################################
7 #################################################
10 class Master < MSG::Process
11 # main : that function that will be executed when running simulation
13 def main(args) # args is an array containing arguments for function master
16 MSG::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 = RTask.new("Task_"+ i.to_s, taskComputeSize , taskCommunicationSize);
28 mailbox = "slave " + (i%slaveCount).to_s
29 MSG::info("Master Sending "+ task.name + " to " + mailbox + " with Comput Size " +
32 MSG::info("Master Done Sending " + task.name + " to " + mailbox)
35 # Sending Finalize MSG::Tasks
36 #MSG::info("Master: All "+numberOfTask+" tasks have been dispatched. Let's tell everybody the computation is over.")
37 MSG::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 finalize_task = RTask.new("finalize",0,0)
41 finalize_task.send(mailbox)
43 MSG::info("Master : Everything's Done")
46 #################################################
48 #################################################
49 class Slave < MSG::Process
52 mailbox = "slave " + args[0]
53 for i in 0..args.size-1
54 MSG::debug("args["+String(i)+"]="+args[i])
58 task = Task.receive(mailbox)
59 if (task.name == "finalize")
63 MSG::debug("Slave '" + mailbox + "' done executing task "+ task.name + ".")
65 MSG::info("I'm done, see you")
68 #################################################
70 #################################################
72 MSG.createEnvironment(ARGV[0])
73 MSG.deployApplication(ARGV[1])
75 MSG.createEnvironment("platform.xml")
76 MSG.deployApplication("deploy.xml")
79 puts "Simulation time : " + MSG.getClock .to_s