3 #################################################
5 #################################################
8 class Master < MSG::Process
9 # main : that function that will be executed when running simulation
11 def main(args) # args is an array containing arguments for function master
14 MSG::info("args["+String(i)+"]="+args[i])
17 raise "Master needs 3 arguments" if size < 3
18 numberOfTask = Integer(args[0])
19 taskComputeSize = Float(args[1])
20 taskCommunicationSize = Float(args[2])
21 slaveCount = Integer(args[3])
23 # Creates and sends the tasks
24 for i in 0..numberOfTask-1
25 task = Task.new("Task_"+ i.to_s, taskComputeSize , taskCommunicationSize);
26 mailbox = "slave " + (i%slaveCount).to_s
27 MSG::info("Master Sending "+ task.name + " to " + mailbox + " with Comput Size " +
30 MSG::info("Master Done Sending " + task.name + " to " + mailbox)
33 # Sending Finalize MSG::Tasks
34 #MSG::info("Master: All "+numberOfTask+" tasks have been dispatched. Let's tell everybody the computation is over.")
35 MSG::info("Master: All tasks have been dispatched. Let's tell everybody the computation is over.")
36 for i in 0..slaveCount-1
37 mailbox = "slave " + i.to_s
38 finalize_task = Task.new("finalize",0,0)
39 finalize_task.send(mailbox)
41 MSG::info("Master : Everything's Done")
44 #################################################
46 #################################################
47 class Slave < MSG::Process
50 mailbox = "slave " + args[0]
51 for i in 0..args.size-1
52 MSG::debug("args["+String(i)+"]="+args[i])
56 task = Task.receive(mailbox)
57 if (task.name == "finalize")
61 MSG::debug("Slave '" + mailbox + "' done executing task "+ task.name + ".")
63 MSG::info("I'm done, see you")
66 #################################################
68 #################################################
70 MSG.createEnvironment(ARGV[0])
71 MSG.deployApplication(ARGV[1])
73 MSG.createEnvironment("platform.xml")
74 MSG.deployApplication("deploy.xml")
77 puts "Simulation time : " + MSG.getClock .to_s