3 #################################################
5 #################################################
7 class Master < MSG::Process
8 # main : that function that will be executed when running simulation
10 def main(args) # args is an array containing arguments for function master
13 MSG::info("args["+String(i)+"]="+args[i])
16 raise "Master needs 3 arguments" if size < 3
17 numberOfTask = Integer(args[0])
18 taskComputeSize = Float(args[1])
19 taskCommunicationSize = Float(args[2])
20 slaveCount = Integer(args[3])
22 # Creates and sends the tasks
23 for i in 0..numberOfTask-1
24 task = Task.new("Task_"+ i.to_s, taskComputeSize , taskCommunicationSize);
25 mailbox = "slave " + (i%slaveCount).to_s
26 MSG::info("Master Sending "+ task.name + " to " + mailbox + " with Comput Size " +
29 MSG::info("Master Done Sending " + task.name + " to " + mailbox)
32 # Sending Finalize MSG::Tasks
33 #MSG::info("Master: All "+numberOfTask+" tasks have been dispatched. Let's tell everybody the computation is over.")
34 MSG::info("Master: All tasks have been dispatched. Let's tell everybody the computation is over.")
35 for i in 0..slaveCount-1
36 mailbox = "slave " + i.to_s
37 finalize_task = Task.new("finalize",0,0)
38 finalize_task.send(mailbox)
40 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")
71 #################################################
73 #################################################
75 MSG.createEnvironment(ARGV[0])
76 MSG.deployApplication(ARGV[1])
78 MSG.createEnvironment("platform.xml")
79 MSG.deployApplication("deploy.xml")
82 puts "Simulation time : " + MSG.getClock .to_s