From: mquinson Date: Tue, 2 Mar 2010 17:10:10 +0000 (+0000) Subject: Further cleanups of ruby, plus add FIXME in ruby and Java for the next cleanups X-Git-Tag: SVN~568 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/51f5efedb7e873fa0c82bdc8bb0aa78ae3e827c7?ds=sidebyside Further cleanups of ruby, plus add FIXME in ruby and Java for the next cleanups git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@7170 48e7efb5-ca39-0410-a469-dd3cf9ba447f --- diff --git a/src/bindings/ruby/MasterSlave.rb b/src/bindings/ruby/MasterSlave.rb index 19afa260da..e945b7adce 100644 --- a/src/bindings/ruby/MasterSlave.rb +++ b/src/bindings/ruby/MasterSlave.rb @@ -2,18 +2,19 @@ # make -C ../.. && valgrind ruby MasterSlave.rb --log=ruby.thres:debug 2>&1 | less require 'simgrid' + 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 - info("args["+String(i)+"]="+args[i]) + MSG::info("args["+String(i)+"]="+args[i]) 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 - 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 - 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.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 - # 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 - 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 - 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] 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") - info("Slave" + s_mailbox + "got finalize msg") + MSG::info("Slave" + s_mailbox + "got finalize msg") 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 - info("Slave " + s_mailbox + "I'm Done , See You !!") + MSG::info("Slave " + s_mailbox + "I'm Done , See You !!") end end @@ -82,6 +83,6 @@ else end # Thread.list.each {|t| p t} -MSG.run() -MSG.getClock() +MSG.run +MSG.getClock #FIXME: write "puts MSG.getClock" instead # exit() diff --git a/src/bindings/ruby/simgrid.rb b/src/bindings/ruby/simgrid.rb index 1eed8176b6..2cfeacf13c 100644 --- a/src/bindings/ruby/simgrid.rb +++ b/src/bindings/ruby/simgrid.rb @@ -1,8 +1,7 @@ require 'simgrid_ruby' -include MSG 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 @@ -15,6 +14,7 @@ class Semaphore end def acquire + MSG::debug("Acquire "+self.to_s) Thread.critical = true if (@counter -= 1) < 0 @waiting_list.push(Thread.current) @@ -26,11 +26,15 @@ class Semaphore end def release + MSG::debug("Release "+self.to_s) 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 @@ -44,7 +48,7 @@ end ######################################################################## # Class Process ######################################################################## -class MsgProcess < Thread +class MSG::Process < Thread @@nextProcessId = 0 # Attributes @@ -53,6 +57,7 @@ class MsgProcess < Thread # 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() @@ -67,13 +72,13 @@ class MsgProcess < Thread @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(){ - 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]) @@ -98,7 +103,7 @@ class MsgProcess < Thread # 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]) @@ -134,42 +139,37 @@ class MsgProcess < Thread 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 - def processList() + def processList() (KILLME?) Thread.list.each {|t| p t} end - #Get Own ID + #Get Own ID (KILLME?) def getID() return @id end - #Get a Process ID + #Get a Process ID (KILLME?) def processID(process) return process.id end - #Get Own Name + #Get Own Name (KILLME?) 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 - #Get Binds + #Get Binds (KILLME?) def setBind(bind) @bind = bind end @@ -226,7 +226,7 @@ class ApplicationHandler @hostName = hostName @function = function - debug("onBeginProcess("+hostName+","+function+")") + MSG::debug("onBeginProcess("+hostName+","+function+")") end def onProperty(id,value) @@ -238,11 +238,14 @@ class ApplicationHandler 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 - host = Host.getByName(@hostName) - processCreate(process,host) + host = MSG::Host.getByName(@hostName) + MSG::processCreate(process,host) process.properties = @properties end end diff --git a/src/bindings/ruby/simgrid_ruby.c b/src/bindings/ruby/simgrid_ruby.c index 3dca774c25..c02fd553aa 100644 --- a/src/bindings/ruby/simgrid_ruby.c +++ b/src/bindings/ruby/simgrid_ruby.c @@ -129,7 +129,7 @@ static void msg_debug(VALUE class,VALUE msg) { 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()); @@ -165,18 +165,18 @@ void Init_simgrid_ruby() { // 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 - 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); @@ -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); - //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); diff --git a/src/java/jmsg.c b/src/java/jmsg.c index 912f3017d2..24d141360a 100644 --- a/src/java/jmsg.c +++ b/src/java/jmsg.c @@ -986,6 +986,11 @@ Java_simgrid_msg_MsgNative_taskSend(JNIEnv * env, jclass cls, (*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")); diff --git a/src/java/simgrid/msg/ApplicationHandler.java b/src/java/simgrid/msg/ApplicationHandler.java index 307c731f0b..335cd46a34 100644 --- a/src/java/simgrid/msg/ApplicationHandler.java +++ b/src/java/simgrid/msg/ApplicationHandler.java @@ -11,6 +11,8 @@ 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; diff --git a/src/java/simgrid/msg/Msg.java b/src/java/simgrid/msg/Msg.java index 6ceeb7aecb..26fa5c03ec 100644 --- a/src/java/simgrid/msg/Msg.java +++ b/src/java/simgrid/msg/Msg.java @@ -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(); diff --git a/src/java/simgrid/msg/MsgNative.java b/src/java/simgrid/msg/MsgNative.java index 535420027a..354afa280e 100644 --- a/src/java/simgrid/msg/MsgNative.java +++ b/src/java/simgrid/msg/MsgNative.java @@ -11,6 +11,8 @@ package simgrid.msg; +/* FIXME: split into internal classes of Msg, Task, Host etc. */ + /** * Contains all the native methods related to Process, Host and Task. */