--- /dev/null
+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
--- /dev/null
+<?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>
--- /dev/null
+<?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>
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;
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
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) {
}
+// 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;
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);
+
+}
+
@name = args[0]
@pargs = args[1]
@properties = args[2]
-
start()
}
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
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
def number
super()
end
+
+ def getHostProcess(process)
+ super(process)
+ end
+
end
#########################
# Main chunck
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++) {
// get Clock
static VALUE msg_get_clock(VALUE class) {
-
return rb_float_new(MSG_get_clock());
}
//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);
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);
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