X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/abaf4c302b65411b41d1c288cfefb8d069395b60..efd71a79ebaec3760d2799bd90c5e5cf96ac0bfa:/examples/ruby/PingPong.rb diff --git a/examples/ruby/PingPong.rb b/examples/ruby/PingPong.rb new file mode 100644 index 0000000000..73b51532ff --- /dev/null +++ b/examples/ruby/PingPong.rb @@ -0,0 +1,88 @@ +require 'simgrid' + +include MSG + +##################### +#PingPongTask Class +##################### + +class PingPongTask < MSG::Task + + # The initialize method has no effect + @time + def setTime(t) + @time = t + end + + def getTime() + return @time + end +end + +#################### +# Sender Class +#################### + +class Sender < MSG::Process + + def main(args) + MSG::info("Hello from Sender") + hostCount = args.size + MSG::info("Host count :" + hostCount.to_s) + mailboxes = Array.new + + for i in 0..hostCount-1 + mailboxes<< MSG::Host.getByName(args[i]).name + end + + for i in 0..hostCount-1 + time = MSG.getClock + MSG::info("sender time :"+time.to_s) + task = PingPongTask.new("PingTask",10000,2000) + MSG::info("task created :" + task.name); + #task.join(time) -- MSG::task.join(data) is a Native method you can use to attach any data you want to the task + task.setTime(time) + task.send(mailboxes[i]) + end + MSG::info("Bye!!") + end + end + +#################### +# Receiver Class +#################### + +class Receiver < MSG::Process + + def main(args) + MSG::info("Hello from Receiver") + time = MSG.getClock + host = MSG::Host.getHostProcess(self) + task = PingPongTask.receive(host.name) + timeGot = MSG.getClock + MSG::info("Got at time: "+timeGot.to_s) + #timeSent = task.data -- + timeSent = task.getTime + MSG::info("Was sent at time "+timeSent.to_s) + communicationTime = timeGot - time + MSG::info("Communication Time: "+communicationTime.to_s) + MSG::info("--- bw "+(100000000/communicationTime).to_s+" ----") + MSG::info("Bye!!") + end + +end + +################################################# +# main chunck +################################################# + +if (ARGV.length == 2) + MSG.createEnvironment(ARGV[0]) + MSG.deployApplication(ARGV[1]) +else + MSG.createEnvironment("ping_pong_platform.xml") + MSG.deployApplication("ping_pong_deployment.xml") +end + +MSG.run +MSG.exit \ No newline at end of file