Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Further cleanups of ruby, plus add FIXME in ruby and Java for the next cleanups
authormquinson <mquinson@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Tue, 2 Mar 2010 17:10:10 +0000 (17:10 +0000)
committermquinson <mquinson@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Tue, 2 Mar 2010 17:10:10 +0000 (17:10 +0000)
git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@7170 48e7efb5-ca39-0410-a469-dd3cf9ba447f

src/bindings/ruby/MasterSlave.rb
src/bindings/ruby/simgrid.rb
src/bindings/ruby/simgrid_ruby.c
src/java/jmsg.c
src/java/simgrid/msg/ApplicationHandler.java
src/java/simgrid/msg/Msg.java
src/java/simgrid/msg/MsgNative.java

index 19afa26..e945b7a 100644 (file)
@@ -2,18 +2,19 @@
 # make -C ../.. && valgrind ruby MasterSlave.rb --log=ruby.thres:debug 2>&1 | less
 
 require 'simgrid'
 # make -C ../.. && valgrind ruby MasterSlave.rb --log=ruby.thres:debug 2>&1 | less
 
 require 'simgrid'
+
 include MSG
 
 #################################################
 # Class Master
 #################################################
 
 include MSG
 
 #################################################
 # Class Master
 #################################################
 
-class Master < MsgProcess  
+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
   # 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 
    end
   
    raise "Master needs 3 arguments" if size < 3 
@@ -24,46 +25,46 @@ class Master < MsgProcess
    
    # Creates and sends the tasks
    for i in 0..numberOfTask-1
    
    # Creates and sends the tasks
    for i in 0..numberOfTask-1
-     task = Task.new("Task_"+ i.to_s, taskComputeSize , taskCommunicationSize);
+     task = MSG::Task.new("Task_"+ i.to_s, taskComputeSize , taskCommunicationSize);
      mailbox = "slave " + (i%slaveCount).to_s
      mailbox = "slave " + (i%slaveCount).to_s
-     info("Master Sending "+ Task.name(task) + " to " + mailbox + " with Comput Size " + 
-          Task.compSize(task).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
 #          task.compSize.to_s) # FIXME: This version creates a deadlock. Interesting
-     Task.send(task,mailbox)
-     info("Master Done Sending " +Task.name(task) + " to " + mailbox)
+     MSG::Task.send(task,mailbox)
+     MSG::info("Master Done Sending " +MSG::Task.name(task) + " to " + mailbox)
    end
   
    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
      mailbox = "slave " + i.to_s
    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)
+     MSG::info("Master Sending Finalize to " + mailbox)
+     MSG::Task.send(Task.new("finalize",0,0),mailbox)
    end
    end
-   info("Master : Everything's Done")
+   MSG::info("Master : Everything's Done")
   end    
 end
 
 #################################################
 # Class Slave
 #################################################
   end    
 end
 
 #################################################
 # Class Slave
 #################################################
-class Slave < MsgProcess
+class Slave < MSG::Process
   def main(args)
     mailbox = "slave " + args[0]
 
     while true
        info("Ready to Receive Task")
   def main(args)
     mailbox = "slave " + args[0]
 
     while true
        info("Ready to Receive Task")
-       task = Task.receive(mailbox)
-       task_name = Task.name(task)
-       info ("Task Received : " + task.name)
+       task = MSG::Task.receive(mailbox)
+       task_name = MSG::Task.name(task)
+       MSG::info("Task Received : " + task.name)
        if (task_name == "finalize")
        if (task_name == "finalize")
-              info("Slave" + s_mailbox + "got finalize msg")
+              MSG::info("Slave" + s_mailbox + "got finalize msg")
               break
        end
               break
        end
-       info("Slave " + s_mailbox + " ...Processing" + Task.name(task))
-       Task.execute(task)
+       MSG::info("Slave " + s_mailbox + " ...Processing" + MSG::Task.name(task))
+       MSG::Task.execute(task)
     end
     end
-    info("Slave " + s_mailbox +  "I'm Done , See You !!")
+    MSG::info("Slave " + s_mailbox +  "I'm Done , See You !!")
   end    
 end
 
   end    
 end
 
@@ -82,6 +83,6 @@ else
 end
 
 # 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()
 # exit()
index 1eed817..2cfeacf 100644 (file)
@@ -1,8 +1,7 @@
 require 'simgrid_ruby'
 require 'simgrid_ruby'
-include MSG
 require 'thread'
 
 require 'thread'
 
-$DEBUG = false  # This is a Global Variable Useful for Debugging
+$DEBUG = false  # This is a Global Variable Useful for MSG::debugging
 
 ###########################################################################
 # Class Semaphore 
 
 ###########################################################################
 # Class Semaphore 
@@ -15,6 +14,7 @@ class Semaphore
   end
 
   def acquire
   end
 
   def acquire
+    MSG::debug("Acquire "+self.to_s)
     Thread.critical = true
     if (@counter -= 1) < 0
       @waiting_list.push(Thread.current)
     Thread.critical = true
     if (@counter -= 1) < 0
       @waiting_list.push(Thread.current)
@@ -26,11 +26,15 @@ class Semaphore
   end
 
   def release
   end
 
   def release
+    MSG::debug("Release "+self.to_s)
     Thread.critical = true
     begin
       if (@counter += 1) <= 0
     Thread.critical = true
     begin
       if (@counter += 1) <= 0
-  t = @waiting_list.shift
-  t.wakeup if t
+        t = @waiting_list.shift
+        t.wakeup if t
+        MSG::debug("Wakeup "+t.to_s)
+      else 
+        MSG::debug("Nobody to wakeup")
       end
     rescue ThreadError
       retry
       end
     rescue ThreadError
       retry
@@ -44,7 +48,7 @@ end
 ########################################################################
 # Class Process 
 ########################################################################
 ########################################################################
 # Class Process 
 ########################################################################
-class MsgProcess < Thread 
+class MSG::Process < Thread 
   @@nextProcessId = 0
 
 # Attributes
   @@nextProcessId = 0
 
 # Attributes
@@ -53,6 +57,7 @@ class MsgProcess < Thread
   
 # Initialize : Used from ApplicationHandler to fill it in
   def initialize(*args)
   
 # Initialize : Used from ApplicationHandler to fill it in
   def initialize(*args)
+    # FIXME: use only one variante (the one with 3 args) and kill the others
     @schedBegin = Semaphore.new(0)
     @schedEnd = Semaphore.new(0)    
     @properties = Hash.new()
     @schedBegin = Semaphore.new(0)
     @schedEnd = Semaphore.new(0)    
     @properties = Hash.new()
@@ -67,13 +72,13 @@ class MsgProcess < Thread
         @name = ""
         @pargs = Array.new()
         start()
         @name = ""
         @pargs = Array.new()
         start()
-        debug "Initializer without any argument"
+        MSG::debug "Initializer without any argument"
       }
        
     # 2 arguments: (HostName,Name) Or (Host , Name)
     elsif argc == 2   
       super(){
       }
        
     # 2 arguments: (HostName,Name) Or (Host , Name)
     elsif argc == 2   
       super(){
-        debug "Initilize with 2 args"
+        MSG::debug "Initilize with 2 args"
         type = args[0].type()
         if ( type.to_s == "String")
           host = Host.getByName(args[0])
         type = args[0].type()
         if ( type.to_s == "String")
           host = Host.getByName(args[0])
@@ -98,7 +103,7 @@ class MsgProcess < Thread
     # 3 arguments: (hostName,Name,args[]) or (Host,Name,args[])
     elsif argc == 3  
       super(){
     # 3 arguments: (hostName,Name,args[]) or (Host,Name,args[])
     elsif argc == 3  
       super(){
-       debug "Initilize with 3 args"
+       MSG::debug "Initilize with 3 args"
         type = args[0].type()
         if ( type.to_s == "String")
           host = Host.getByName(args[0])
         type = args[0].type()
         if ( type.to_s == "String")
           host = Host.getByName(args[0])
@@ -134,42 +139,37 @@ class MsgProcess < Thread
   def start()
     @schedBegin.acquire
     # execute the main code of the process     
   def start()
     @schedBegin.acquire
     # execute the main code of the process     
-    debug("Begin execution")
+    MSG::debug("Begin execution")
     main(@pargs)
     processExit(self) # Exit the Native Process
     @schedEnd.release
   end
     
     main(@pargs)
     processExit(self) # Exit the Native Process
     @schedEnd.release
   end
     
-  def processList()
+  def processList() (KILLME?)
     Thread.list.each {|t| p t}
   end
   
     Thread.list.each {|t| p t}
   end
   
-  #Get Own ID
+  #Get Own ID (KILLME?)
   def getID()
     return @id
   end
   
   def getID()
     return @id
   end
   
-  #Get a Process ID
+  #Get a Process ID (KILLME?)
   def processID(process)
     return process.id
   end
   
   def processID(process)
     return process.id
   end
   
-  #Get Own Name
+  #Get Own Name (KILLME?)
   def getName()
     return @name
   end
   
   def getName()
     return @name
   end
   
-  #Get a Process Name
-  def processName(process)
-    return process.name
-  end
-  
-  #Get Bind
+  #Get Bind (KILLME?)
   def getBind()
     return @bind
   end
   
   def getBind()
     return @bind
   end
   
-  #Get Binds
+  #Get Binds (KILLME?)
   def setBind(bind)
     @bind = bind
   end
   def setBind(bind)
     @bind = bind
   end
@@ -226,7 +226,7 @@ class ApplicationHandler
     @hostName = hostName
     @function = function
       
     @hostName = hostName
     @function = function
       
-    debug("onBeginProcess("+hostName+","+function+")")
+    MSG::debug("onBeginProcess("+hostName+","+function+")")
   end
 
   def onProperty(id,value)
   end
 
   def onProperty(id,value)
@@ -238,11 +238,14 @@ class ApplicationHandler
   end
 
   def onEndProcess()
   end
 
   def onEndProcess()
-    process = rubyNewInstance(@function) 
+    # must be in C, called from a callback to the FlexML parser 
+    # newInstance must take args and hostname as argument to initialize everything, *and* bind it to C element
+    # Allows to mark all attributes of process (but properties) to read-only
+    process = MSG::rubyNewInstance(@function) 
     process.pargs = @args
     process.name = @function
     process.pargs = @args
     process.name = @function
-    host = Host.getByName(@hostName)
-    processCreate(process,host)
+    host = MSG::Host.getByName(@hostName)
+    MSG::processCreate(process,host)
     process.properties = @properties
   end
 end
     process.properties = @properties
   end
 end
index 3dca774..c02fd55 100644 (file)
@@ -129,7 +129,7 @@ static void msg_debug(VALUE class,VALUE msg) {
   DEBUG1("%s",s);
 }
 
   DEBUG1("%s",s);
 }
 
-// Get Clock
+// Get Clock FIXME: return the double instead of displaying it
 static void msg_get_clock(VALUE class) {
 
   printf("Simulation time %f\n",MSG_get_clock());
 static void msg_get_clock(VALUE class) {
 
   printf("Simulation time %f\n",MSG_get_clock());
@@ -165,18 +165,18 @@ void Init_simgrid_ruby() {
   // Modules
   rb_msg = rb_define_module("MSG");
   //Associated Environment Methods!
   // Modules
   rb_msg = rb_define_module("MSG");
   //Associated Environment Methods!
-  rb_define_method(rb_msg,"init",(rb_meth)msg_init,1);
-  rb_define_method(rb_msg,"run",(rb_meth)msg_run,0);
-  rb_define_method(rb_msg,"createEnvironment",(rb_meth)msg_createEnvironment,1);
-  rb_define_method(rb_msg,"deployApplication",(rb_meth)msg_deployApplication,1);
-  rb_define_method(rb_msg,"info",(rb_meth)msg_info,1);
-  rb_define_method(rb_msg,"debug",(rb_meth)msg_debug,1);
-  rb_define_method(rb_msg,"getClock",(rb_meth)msg_get_clock,0);
-  rb_define_method(rb_msg,"rubyNewInstance",(rb_meth)msg_new_ruby_instance,1);
-  rb_define_method(rb_msg,"rubyNewInstanceArgs",(rb_meth)msg_new_ruby_instance_with_args,2);
+  rb_define_module_function(rb_msg,"init",(rb_meth)msg_init,1);
+  rb_define_module_function(rb_msg,"run",(rb_meth)msg_run,0);
+  rb_define_module_function(rb_msg,"createEnvironment",(rb_meth)msg_createEnvironment,1);
+  rb_define_module_function(rb_msg,"deployApplication",(rb_meth)msg_deployApplication,1);
+  rb_define_module_function(rb_msg,"info",(rb_meth)msg_info,1);
+  rb_define_module_function(rb_msg,"debug",(rb_meth)msg_debug,1);
+  rb_define_module_function(rb_msg,"getClock",(rb_meth)msg_get_clock,0);
+  rb_define_module_function(rb_msg,"rubyNewInstance",(rb_meth)msg_new_ruby_instance,1);
+  rb_define_module_function(rb_msg,"rubyNewInstanceArgs",(rb_meth)msg_new_ruby_instance_with_args,2);
 
   // Associated Process Methods
 
   // Associated Process Methods
-  rb_define_method(rb_msg,"processCreate",(rb_meth)rb_process_create,2);
+  rb_define_module_function(rb_msg,"processCreate",(rb_meth)rb_process_create,2);
   rb_define_method(rb_msg,"processSuspend",(rb_meth)rb_process_suspend,1);
   rb_define_method(rb_msg,"processResume",(rb_meth)rb_process_resume,1);
   rb_define_method(rb_msg,"processIsSuspend",(rb_meth)rb_process_isSuspended,1);
   rb_define_method(rb_msg,"processSuspend",(rb_meth)rb_process_suspend,1);
   rb_define_method(rb_msg,"processResume",(rb_meth)rb_process_resume,1);
   rb_define_method(rb_msg,"processIsSuspend",(rb_meth)rb_process_isSuspended,1);
@@ -188,7 +188,7 @@ void Init_simgrid_ruby() {
   rb_task = rb_define_class_under(rb_msg,"Task",rb_cObject);
   rb_host = rb_define_class_under(rb_msg,"Host",rb_cObject);
 
   rb_task = rb_define_class_under(rb_msg,"Task",rb_cObject);
   rb_host = rb_define_class_under(rb_msg,"Host",rb_cObject);
 
-  //Task Methods
+  //Task Methods FIXME: Convert to methods
   rb_define_module_function(rb_task,"new",(rb_meth)rb_task_new,3);
   rb_define_module_function(rb_task,"compSize",(rb_meth)rb_task_comp,1);
   rb_define_module_function(rb_task,"name",(rb_meth)rb_task_name,1);
   rb_define_module_function(rb_task,"new",(rb_meth)rb_task_new,3);
   rb_define_module_function(rb_task,"compSize",(rb_meth)rb_task_comp,1);
   rb_define_module_function(rb_task,"name",(rb_meth)rb_task_name,1);
index 912f301..24d1413 100644 (file)
@@ -986,6 +986,11 @@ Java_simgrid_msg_MsgNative_taskSend(JNIEnv * env, jclass cls,
 
   (*env)->ReleaseStringUTFChars(env, jalias, alias);
 
 
   (*env)->ReleaseStringUTFChars(env, jalias, alias);
 
+  /* FIXME throw the right exception corresponding to HostFailureException, TransferFailureException, TimeoutFailureException
+   * Note: these exceptions must be created beforehand
+   *       then, you want to create some functions like jxbt_throw_notbound()
+   *       then, you must declare in the MsgNative stuff that these native functions can throw these exceptions
+   */
   if (MSG_OK != rv)
     jxbt_throw_native(env, xbt_strdup("MSG_task_send_with_timeout() failed"));
 
   if (MSG_OK != rv)
     jxbt_throw_native(env, xbt_strdup("MSG_task_send_with_timeout() failed"));
 
index 307c731..335cd46 100644 (file)
@@ -11,6 +11,8 @@
 
 package simgrid.msg;
 
 
 package simgrid.msg;
 
+/* FIXME: Kill the process factory: that's just a storage of informations, AppHandler can do the work itself */
+
 import java.util.Vector;
 import java.util.Hashtable;
 
 import java.util.Vector;
 import java.util.Hashtable;
 
index 6ceeb7a..26fa5c0 100644 (file)
@@ -25,6 +25,7 @@ public final class Msg {
                }
        }
 
                }
        }
 
+       /* FIXME: kill these C crufts */
        /** Returns the last error code of the simulation */
        public final static native int getErrCode();
 
        /** Returns the last error code of the simulation */
        public final static native int getErrCode();
 
index 5354200..354afa2 100644 (file)
@@ -11,6 +11,8 @@
 
 package simgrid.msg;
 
 
 package simgrid.msg;
 
+/* FIXME: split into internal classes of Msg, Task, Host etc. */
+
 /**
  *  Contains all the native methods related to Process, Host and Task.
  */
 /**
  *  Contains all the native methods related to Process, Host and Task.
  */