Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Do not request status if not requested by caller.
[simgrid.git] / src / bindings / ruby / PingPong.rb
1 require 'simgrid'
2
3 include MSG
4
5 #####################
6 #PingPongTask Class
7 #####################
8
9 class PingPongTask < MSG::Task
10   
11   def initialize(*args)
12   puts "Here is the ping pong initializer"
13     #Has No Role, Since Its The Task Class ( Created from C ) tht will be called , 
14     # and any instruction here will be ignored
15   end
16
17 end
18
19 ####################
20 # Sender Class
21 ####################
22
23 class Sender < MSG::Process
24   
25  def main(args)
26    MSG::info("Hello from Sender")
27    hostCount = args.size
28    MSG::info("Host count :" + hostCount.to_s)
29    mailboxes = Array.new
30       
31    for i in 0..hostCount-1
32    
33      mailboxes<< MSG::Host.getByName(args[i]).name
34      
35 #      FIXME Handel Exceptions 
36    end
37    
38    for i in 0..hostCount-1
39      time = MSG.getClock
40      MSG::info("sender time :"+time.to_s)
41      task = PingPongTask.new("PingTask",10000,2000)
42      MSG::info("task created :" + task.name);
43      task.setData(time)
44      p "mailboxe >>> "+ mailboxes[i]
45      task.send(mailboxes[i])
46    end
47    
48    MSG::info("GoodBye !!!")     
49    
50    end
51    
52  end
53   
54 ####################
55 # Receiver Class
56 ####################
57
58 class Receiver < MSG::Process
59   
60   def main(args)
61     MSG::info("Hello from Receiver")
62     time = MSG.getClock
63     MSG::info("Try to get a task")
64     host = MSG::Host.getHostProcess(self)
65     task = PingPongTask.receive(host.name)
66     p "task name recevied : "+ task.name
67     timeGot = MSG.getClock
68     MSG::info("Got at time: "+timeGot.to_s)
69     timeSent = task.data
70     MSG::info("Was sent at time "+timeSent.to_s)
71     communicationTime = timeGot - time
72     MSG::info("Communication Time: "+communicationTime.to_s)
73     MSG::info("--- bw "+(100000000/communicationTime).to_s+" ----")
74     MSG::info("GoodBye !!!")
75   end
76   
77 end
78
79 #################################################
80 # main chunck
81 #################################################
82
83 if (ARGV.length == 2) 
84         MSG.createEnvironment(ARGV[0])
85         MSG.deployApplication(ARGV[1])
86 else 
87         MSG.createEnvironment("ping_pong_platform.xml")
88         MSG.deployApplication("ping_pong_deployment.xml")
89 end
90
91 MSG.run
92 MSG.exit
93