Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@7180 48e7efb5...
[simgrid.git] / src / bindings / ruby / MasterSlave.rb
index aafa5ed..e945b7a 100644 (file)
@@ -2,88 +2,71 @@
 # make -C ../.. && valgrind ruby MasterSlave.rb --log=ruby.thres:debug 2>&1 | less
 
 require 'simgrid'
+
 include MSG
 
 #################################################
 # Class Master
 #################################################
 
-class Master < MsgProcess  
-  def initialize2()
-    super()
-  end
-  
-  # msg_main : that function that will be executed when Running Simulation
-  def msg_main(args) # args is an array containing arguments for function master
-    info("Hello From Master")
-    size = args.size
-    info ("Number of Args for Master = " + size.to_s)
+class Master < MSG::Process  
+  # main : that function that will be executed when Running Simulation
+  def main(args) # args is an array containing arguments for function master
+   size = args.size
    for i in 0..size-1
-      info("args["+String(i)+"]="+args[i])
+     MSG::info("args["+String(i)+"]="+args[i])
    end
-   
+  
    raise "Master needs 3 arguments" if size < 3 
    numberOfTask = Integer(args[0]) 
    taskComputeSize = Float(args[1])
    taskCommunicationSize = Float(args[2])
    slaveCount = Integer(args[3]) 
    
-   #Creating & Sending Task
+   # Creates and sends the tasks
    for i in 0..numberOfTask-1
-  
-     
-     task = Task.new("Task_"+ i.to_s, taskComputeSize , taskCommunicationSize );
-     s_alias = "slave>>" + (i%slaveCount).to_s
-     info("Master Sending "+ Task.name(task) + " to " + s_alias + " with Comput Size " + Task.compSize(task).to_s)
-     Task.send(task,s_alias)
-     info("Master Done Sending " +Task.name(task) + " to " + s_alias)
-#       sameTask = Task.receive(s_alias)
-#      puts "Master Receiving its Own Task"
+     task = MSG::Task.new("Task_"+ i.to_s, taskComputeSize , taskCommunicationSize);
+     mailbox = "slave " + (i%slaveCount).to_s
+     MSG::info("Master Sending "+ MSG::Task.name(task) + " to " + mailbox + " with Comput Size " + 
+          MSG::Task.compSize(task).to_s)
+#          task.compSize.to_s) # FIXME: This version creates a deadlock. Interesting
+     MSG::Task.send(task,mailbox)
+     MSG::info("Master Done Sending " +MSG::Task.name(task) + " to " + mailbox)
    end
   
-   # Sending Finalize Tasks
-   info ("Master: All tasks have been dispatched. Let's tell everybody the computation is over.")
+   # Sending Finalize MSG::Tasks
+   MSG::info("Master: All tasks have been dispatched. Let's tell everybody the computation is over.")
    for i in 0..slaveCount-1
-     s_alias = "slave " + i.to_s
-     info ("Master Sending Finalize to " + s_alias)
-     Task.send(Task.new("finalize",0,0),s_alias)
+     mailbox = "slave " + i.to_s
+     MSG::info("Master Sending Finalize to " + mailbox)
+     MSG::Task.send(Task.new("finalize",0,0),mailbox)
    end
-   info("Master : Everything's Done")
+   MSG::info("Master : Everything's Done")
   end    
 end
 
 #################################################
 # Class Slave
 #################################################
-class Slave < MsgProcess
-  
-  def initialize()
-    super()
-  end
-  
- # msg_main : that function that will be executed when Running Simulation
-  def msg_main(args)
-    info("Hello From Slave")
-    s_mailbox = "slave>>" + args[0]
+class Slave < MSG::Process
+  def main(args)
+    mailbox = "slave " + args[0]
 
     while true
-        
        info("Ready to Receive Task")
-       task = Task.receive(s_mailbox)
-       task_name = Task.name(task)
-       info ("Task Received : " + task.name)
-      if (task_name == "finalize")
-       info("Slave" + s_mailbox + "got finalize msg")
-       break
-      end
-      info("Slave " + s_mailbox + " ...Processing" + Task.name(task))
-       Task.execute(task)
-    end
-    info("Slave " + s_mailbox +  "I'm Done , See You !!")
+       task = MSG::Task.receive(mailbox)
+       task_name = MSG::Task.name(task)
+       MSG::info("Task Received : " + task.name)
+       if (task_name == "finalize")
+              MSG::info("Slave" + s_mailbox + "got finalize msg")
+              break
+       end
+       MSG::info("Slave " + s_mailbox + " ...Processing" + MSG::Task.name(task))
+       MSG::Task.execute(task)
     end
-    
-  end
+    MSG::info("Slave " + s_mailbox +  "I'm Done , See You !!")
+  end    
+end
 
 
 #################################################
@@ -96,10 +79,10 @@ if (ARGV.length == 2)
 else 
        MSG.createEnvironment("platform.xml")
        MSG.deployApplication("deploy.xml")
-  Thread.list.each {|t| p t}
+  #Thread.list.each {|t| p t}
 end
 
 # Thread.list.each {|t| p t}
-MSG.run()
-MSG.getClock()
+MSG.run
+MSG.getClock #FIXME: write "puts MSG.getClock" instead
 # exit()