Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Ruby Msg Binding : new Methods and new Example
authorcoldpeace <coldpeace@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Fri, 19 Mar 2010 16:27:02 +0000 (16:27 +0000)
committercoldpeace <coldpeace@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Fri, 19 Mar 2010 16:27:02 +0000 (16:27 +0000)
git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@7278 48e7efb5-ca39-0410-a469-dd3cf9ba447f

src/bindings/ruby/PingPong.rb [new file with mode: 0644]
src/bindings/ruby/ping_pong_deployment.xml [new file with mode: 0644]
src/bindings/ruby/ping_pong_platform.xml [new file with mode: 0644]
src/bindings/ruby/rb_application_handler.c
src/bindings/ruby/rb_msg_host.c
src/bindings/ruby/rb_msg_process.c
src/bindings/ruby/rb_msg_task.c
src/bindings/ruby/simgrid.rb
src/bindings/ruby/simgrid_ruby.c

diff --git a/src/bindings/ruby/PingPong.rb b/src/bindings/ruby/PingPong.rb
new file mode 100644 (file)
index 0000000..2281b1d
--- /dev/null
@@ -0,0 +1,98 @@
+require 'simgrid'
+
+include MSG
+
+#####################
+#PingPongTask Class
+#####################
+
+class PingPongTask < MSG::Task
+  
+
+  def initialize(*args)
+    #Has No Role, Since Its The Task Class ( Created from C ) tht will be called , 
+    # and any instruction here will be ignored
+  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
+     
+#      FIXME Handel Exceptions 
+   end
+   
+   for i in 0..hostCount-1
+     time = MSG.getClock.to_s # to send as a data >> must be a string
+     MSG::info("sender time :"+time.to_s)
+     task = PingPongTask.new("PingTask",10000,2000)
+     task.setData(time)
+     p "mailboxe >>> "+ mailboxes[i]
+     task.send(mailboxes[i])
+   end
+   
+   MSG::info("GoodBye !!!")
+     
+   end
+   
+ end
+  
+####################
+# Receiver Class
+####################
+
+class Receiver < MSG::Process
+  
+  def main(args)
+    
+    MSG::info("Hello from Receiver")
+    time = MSG.getClock
+    MSG::info("Try to get a task")
+    host = MSG::Host.getHostProcess(self)
+    task = PingPongTask.receive(host.name)
+    p "task name recevied : "+ task.name
+    p "data in the task :" + task.data
+    timeGot = MSG.getClock
+    timeSent= task.data
+    MSG::info("Got at time: "+timeGot.to_s)
+    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("GoodBye !!!")
+  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
diff --git a/src/bindings/ruby/ping_pong_deployment.xml b/src/bindings/ruby/ping_pong_deployment.xml
new file mode 100644 (file)
index 0000000..b02edda
--- /dev/null
@@ -0,0 +1,8 @@
+<?xml version='1.0'?>
+<!DOCTYPE platform SYSTEM "simgrid.dtd">
+<platform version="2">
+  <process host="Inmos" function="Sender">
+      <argument value="Bellevue"/>
+  </process>
+<process host="Bellevue" function="Receiver"/>
+</platform>
diff --git a/src/bindings/ruby/ping_pong_platform.xml b/src/bindings/ruby/ping_pong_platform.xml
new file mode 100644 (file)
index 0000000..39eddb2
--- /dev/null
@@ -0,0 +1,90 @@
+<?xml version='1.0'?>
+<!DOCTYPE platform SYSTEM "simgrid.dtd">
+<platform version="2">
+  <!-- ljlkj -->
+  <host id="Inmos" power="98095000"/>
+  <host id="Bellevue" power="76296000"/>
+  <host id="Fafard" power="76296000"/>
+  <host id="Ginette" power="48492000"/>
+  <host id="Bourassa" power="48492000"/>
+  <link id="6" bandwidth="41279125" latency="5.9904e-05"/>
+  <link id="11" bandwidth="252750" latency="0.00570455"/>
+  <link id="3" bandwidth="34285625" latency="0.000514433"/>
+  <link id="7" bandwidth="11618875" latency="0.00018998"/>
+  <link id="9" bandwidth="7209750" latency="0.001461517"/>
+  <link id="12" bandwidth="1792625" latency="0.007877863"/>
+  <link id="2" bandwidth="118682500" latency="0.000136931"/>
+  <link id="8" bandwidth="8158000" latency="0.000270544"/>
+  <link id="1" bandwidth="34285625" latency="0.000514433"/>
+  <link id="4" bandwidth="10099625" latency="0.00047978"/>
+  <link id="0" bandwidth="41279125" latency="5.9904e-05"/>
+  <link id="10" bandwidth="4679750" latency="0.000848712"/>
+  <link id="5" bandwidth="27946250" latency="0.000278066"/>
+  <link id="loopback_FATPIPE" bandwidth="10000000" latency="0.1" sharing_policy="FATPIPE"/>
+  <link id="loopback" bandwidth="498000000" latency="0.000015"/>
+  <route src="Inmos" dst="Inmos"><link:ctn id="loopback"/></route>
+  <route src="Bellevue" dst="Bellevue"><link:ctn id="loopback"/></route>
+  <route src="Fafard" dst="Fafard"><link:ctn id="loopback"/></route>
+  <route src="Ginette" dst="Ginette"><link:ctn id="loopback"/></route>
+  <route src="Bourassa" dst="Bourassa"><link:ctn id="loopback"/></route>
+  <route src="Inmos" dst="Bellevue">
+    <link:ctn id="9"/>
+  </route>
+  <route src="Inmos" dst="Fafard">
+    <link:ctn id="4"/><link:ctn id="3"/><link:ctn id="2"/><link:ctn id="0"/><link:ctn id="1"/><link:ctn id="8"/>
+  </route>
+  <route src="Inmos" dst="Ginette">
+    <link:ctn id="4"/><link:ctn id="3"/><link:ctn id="5"/>
+  </route>
+  <route src="Inmos" dst="Bourassa">
+    <link:ctn id="4"/><link:ctn id="3"/><link:ctn id="2"/><link:ctn id="0"/><link:ctn id="1"/><link:ctn id="6"/><link:ctn id="7"/>
+  </route>
+  <route src="Bellevue" dst="Inmos">
+    <link:ctn id="9"/>
+  </route>
+  <route src="Bellevue" dst="Fafard">
+    <link:ctn id="9"/><link:ctn id="4"/><link:ctn id="3"/><link:ctn id="2"/><link:ctn id="0"/><link:ctn id="1"/><link:ctn id="8"/>
+  </route>
+  <route src="Bellevue" dst="Ginette">
+    <link:ctn id="9"/><link:ctn id="4"/><link:ctn id="3"/><link:ctn id="5"/>
+  </route>
+  <route src="Bellevue" dst="Bourassa">
+    <link:ctn id="9"/><link:ctn id="4"/><link:ctn id="3"/><link:ctn id="2"/><link:ctn id="0"/><link:ctn id="1"/><link:ctn id="6"/><link:ctn id="7"/>
+  </route>
+  <route src="Fafard" dst="Inmos">
+    <link:ctn id="8"/><link:ctn id="1"/><link:ctn id="0"/><link:ctn id="2"/><link:ctn id="3"/><link:ctn id="4"/>
+  </route>
+  <route src="Fafard" dst="Bellevue">
+    <link:ctn id="8"/><link:ctn id="1"/><link:ctn id="0"/><link:ctn id="2"/><link:ctn id="3"/><link:ctn id="4"/><link:ctn id="9"/>
+  </route>
+  <route src="Fafard" dst="Ginette">
+    <link:ctn id="8"/><link:ctn id="1"/><link:ctn id="0"/><link:ctn id="2"/><link:ctn id="5"/>
+  </route>
+  <route src="Fafard" dst="Bourassa">
+    <link:ctn id="8"/><link:ctn id="6"/><link:ctn id="7"/>
+  </route>
+  <route src="Ginette" dst="Inmos">
+    <link:ctn id="5"/><link:ctn id="3"/><link:ctn id="4"/>
+  </route>
+  <route src="Ginette" dst="Bellevue">
+    <link:ctn id="5"/><link:ctn id="3"/><link:ctn id="4"/><link:ctn id="9"/>
+  </route>
+  <route src="Ginette" dst="Fafard">
+    <link:ctn id="5"/><link:ctn id="2"/><link:ctn id="0"/><link:ctn id="1"/><link:ctn id="8"/>
+  </route>
+  <route src="Ginette" dst="Bourassa">
+    <link:ctn id="5"/><link:ctn id="2"/><link:ctn id="0"/><link:ctn id="1"/><link:ctn id="6"/><link:ctn id="7"/>
+  </route>
+  <route src="Bourassa" dst="Inmos">
+    <link:ctn id="7"/><link:ctn id="6"/><link:ctn id="1"/><link:ctn id="0"/><link:ctn id="2"/><link:ctn id="3"/><link:ctn id="4"/>
+  </route>
+  <route src="Bourassa" dst="Bellevue">
+    <link:ctn id="7"/><link:ctn id="6"/><link:ctn id="1"/><link:ctn id="0"/><link:ctn id="2"/><link:ctn id="3"/><link:ctn id="4"/><link:ctn id="9"/>
+  </route>
+  <route src="Bourassa" dst="Fafard">
+    <link:ctn id="7"/><link:ctn id="6"/><link:ctn id="8"/>
+  </route>
+  <route src="Bourassa" dst="Ginette">
+    <link:ctn id="7"/><link:ctn id="6"/><link:ctn id="1"/><link:ctn id="0"/><link:ctn id="2"/><link:ctn id="5"/>
+  </route>
+</platform>
index 63e465a..f145531 100644 (file)
@@ -10,7 +10,7 @@
 
 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(ruby);
 
-// Used to instanciate the Process
+// Used to instanciate the Process 
 static  VALUE args;
 static  VALUE prop;
 static  VALUE function_name;
index 4ac3a82..bab7b71 100644 (file)
@@ -70,3 +70,23 @@ VALUE rb_host_is_avail(VALUE class,VALUE host) {
 
   return Qfalse;
 }
+
+// getHost from process
+VALUE rb_host_process(VALUE class,VALUE ruby_process)
+{
+  
+ m_process_t process = rb_process_to_native(ruby_process);
+  m_host_t host;
+  
+
+  if (!process) {
+    rb_raise(rb_eRuntimeError,"Process Not Bound...while getting Host");
+    return Qnil; // NULL
+  }
+  
+  host = MSG_process_get_host(process);
+  
+  return Data_Wrap_Struct(class, 0, rb_host_free, host); 
+  
+  
+}
\ No newline at end of file
index dbf8c55..9b0f18c 100644 (file)
@@ -140,20 +140,24 @@ void rb_process_kill_down(VALUE class,VALUE ruby_process) {
 VALUE rb_process_getHost(VALUE class,VALUE ruby_process) {
   m_process_t process = rb_process_to_native(ruby_process);
   m_host_t host;
+  
 
   if (!process) {
     rb_raise(rb_eRuntimeError,"Process Not Bound...while getting Host");
     return Qnil; // NULL
   }
-
+  
   host = MSG_process_get_host(process);
-
+  
+  return Data_Wrap_Struct(class, 0, rb_host_free, host);
+  /*if(host->data) printf("Ok\n"); 
   if(!host->data) {
     rb_raise (rb_eRuntimeError,"MSG_process_get_host() failed");
     return Qnil;
   }
-
-  return Data_Wrap_Struct(class, 0, rb_host_free, host);
+  printf("Houuuuuuuuuuuuuuna3!!\n");
+  return Data_Wrap_Struct(class, 0, rb_host_free, host);*/
 }
 
 void rb_process_exit(VALUE class,VALUE ruby_process) {
index ea770cc..dadc6f5 100644 (file)
@@ -23,6 +23,26 @@ VALUE rb_task_new(VALUE class, VALUE name,VALUE comp_size,VALUE comm_size) {
 
 }
 
+// set Data : For the Moment , we will consider Data as asimple String ( char * )
+void rb_task_set_data(VALUE class,VALUE task,VALUE data)
+{
+ const char *str_data = RSTRING(data)->ptr;
+ m_task_t tk;
+ Data_Get_Struct(task, s_m_task_t, tk);
+ tk->data = (void*)str_data;
+}
+
+// get Data
+VALUE rb_task_get_data(VALUE class,VALUE task)
+{
+  m_task_t tk;
+  Data_Get_Struct(task, s_m_task_t, tk);
+  return rb_str_new2(tk->data);
+  
+}
+
+
 //Get Computation Size
 VALUE rb_task_comp(VALUE class,VALUE task) {
   double size;
@@ -144,3 +164,25 @@ VALUE rb_task_listen_host(VALUE class,VALUE task,VALUE alias,VALUE host) {
     return Qtrue;
   return Qfalse;
 }
+
+
+// Set Priority
+void rb_task_set_priority(VALUE class,VALUE task,VALUE priority)
+{
+  
+  m_task_t tk;
+  double prt = NUM2DBL(priority);
+  Data_Get_Struct(task,s_m_task_t,tk);
+  MSG_task_set_priority(tk,prt);
+  
+}
+
+// Cancel
+void rb_task_cancel(VALUE class,VALUE task)
+{
+ m_task_t tk;
+ Data_Get_Struct(task,s_m_task_t,tk);
+ MSG_task_cancel(tk);
+  
+}
+
index 30dc1df..c618f33 100644 (file)
@@ -72,7 +72,6 @@ class MSG::Process < Thread
     @name = args[0]
     @pargs = args[1]
     @properties = args[2]
-      
     start()
       }
     end
@@ -134,7 +133,15 @@ end
 class MSG::Task < MSG::RbTask
 
   def initialize(*args)
-     super()
+     super()    
+  end
+  
+  def setData(value)
+    super(self,value)
+  end
+  
+  def data()
+    super(self)
   end
   
   def name
@@ -168,6 +175,15 @@ class MSG::Task < MSG::RbTask
   def listenFromHost(t_alias,host)
     super(t_alias,host)
   end
+  
+  def setPriority(priority)
+    super(self,priority)
+  end
+  
+  def cancel()
+    super(self)
+  end
+  
 end  
 ####################################################
 # Host Extend from the native Class RbHost
@@ -200,6 +216,11 @@ class MSG::Host < MSG::RbHost
   def number
     super()
   end
+  
+  def getHostProcess(process)
+    super(process)
+  end
+    
 end
 #########################
 # Main chunck 
index c30de11..74fba1d 100644 (file)
@@ -65,7 +65,7 @@ static void msg_run(VALUE class) {
   DEBUG0
   ("MSG_main finished. Bail out before cleanup since there is a bug in this part.");
   /* Cleanup Ruby hosts */
-  DEBUG0("Clean Ruby World (TODO) ");
+  DEBUG0("Clean Ruby World  ");
   hosts = MSG_get_host_table();
   host_count = MSG_get_host_number();
   for (cpt=0;cpt<host_count;cpt++) {
@@ -132,7 +132,6 @@ static void msg_debug(VALUE class,VALUE msg) {
 
 // get Clock
 static VALUE msg_get_clock(VALUE class) {
-
   return rb_float_new(MSG_get_clock());
 
 }
@@ -171,6 +170,8 @@ void Init_simgrid_ruby() {
 
   //Task Methods 
   rb_define_module_function(rb_task,"new",(rb_meth)rb_task_new,3);
+  rb_define_module_function(rb_task,"setData",(rb_meth)rb_task_set_data,2);
+  rb_define_module_function(rb_task,"data",(rb_meth)rb_task_get_data,1);
   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,"execute",(rb_meth)rb_task_execute,1);
@@ -180,6 +181,8 @@ void Init_simgrid_ruby() {
   rb_define_module_function(rb_task,"source",(rb_meth)rb_task_source,1);
   rb_define_module_function(rb_task,"listen",(rb_meth)rb_task_listen,2);
   rb_define_module_function(rb_task,"listenFromHost",(rb_meth)rb_task_listen_host,3);
+  rb_define_module_function(rb_task,"setPriority",(rb_meth)rb_task_set_priority,2);
+  rb_define_module_function(rb_task,"cancel",(rb_meth)rb_task_cancel,1);
 
   //Host Methods
   rb_define_module_function(rb_host,"getByName",(rb_meth)rb_host_get_by_name,1);
@@ -189,4 +192,5 @@ void Init_simgrid_ruby() {
   rb_define_module_function(rb_host,"setData",(rb_meth)rb_host_set_data,2);
   rb_define_module_function(rb_host,"getData",(rb_meth)rb_host_get_data,1);
   rb_define_module_function(rb_host,"isAvail",(rb_meth)rb_host_is_avail,1);
+  rb_define_module_function(rb_host,"getHostProcess",(rb_meth)rb_host_process,1);
 }
\ No newline at end of file