Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
reduce verbosity: debug is almost over
[simgrid.git] / src / bindings / ruby / MasterSlave.rb
index 19afa26..848fba2 100644 (file)
@@ -2,18 +2,20 @@
 # make -C ../.. && valgrind ruby MasterSlave.rb --log=ruby.thres:debug 2>&1 | less
 
 require 'simgrid'
+
 include MSG
 
 #################################################
 # Class Master
 #################################################
 
-class Master < MsgProcess  
-  # main : that function that will be executed when Running Simulation
+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 
@@ -23,51 +25,50 @@ class Master < MsgProcess
    slaveCount = Integer(args[3]) 
    
    # Creates and sends the tasks
-   for i in 0..numberOfTask-1
-     task = Task.new("Task_"+ i.to_s, taskComputeSize , taskCommunicationSize);
-     mailbox = "slave " + (i%slaveCount).to_s
-     info("Master Sending "+ Task.name(task) + " to " + mailbox + " with Comput Size " + 
-          Task.compSize(task).to_s)
-#          task.compSize.to_s) # FIXME: This version creates a deadlock. Interesting
-     Task.send(task,mailbox)
-     info("Master Done Sending " +Task.name(task) + " to " + mailbox)
-   end
+    for i in 0..numberOfTask-1
+     task = MSG::Task.new("Task_"+ i.to_s, taskComputeSize , taskCommunicationSize);
+      mailbox = "slave " + (i%slaveCount).to_s
+      MSG::debug("Master Sending "+ task.name + " to " + mailbox + " with Comput Size " + 
+           task.compSize.to_s)
+      task.send(mailbox)
+      MSG::debug("Master Done Sending " + task.name + " 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 "+numberOfTask+" tasks have been dispatched. Let's tell everybody the computation is over.")
+   MSG::info("Master: All tasks have been dispatched. Let's tell everybody the computation is over.")
    for i in 0..slaveCount-1
      mailbox = "slave " + i.to_s
-     info ("Master Sending Finalize to " + mailbox)
-     Task.send(Task.new("finalize",0,0),mailbox)
+     finalize_task = Task.new("finalize",0,0)
+     finalize_task.send(mailbox)
    end
-   info("Master : Everything's Done")
+   MSG::info("Master : Everything's Done")
   end    
 end
 
 #################################################
 # Class Slave
 #################################################
-class Slave < MsgProcess
+class Slave < MSG::Process
+
   def main(args)
     mailbox = "slave " + args[0]
+    for i in 0..args.size-1
+      MSG::debug("args["+String(i)+"]="+args[i])
+    end
 
     while true
-       info("Ready to Receive Task")
-       task = Task.receive(mailbox)
-       task_name = Task.name(task)
-       info ("Task Received : " + task.name)
-       if (task_name == "finalize")
-              info("Slave" + s_mailbox + "got finalize msg")
+       task = MSG::Task.receive(mailbox)
+       if (task.name == "finalize")
               break
        end
-       info("Slave " + s_mailbox + " ...Processing" + Task.name(task))
-       Task.execute(task)
+       task.execute
+       MSG::debug("Slave '" + mailbox + "' done executing task "+ task.name + ".")
     end
-    info("Slave " + s_mailbox +  "I'm Done , See You !!")
+    MSG::info("I'm done, see you")
   end    
 end
 
-
 #################################################
 # main chunck
 #################################################
@@ -78,10 +79,9 @@ if (ARGV.length == 2)
 else 
        MSG.createEnvironment("platform.xml")
        MSG.deployApplication("deploy.xml")
-  #Thread.list.each {|t| p t}
+
 end
 
-# Thread.list.each {|t| p t}
-MSG.run()
-MSG.getClock()
-# exit()
+MSG.run
+puts "Simulation time : " + MSG.getClock .to_s
+MSG.exit