### Declare the library content
###
-lib_LTLIBRARIES= libsimgrid.la libgras.la libsmpi.la
+if HAVE_RUBY
+ libruby=simgrid_ruby.la
+else
+ libruby=
+endif
+
+lib_LTLIBRARIES= libsimgrid.la libgras.la libsmpi.la $(libruby)
gras_sources=$(XBT_SRC) $(GRAS_COMMON_SRC) $(GRAS_RL_SRC) $(AMOK_SRC)
simgrid_sources=$(XBT_SRC) $(SURF_SRC) $(GTNETS_USED) \
libsmpi_la_SOURCES = $(SMPI_SRC)
libsmpi_la_LDFLAGS = $(VERSION_INFO) @SMPI_DEP@ @LD_DYNAMIC_FLAGS@ -lm
+if HAVE_RUBY
+simgrid_ruby_la_LIBADD = libsimgrid.la
+simgrid_ruby_la_SOURCES = bindings/ruby/simgrid_ruby.c
+simgrid_ruby_la_LDFLAGS = $(VERSION_INFO) @LD_DYNAMIC_FLAGS@ -lm -module
+endif
+
# Windows users (at least, MSVC ones) need a def file.
if IS_WINDOWS
libgras_la_LDFLAGS += -Wl,--output-def,libgras.def
RUBY_SRC= simix/smx_context_ruby.c \
bindings/ruby/rb_msg_process.c \
bindings/ruby/rb_msg_host.c \
- bindings/ruby/rb_msg_task.c
+ bindings/ruby/rb_msg_task.c \
+ bindings/ruby/rb_application_handler.c
if HAVE_RUBY
simgrid_sources += $(RUBY_SRC)
else
#
-# * $Id$
-# *
-# * Copyright 2010 Martin Quinson, Mehdi Fekari
-# * All right reserved.
-# *
-# * This program is free software; you can redistribute
-# * it and/or modify it under the terms of the license
-# *(GNU LGPL) which comes with this package.
-require 'ProcessFactory'
-$DEBUG = false
-class ApplicationHandler
-
- @processFactory
-# Initialize
- def initialize()
- #Nothing todo
- end
-
- # onStartDocument
- def onStartDocument()
-
- @processFactory = ProcessFactory.new
- if ($DEBUG)
- puts "onStartDocument"
- end
-
- end
-
-# onBeginProcess
- def onBeginProcess(hostName,function)
-
- @processFactory.setProcessIdentity(hostName,function)
-
- if ($DEBUG)
- puts "onBeginProcess"
- end
-
- end
-
-# onProperty
- def onProperty(id,value)
-
- @processFactory.setProperty(id,value)
-
- if ($DEBUG)
- puts "onProperty"
- end
-
- end
-
-# RegisterProcessArg
- def onProcessArg(arg)
-
- @processFactory.registerProcessArg(arg)
-
- if ($DEBUG)
- puts "onProcessArg"
- end
-
- end
-
-# OnEndProcess
- def onEndProcess()
-
- @processFactory.createProcess()
-
- if ($DEBUG)
- puts "onEndProcess"
- end
-
- end
+# Copyright 2010. The SimGrid Team. All right reserved.
+#
+# This program is free software; you can redistribute it and/or modify it
+# under the terms of the license (GNU LGPL) which comes with this package.
- # onEndDocument
- def onEndDocument()
-# Euh...Actually Nothin' to Do !!
-
- if($DEBUG)
- puts "onEndDocument"
- end
- end
-
- # End Class
- end
\ No newline at end of file
+require 'simgrid'
+include MSG
+$DEBUG = false
+++ /dev/null
-
-SHELL = /bin/sh
-
-#### Start of system configuration section. ####
-
-srcdir = .
-topdir = /usr/lib/ruby/1.8/i486-linux
-hdrdir = $(topdir)
-VPATH = $(srcdir):$(topdir):$(hdrdir)
-exec_prefix = $(prefix)
-prefix = $(DESTDIR)/usr
-sharedstatedir = $(prefix)/com
-mandir = $(prefix)/share/man
-psdir = $(docdir)
-oldincludedir = $(DESTDIR)/usr/include
-localedir = $(datarootdir)/locale
-bindir = $(exec_prefix)/bin
-libexecdir = $(prefix)/lib/ruby1.8
-sitedir = $(DESTDIR)/usr/local/lib/site_ruby
-htmldir = $(docdir)
-vendorarchdir = $(vendorlibdir)/$(sitearch)
-includedir = $(prefix)/include
-infodir = $(prefix)/share/info
-vendorlibdir = $(vendordir)/$(ruby_version)
-sysconfdir = $(DESTDIR)/etc
-libdir = $(exec_prefix)/lib
-sbindir = $(exec_prefix)/sbin
-rubylibdir = $(libdir)/ruby/$(ruby_version)
-docdir = $(datarootdir)/doc/$(PACKAGE)
-dvidir = $(docdir)
-vendordir = $(libdir)/ruby/vendor_ruby
-datarootdir = $(prefix)/share
-pdfdir = $(docdir)
-archdir = $(rubylibdir)/$(arch)
-sitearchdir = $(sitelibdir)/$(sitearch)
-datadir = $(datarootdir)
-localstatedir = $(DESTDIR)/var
-sitelibdir = $(sitedir)/$(ruby_version)
-
-CC = gcc
-LIBRUBY = $(LIBRUBY_SO)
-LIBRUBY_A = lib$(RUBY_SO_NAME)-static.a
-LIBRUBYARG_SHARED = -l$(RUBY_SO_NAME) -I . ../../.libs/libsimgrid.a -ldl -llua5.1
-LIBRUBYARG_STATIC = -l$(RUBY_SO_NAME)-static
-
-RUBY_EXTCONF_H =
-CFLAGS = -fPIC -fno-strict-aliasing -g -g -O2 -fPIC $(cflags)
-INCFLAGS = -I. -I$(topdir) -I$(hdrdir) -I$(srcdir) -I../../../include -I../../include -I../..
-DEFS = -D_FILE_OFFSET_BITS=64
-CPPFLAGS = $(DEFS) $(cppflags)
-CXXFLAGS = $(CFLAGS)
-ldflags = -L. -Wl,-Bsymbolic-functions -rdynamic -Wl,-export-dynamic
-dldflags =
-archflag =
-DLDFLAGS = $(ldflags) $(dldflags) $(archflag)
-LDSHARED = $(CC) -shared
-AR = ar
-EXEEXT =
-
-RUBY_INSTALL_NAME = ruby1.8
-RUBY_SO_NAME = ruby1.8
-arch = i486-linux
-sitearch = i486-linux
-ruby_version = 1.8
-ruby = /usr/bin/ruby1.8
-RUBY = $(ruby)
-RM = rm -f
-MAKEDIRS = mkdir -p
-INSTALL = /usr/bin/install -c
-INSTALL_PROG = $(INSTALL) -m 0755
-INSTALL_DATA = $(INSTALL) -m 644
-COPY = cp
-
-#### End of system configuration section. ####
-
-preload =
-
-libpath = . $(libdir)
-LIBPATH = -L. -L$(libdir)
-DEFFILE =
-
-CLEANFILES = mkmf.log
-DISTCLEANFILES =
-
-extout =
-extout_prefix =
-target_prefix =
-LOCAL_LIBS =
-LIBS = $(LIBRUBYARG_SHARED) -lpthread -lrt -ldl -lcrypt -lm -lc
-SRCS = rb_application_handler.c rb_msg_task.c rb_msg_process.c rb_msg_host.c rb_msg.c
-OBJS = rb_application_handler.o rb_msg_task.o rb_msg_process.o rb_msg_host.o rb_msg.o
-TARGET = msg
-DLLIB = $(TARGET).so
-EXTSTATIC =
-STATIC_LIB =
-
-BINDIR = $(bindir)
-RUBYCOMMONDIR = $(sitedir)$(target_prefix)
-RUBYLIBDIR = $(sitelibdir)$(target_prefix)
-RUBYARCHDIR = $(sitearchdir)$(target_prefix)
-
-TARGET_SO = $(DLLIB)
-CLEANLIBS = $(TARGET).so $(TARGET).il? $(TARGET).tds $(TARGET).map
-CLEANOBJS = *.o *.a *.s[ol] *.pdb *.exp *.bak
-
-all: $(DLLIB)
-static: $(STATIC_LIB)
-
-clean:
- @-$(RM) $(CLEANLIBS) $(CLEANOBJS) $(CLEANFILES)
-
-distclean: clean
- @-$(RM) Makefile $(RUBY_EXTCONF_H) conftest.* mkmf.log
- @-$(RM) core ruby$(EXEEXT) *~ $(DISTCLEANFILES)
-
-realclean: distclean
-install: install-so install-rb
-
-install-so: $(RUBYARCHDIR)
-install-so: $(RUBYARCHDIR)/$(DLLIB)
-$(RUBYARCHDIR)/$(DLLIB): $(DLLIB)
- $(INSTALL_PROG) $(DLLIB) $(RUBYARCHDIR)
-install-rb: pre-install-rb install-rb-default
-install-rb-default: pre-install-rb-default
-pre-install-rb: Makefile
-pre-install-rb-default: Makefile
-$(RUBYARCHDIR):
- $(MAKEDIRS) $@
-
-site-install: site-install-so site-install-rb
-site-install-so: install-so
-site-install-rb: install-rb
-
-.SUFFIXES: .c .m .cc .cxx .cpp .C .o
-
-.cc.o:
- $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) -c $<
-
-.cxx.o:
- $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) -c $<
-
-.cpp.o:
- $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) -c $<
-
-.C.o:
- $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) -c $<
-
-.c.o:
- $(CC) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) -c $<
-
-$(DLLIB): $(OBJS) Makefile
- @-$(RM) $@
- $(LDSHARED) -o $@ $(OBJS) $(LIBPATH) $(DLDFLAGS) $(LOCAL_LIBS) $(LIBS)
-
-
-
-$(OBJS): ruby.h defines.h
+++ /dev/null
-require 'msg'
-require 'RubyProcess'
-
-include MSG
-
-class Master < RbProcess
- def initialize2()
- super()
- end
-
-
- #for Testing
- def msg_main2(args)
- info("Hello From Master")
- end
-
-
- # msg_main : that function that will be executed when Running Simulation
- def msg_main(args) # args is an array Containin' arguments for function master
- info("Hello From Master")
- size = args.size
- info ("Number of Args for Master = " + size.to_s)
- for i in 0..size-1
- info(args[i])
- end
-
- raise "Master needs 3 arguments" if size < 3
- numberOfTask = Integer(args[0])
- taskComputeSize = Float(args[1])
- taskCommunicationSize = Float(args[2])
- slaveCount = Integer(args[3])
-
- #Creating & Sending Task
- for i in 0..numberOfTask-1
-
-
- task = RbTask.new("Task_"+ i.to_s, taskComputeSize , taskCommunicationSize );
- s_alias = "slave>>" + (i%slaveCount).to_s
- info("Master Sending "+ RbTask.name(task) + " to " + s_alias + " with Comput Size " + RbTask.compSize(task).to_s)
- RbTask.send(task,s_alias)
- info("Master Done Sending " +RbTask.name(task) + " to " + s_alias)
-# sameTask = RbTask.receive(s_alias)
-# puts "Master Receiving its Own Task"
- end
-
- # Sending Finalize Tasks
- info ("Master: All tasks have been dispatched. Let's tell everybody the computation is over.")
- for i in 0..slaveCount-1
- s_alias = "slave " + i.to_s
- info ("Master Sending Finalize to " + s_alias)
- RbTask.send(RbTask.new("finalize",0,0),s_alias)
- end
- info("Master : Everything's Done")
- end
-
-end
\ No newline at end of file
-require 'msg'
-require 'RubyProcess'
-require 'Master'
-require 'Slave'
+require 'simgrid'
+include MSG
-# include MSG
+#################################################
+# Class Master
+#################################################
-raise "Bad Number Of Arguments" if ARGV.length != 2
+class Master < RbProcess
+ def initialize2()
+ super()
+ end
+
+
+ # msg_main : that function that will be executed when Running Simulation
+ def msg_main(args) # args is an array containing arguments for function master
+ info("Hello From Master")
+ size = args.size
+ info ("Number of Args for Master = " + size.to_s)
+ for i in 0..size-1
+ info("args["+String(i)+"]="+args[i])
+ end
+
+ raise "Master needs 3 arguments" if size < 3
+ numberOfTask = Integer(args[0])
+ taskComputeSize = Float(args[1])
+ taskCommunicationSize = Float(args[2])
+ slaveCount = Integer(args[3])
+
+ #Creating & Sending Task
+ for i in 0..numberOfTask-1
+
+
+ task = RbTask.new("Task_"+ i.to_s, taskComputeSize , taskCommunicationSize );
+ s_alias = "slave>>" + (i%slaveCount).to_s
+ info("Master Sending "+ RbTask.name(task) + " to " + s_alias + " with Comput Size " + RbTask.compSize(task).to_s)
+ RbTask.send(task,s_alias)
+ info("Master Done Sending " +RbTask.name(task) + " to " + s_alias)
+# sameTask = RbTask.receive(s_alias)
+# puts "Master Receiving its Own Task"
+ end
+
+ # Sending Finalize Tasks
+ info ("Master: All tasks have been dispatched. Let's tell everybody the computation is over.")
+ for i in 0..slaveCount-1
+ s_alias = "slave " + i.to_s
+ info ("Master Sending Finalize to " + s_alias)
+ RbTask.send(RbTask.new("finalize",0,0),s_alias)
+ end
+ info("Master : Everything's Done")
+ end
+end
+
+#################################################
+# Class Slave
+#################################################
+class Slave < RbProcess
+
+ def initialize()
+ super()
+ end
+
+ # msg_main : that function that will be executed when Running Simulation
+ def msg_main(args)
+ info("Hello From Slave")
+ s_mailbox = "slave>>" + args[0]
+
+ while true
+
+ info("Ready to Receive Task")
+ task = RbTask.receive(s_mailbox)
+ task_name = RbTask.name(task)
+ info ("Task Received : " + task.name)
+ if (task_name == "finalize")
+ info("Slave" + s_mailbox + "got finalize msg")
+ break
+ end
+ info("Slave " + s_mailbox + " ...Processing" + RbTask.name(task))
+ RbTask.execute(task)
+ end
+ info("Slave " + s_mailbox + "I'm Done , See You !!")
+ end
+
+ end
+
+
+#################################################
+# main chunck
+#################################################
+
+if (ARGV.length == 2)
+ MSG.createEnvironment(ARGV[0])
+ MSG.deployApplication(ARGV[1])
+else
+ MSG.createEnvironment("platform.xml")
+ MSG.deployApplication("deploy.xml")
+ Thread.list.each {|t| p t}
+end
-MSG.init(ARGV)
-# Thread.list.each {|t| p t}
-raise "Bad Number Of Arguments" if (ARGV.length < 2)
-MSG.createEnvironment(ARGV[0])
-# Thread.list.each {|t| p t}
-MSG.deployApplication(ARGV[1])
# Thread.list.each {|t| p t}
MSG.run()
-# Thread.list.each {|t| p t}
MSG.getClock()
# exit()
+++ /dev/null
-require 'msg'
-require 'RubyProcess'
-
-include MSG
-
-class Master < RbProcess
- def initialize()
- super()
- end
-
- def msg_main2(args)
- info("Hello From Master")
- end
-
- # msg_main : that function that will be executed when Running Simulation
- def msg_main(args) # args is an array Containin' arguments for function master
- info("Hello From Master")
- size = args.size
- puts "Number of Args for Master = " + size.to_s
- for i in 0..size-1
- puts args[i]
- end
-
- raise "Master needs 3 arguments" if size < 3
- channel = 0
- numberOfTask = Integer(args[0])
- taskComputeSize = Float(args[1])
- taskCommunicationSize = Float(args[2])
- slaveCount = args.size - 3
-
- slaves = Array.new
- todo = Array.new
-
-
- #Creating & Sending Task
- for i in 0..numberOfTask-1
-
- todo[i] = RbTask.new("Task_"+ i.to_s, taskComputeSize , taskCommunicationSize );
-
- end
-
- for i in 3..args.size-1
-
- slaves[i-3] = RbHost.getByName(args[i])
- end
-
-
- for i in 0..numberOfTask-1
- p "Sending ( Put ) Task .." + i.to_s+ " to Slave " + RbHost.name(slaves[i%slaveCount])
- RbTask.put(todo[i],slaves[i%slaveCount])
- end
-
- # Sending Finalize Tasks
- p "Sending Finalize Task Later !!"
- puts "Master : Everything's Done"
- end
-
-end
\ No newline at end of file
+++ /dev/null
-#
-# * $Id$
-# *
-# * Copyright 2010 Martin Quinson, Mehdi Fekari
-# * All right reserved.
-# *
-# * This program is free software; you can redistribute
-# * it and/or modify it under the terms of the license
-# *(GNU LGPL) which comes with this package.
-require 'RubyProcess'
-require 'RubyHost'
-class ProcessFactory
-
-# Attributes
- attr_accessor :args, :proprieties, :hostName, :function
-# Initlialize
- def initialize()
-
- @args = Array.new
- @proprieties = Hash.new
- @hostName = nil
- @function = nil
-
- end
-
-# setProcessIdentity
- def setProcessIdentity(hostName,function)
- @hostName = hostName
- @function = function
-
- if !args.empty?
- args.clear
- end
-
- if !proprieties.empty?
- proprieties.clear
- end
-
- end
-
-# RegisterProcess
- def registerProcessArg(arg)
-
- @args.push(arg)
-
- end
-
-# CreateProcess
- def createProcess()
-
- process = rubyNewInstance(@function) #process = rubyNewInstanceArgs(@function,@args) #
- size = @args.size
- for i in 0..size-1
- process.pargs.push(@args[i])
- end
- process.name = @function
- process.id = process.nextId() # This increment Automaticly The Static ProcessNextId for The Class RbProces
- host = RbHost.getByName(@hostName)
- processCreate(process,host)
- process.proprieties = @proprieties
- @proprieties = Hash.new
-
- end
-
-# SetProperty
- def setProperty(id,value)
- @proprieties[id] = value
- end
-
-# End Class
- end
\ No newline at end of file
+++ /dev/null
-#
-# * $Id$
-# *
-# * Copyright 2010 Martin Quinson, Mehdi Fekari
-# * All right reserved.
-# *
-# * This program is free software; you can redistribute
-# * it and/or modify it under the terms of the license
-# *(GNU LGPL) which comes with this package.
-
-require 'msg'
-include MSG
-
-class RbHost < Host
-# Attributes
- attr_accessor :bind, :data
-
-# Initialize
- def initialize()
- @bind = 0
- @data = nil
- end
-
-end
\ No newline at end of file
+++ /dev/null
-#
-# * $Id$
-# *
-# * Copyright 2010 Martin Quinson, Mehdi Fekari
-# * All right reserved.
-# *
-# * This program is free software; you can redistribute
-# * it and/or modify it under the terms of the license
-# *(GNU LGPL) which comes with this package.
-
-require 'msg'
-require 'Semaphore'
-include MSG
-$DEBUG = true # This is a Global Variable Useful for Debugging
-
-class RbProcess < Thread
- @@nextProcessId = 0
-# Attributes
- attr_accessor :bind, :id, :proprieties, :name,
- :pargs, :schedBegin, :schedEnd, :mutex, :cv
-
-# Initialize : USED in ApplicationHandler to Initialize it
- def initialize(*args)
-
- argc = args.size
-# Default initializer
- if argc == 0 #>>> new()
- super() {
- @id = 0
- @bind = 0
- @name = ""
- @pargs = Array.new()
- init_var()
- start()
- if $DEBUG
- puts "Init Default Initialzer...Nothing to do...Bye"
- end
- }
- end
-
- # Init with 2 arguments **********************>>>(HostName,Name) Or (Host , Name)
- if argc == 2
- super(){
- type = args[0].type()
- if ( type.to_s == "String")
- host = Host.getByName(args[0])
- end
- if ( type.to_s == "MSG::Host")
- host = args[0]
- end
- if $DEBUG
- puts host
- end
- raise "Process Name Cannot Be Null" if args[1].empty?
- @name = args[1] # First Arg
- if $DEBUG
- puts @name
- end
- @pargs = Array.new() # No Args[] Passed in Arguments
- @@nextProcessId += 1
- @id = @@nextProcessId
- init_var()
- start()
- createProcess(self,host)
- if $DEBUG
- puts "Initilize with 2 args"
- end
- }
-
- end
-
- # Init with 3 arguments **********************(hostName,Name,args[]) or # (Host,Name,args[])
-
- if argc == 3
- super(){
- type = args[0].type()
- if( type.to_s == "String")
- host =Host.getByName(args[0])
- end
- if ( type.to_s == "MSG::Host" )
- host = args[0]
- end
- if $DEBUG
- puts host
- end
-
- raise "Process Name Cannot Be Null" if args[0].empty?
- @name = args[1]
- type = args[2].type()
- raise "Third Argument Should be an Array" if type != "Array"
- @pargs = args[3]
- @@nextProcessId +=1
- @id = @@nextProcessId
- init_var()
- createProcess(self,host)
-
- if $DEBUG
- puts "Initilize with 3 args"
- end
-
-# sleep #keep the thread running
- }
- end
- end
-
- # Init_var Called By Initialize
- def init_var()
- @proprieties = Hash.new()
- @mutex = Mutex.new
- @cv = ConditionVariable.new
- # Process Synchronization Tools
- @schedBegin = Semaphore.new(0)
- @schedEnd = Semaphore.new(0)
- end
-
- #main
- def msg_main(args)
- # To Be Implemented within The Process...
- # The Main Code of The Process to be Executed ...
- end
-
- # Start : To keep the Process Alive and waitin' via semaphore
- def start()
- @schedBegin.acquire(@mutex,@cv)
- #execute The Main Code of The Process ( Example Master ; Slave ...)
- msg_main(@pargs)
- processExit(self) #Exite the Native Process
- @schedEnd.release(@mutex,@cv)
- end
-
-# NetxId
- def nextId ()
- @@nextProcessId +=1
- return @@nextProcessId
- end
-
- if $DEBUG
- #Process List
- def processList()
- Thread.list.each {|t| p t}
- end
- end
-
- #Get Own ID
- def getID()
- return @id
- end
-
- # set Id
- def setID(id)
- @id = id
- end
-
- #Get a Process ID
- def processID(process)
- return process.id
- end
-
- #Get Own Name
- def getName()
- return @name
- end
-
- #Get a Process Name
- def processName(process)
- return process.name
- end
-
- #Get Bind
- def getBind()
- return @bind
- end
-
- #Get Binds
- def setBind(bind)
- @bind = bind
- end
-
- def unschedule()
-
- @schedEnd.release(@mutex,@cv)
-# info("@schedEnd.release(@mutex,@cv)")
- @schedBegin.acquire(@mutex,@cv)
-# info("@schedBegin.acquire(@mutex,@cv)")
-
- end
-
- def schedule()
- @schedBegin.release(@mutex,@cv)
- @schedEnd.acquire(@mutex,@cv)
- end
-
- #C Simualateur Process Equivalent Management
- # After Binding Ruby Process to C Process
-
-# pause
- def pause()
- processSuspend(self)
- end
-
-# restart
- def restart()
- processResume(self)
- end
-
-# isSuspended
- def isSuspended()
- processIsSuspended(self)
- end
-
-# getHost
- def getHost()
- processGetHost(self)
- end
-
-# The Rest of Methods !!! To be Continued ...
-end
\ No newline at end of file
+++ /dev/null
-class Sem
-
-
- attr_accessor :permits, :mutex, :cv
-
- Thread.abort_on_exception = true
-
-
-
-# Initialize
- def initialize ( permits )
-
- @permits = permits
- @mutex = Mutex.new
- @cv = ConditionVariable.new
-
- end
-
-
-
-# Aquire
- def acquire()
-
- if(!Thread.current.alive?) #Thread.interrupted in Java
- raise "Exception : Thread Interrupted"
- end
-
- mutex.synchronize {
-
- while @permits <= 0
-
- @cv.wait(mutex) #or Thread.stop ???!!
-
- end
-
- @permits -=1
- }
-
- end
-
-
- def release()
-
- mutex.synchronize {
-
- @permits +=1
- @cv.signal #Notify ??!!
-
- }
-
-
-end
\ No newline at end of file
+++ /dev/null
-#
-# * $Id$
-# *
-# * Copyright 2010 Martin Quinson, Mehdi Fekari
-# * All right reserved.
-# *
-# * This program is free software; you can redistribute
-# * it and/or modify it under the terms of the license
-# *(GNU LGPL) which comes with this package.
-require 'msg'
-include MSG
-
-class RbTask < Task
-
-
-# Attributes
- attr_accessor :bind
-
-
-# Initialize
- def initialize(name,comp_size,comm_size)
-# @bind = 10
- super(name,comp_size,comm_size)
- end
-
-
-end
\ No newline at end of file
+++ /dev/null
-#
-# * $Id$
-# *
-# * Copyright 2010 Martin Quinson, Mehdi Fekari
-# * All right reserved.
-# *
-# * This program is free software; you can redistribute
-# * it and/or modify it under the terms of the license
-# *(GNU LGPL) which comes with this package.
-require 'msg'
-require 'thread'
-class Semaphore
-
- Thread.abort_on_exception = true
- attr_accessor :permits
-
-
- def initialize ( permits )
-
- @permits = permits
-
- end
-
-
- def acquire(mutex,cv)
-
- raise "Interrupted Thread " if (!Thread.current.alive?)
- mutex.synchronize {
- while @permits <= 0
-
- cv.wait(mutex)
-
- end
-
- @permits = @permits - 1
- cv.signal
-
- }
-
- end
-
- def release(mutex,cv)
- mutex.synchronize{
-
- @permits += 1
- cv.signal
-
- }
- end
-
-end
\ No newline at end of file
+++ /dev/null
-require 'msg'
-require 'RubyProcess'
-require 'RubyTask'
-include MSG
-
-class Slave < RbProcess
-
- def initialize()
- super()
- end
-
- #for Testing
- def msg_main2(args)
- info("Hello From Slave")
- end
-
-
-
-
-
- # msg_main : that function that will be executed when Running Simulation
- def msg_main(args)
- info("Hello From Slave")
- s_mailbox = "slave>>" + args[0]
-
- while true
-
- info("Ready to Receive Task")
- task = RbTask.receive(s_mailbox)
- task_name = RbTask.name(task)
- info ("Task Received : " + task_name)
- if (task_name == "finalize")
- info("Slave" + s_mailbox + "got finalize msg")
- break
- end
- info("Slave " + s_mailbox + " ...Processing" + RbTask.name(task))
- RbTask.execute(task)
- end
- info("Slave " + s_mailbox + "I'm Done , See You !!")
- end
-
- end
+++ /dev/null
-require 'msg'
-require 'RubyProcess'
-require 'RubyTask'
-include MSG
-
-class Slave < RbProcess
-
- def initialize()
- super()
- end
-
- def msg_main(args)
- info("Hello From Slave")
- end
-
- # msg_main : that function that will be executed when Running Simulation
- def msg_main(args)
- info("Hello From Slave")
- while true
-
- task = RbTask.get(); #by default Port set to 0
- task_name = RbTask.name(task)
- puts "my name ........" + task_name
- if ( task_name == "finalize" )
- puts "Received finalize msg"
- break
- end
- puts "Processing..." + RbTask.name(task)
- RbTask.execute(task)
- end
- puts "I'm Done ... See You !!"
- break
- end
-
-
- end
-
\ No newline at end of file
+++ /dev/null
-require 'msg'
-include MSG
-require 'RubyProcess'
-require 'Master'
-require 'RubyHost'
-
-
-array = Array.new()
-
-# puts array.empty?
-array << "Peace!!" << "Hey" << "Euh..."<< "Hey2" << "Euh...2"
-
-
-# process = rubyNewInstanceArgs("Master",array)
-
-# array.clear
-# puts array.empty?
-
-mehdi = "Hey...this is my name"
-
-hash = Hash.new
-
-var = "name"
-
-hash[var] = mehdi
-
-# puts hash["name"]
-
-array.push(mehdi)
-
-# info("Hey...")
-# puts array[0]
-
-array2 = array
-
-# puts array2[0]
-
-size = array2.size
-
-task = Task.new('marine',12,23)
-puts "Created task :"+task.to_s+" ; name: "+Task.name(task)
-
-# Task.send(Task.new("finalize",0,0),"alias")
-#task2 =RbTask.new('task2')
-# task = RbTask.new()
-# host = Host.new("Brad")
-
-#host2 = Host.new()
-# task_2 = Task.new('task2',12,23)
-# name1 = task_2.name()
-# name2 = Task.name(task)
-# size = Task.compSize(task)
-name = Task.name(task)
-# task.bind
-number = 56
-process = rubyNewInstance("RbProcess");#RbProcess.new()
-# process.run()
-p process.class
-# puts "Created process :"+process.to_s+" ; name: "+RbProcess.name(task)
-# name = process.name
-puts name
-argue = ARGV[0]
-puts argue
-# puts process.alive?
-# Thread.stop
-# process2 = RbProcess.new()
-# process2.name = "Hope"
-# reader = RubyXML.new();
-# reader.parseApplication("application.xml")
-# reader.printAll()
-# name2 = Task.test()
-# puts name
-# process2 = RbProcess.new()
-# puts (name)
-# init(array)
-# createEnvironment(name);
-# Task.goodbye
\ No newline at end of file
<argument value="20"/> <!-- Number of tasks -->
<argument value="50000000"/> <!-- Computation size of tasks -->
<argument value="1000000"/> <!-- Communication size of tasks -->
- <argument value="5"/> <!-- Amount of slaves -->
+ <argument value="4"/> <!-- Amount of slaves -->
</process>
- <!-- The slave process (with no argument) -->
- <process host="Tremblay" function="Slave">
+ <!-- The slave process (argument: slave rank) -->
+ <process host="Bourassa" function="Slave">
<argument value="0"/>
</process>
<process host="Jupiter" function="Slave">
<process host="Ginette" function="Slave">
<argument value="3"/>
</process>
- <process host="Bourassa" function="Slave">
- <argument value="4"/>
- </process>
</platform>
+++ /dev/null
-require 'mkmf'
-extension_name ='msg'
-dir_config(extension_name)
-create_makefile(extension_name)
--- /dev/null
+../../.libs/libsimgrid.so
\ No newline at end of file
/*
- * $Id$
+ * Copyright 2010. The SimGrid Team. All right reserved.
*
- * Copyright 2010 Martin Quinson, Mehdi Fekari
- * All right reserved.
- *
- * This program is free software; you can redistribute
- * it and/or modify it under the terms of the license
- *(GNU LGPL) which comes with this package.
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the license (GNU LGPL) which comes with this package.
*/
-#include "rb_application_handler.h"
+#include "bindings/ruby_bindings.h"
#include "surf/surfxml_parse.h"
-#include <stdio.h>
+
+static VALUE application_handler_class; // The Current Instance of ApplicationHandler Class ,is it the same as Current Thread ??!!
+
// #define MY_DEBUG
-static void r_init()
-{
-
+static void r_init() {
ruby_init();
ruby_init_loadpath();
rb_require("ApplicationHandler.rb");
}
-static void application_handler_on_start_document(void)
-{
+void rb_application_handler_on_start_document(void) {
r_init();
- //current One
- current = rb_funcall3(rb_const_get(rb_cObject, rb_intern("ApplicationHandler")), rb_intern("new"), 0, 0);
- rb_funcall(current,rb_intern("onStartDocument"),0);
+ application_handler_class = rb_funcall3(rb_const_get(rb_cObject, rb_intern("ApplicationHandler")), rb_intern("new"), 0, 0);
+ rb_funcall(application_handler_class,rb_intern("onStartDocument"),0);
#ifdef MY_DEBUG
printf ("application_handler_on_start_document ...Done\n" );
#endif
}
-static void application_handler_on_end_document(void)
-{
- //r_init();
- rb_funcall(current,rb_intern("onEndDocument"),0);
-
+void rb_application_handler_on_end_document(void) {
+ rb_funcall(application_handler_class,rb_intern("onEndDocument"),0);
}
-static void application_handler_on_begin_process(void)
-{
- //r_init();
+void rb_application_handler_on_begin_process(void) {
VALUE hostName = rb_str_new2(A_surfxml_process_host);
VALUE function = rb_str_new2(A_surfxml_process_function);
#ifdef MY_DEBUG
printf ("On_Begin_Process: %s : %s \n",RSTRING(hostName)->ptr,RSTRING(function)->ptr);
#endif
- rb_funcall(current,rb_intern("onBeginProcess"),2,hostName,function);
+ rb_funcall(application_handler_class,rb_intern("onBeginProcess"),2,hostName,function);
}
-static void application_handler_on_process_arg(void)
-{
- //r_init();
+void rb_application_handler_on_process_arg(void) {
VALUE arg = rb_str_new2(A_surfxml_argument_value);
#ifdef MY_DEBUG
printf ("On_Process_Args >> Sufxml argument value : %s\n",RSTRING(arg)->ptr);
#endif
- rb_funcall(current,rb_intern("onProcessArg"),1,arg);
+ rb_funcall(application_handler_class,rb_intern("onProcessArg"),1,arg);
}
-static void application_handler_on_property(void)
-{
-
- //r_init()
+void rb_application_handler_on_property(void) {
VALUE id = rb_str_new2(A_surfxml_prop_id);
VALUE val = rb_str_new2(A_surfxml_prop_value);
- rb_funcall(current,rb_intern("onProperty"),2,id,val);
-
+ rb_funcall(application_handler_class,rb_intern("onProperty"),2,id,val);
}
-static void application_handler_on_end_process(void)
-{
-
- //r_init()
- rb_funcall(current,rb_intern("onEndProcess"),0);
-
+void rb_application_handler_on_end_process(void) {
+ rb_funcall(application_handler_class,rb_intern("onEndProcess"),0);
}
+++ /dev/null
-#ifndef _RB_APPLICATION_HANDLER_H_
-#define _RB_APPLICATION_HANDLER_H_
-
-#include <ruby.h>
-#include "msg/msg.h"
-
-
-
-VALUE current; // The Current Instance of ApplicationHandler Class ,is it the same as Current Thread ??!!
-
-static void r_init(void);
-
-static void application_handler_on_start_document(void);
-
-static void application_handler_on_end_document(void);
-
-static void application_handler_on_begin_process(void);
-
-static void application_handler_on_process_arg(void);
-
-static void application_handler_on_property(void);
-
-static void application_handler_on_end_process(void);
-
-
-#endif
/*
- * $Id$
+ * Copyright 2010. The SimGrid Team. All right reserved.
*
- * Copyright 2010 Martin Quinson, Mehdi Fekari
- * All right reserved.
- *
- * This program is free software; you can redistribute
- * it and/or modify it under the terms of the license
- *(GNU LGPL) which comes with this package.
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the license GNU LGPL) which comes with this package.
*/
#include "rb_msg.h"
+++ /dev/null
-#ifndef RB_MSG
-#define RB_MSG
-#include <stdio.h>
-#include "msg/msg.h"
-#include <ruby.h>
-
-XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test,
- "Messages specific for this msg example");
-
-// #include "msg/private.h"
-// #include "simix/private.h"
-// #include "simix/smx_context_ruby.h"
-
-// MSG Module
-VALUE rb_msg;
-// MSG Classes
-VALUE rb_task;
-VALUE rb_host;
-
-//init_Msg Called When The Ruby Interpreter loads this C extension
-void Init_msg();
-
-// Msg_Init From Ruby
-static void msg_init(VALUE Class,VALUE args);
-
-// Msg_Run From Ruby
-static void msg_run(VALUE Class);
-
-// Create Environment
-static void msg_createEnvironment(VALUE Class,VALUE plateformFile);
-
-// deploy Application
-static void msg_deployApplication(VALUE Class,VALUE deploymntFile);
-
-// Tools
-static void msg_info(VALUE Class,VALUE msg);
-
-//get Clock
-static void msg_get_clock(VALUE Class);
-
-//pajeOutput
-static void msg_paje_output(VALUE Class,VALUE pajeFile);
-
-// Ruby Introspection : To instanciate a Ruby Class from its Name
-static VALUE msg_new_ruby_instance(VALUE Class,VALUE className);
-
-// The Same ... This Time with Args
-static VALUE msg_new_ruby_instance_with_args(VALUE Class,VALUE className,VALUE args);
-
-#endif
\ No newline at end of file
const char * h_name = RSTRING(name)->ptr;
m_host_t host = MSG_get_host_by_name(h_name);
if(!host)
- rb_raise(rb_eRuntimeError,"MSG_get_host_by_name() failed");
+ rb_raise(rb_eRuntimeError,bprintf("No host called '%s' found",h_name));
return Data_Wrap_Struct(class,0,rb_host_free,host);
}
void initRuby(void) {
ruby_init();
ruby_init_loadpath();
- rb_require("RubyProcess.rb");
+// KILLME rb_require("RubyProcess.rb");
}
#include "bindings/ruby_bindings.h"
+XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(ruby);
+
// Free Method
void rb_task_free(m_task_t tk) {
MSG_task_destroy(tk);
// Wrap Ruby Value to m_task_t struct
m_task_t tk;
Data_Get_Struct(task, s_m_task_t, tk);
+ xbt_backtrace_display_current();
int res = MSG_task_send(tk,RSTRING(mailbox)->ptr);
if(res != MSG_OK)
rb_raise(rb_eRuntimeError,"MSG_task_send failed");
}
// Receiving Task (returns a Task)
-VALUE rb_task_receive(VALUE class,VALUE mailbox) {
+VALUE rb_task_receive(VALUE class, VALUE mailbox) {
// Task
m_task_t task = NULL;
+ INFO1("Receiving a task on mailbox %s",RSTRING(mailbox)->ptr);
+ xbt_backtrace_display_current();
MSG_task_receive(&task,RSTRING(mailbox)->ptr);
+ INFO2("XXXXXXXXReceived a task %p %s",task,task->name);
return Data_Wrap_Struct(class, 0, rb_task_free, task);
}
-// Recieve Task 2
-// Not Appreciated
-void rb_task_receive2(VALUE class,VALUE task,VALUE mailbox) {
- m_task_t tk;
- Data_Get_Struct(task, s_m_task_t, tk);
- MSG_task_receive(&tk,RSTRING(mailbox)->ptr);
-}
-
// It Return a Native Process ( m_process_t )
VALUE rb_task_sender(VALUE class,VALUE task) {
m_task_t tk;
--- /dev/null
+require 'simgrid_ruby'
+include MSG
+require 'thread'
+
+$DEBUG = true # This is a Global Variable Useful for Debugging
+
+###########################################################################
+# Class Semaphore
+###########################################################################
+class Semaphore
+ Thread.abort_on_exception = true
+ attr_accessor :permits
+
+ def initialize ( permits )
+ @permits = permits
+ end
+
+
+ def acquire(mutex,cv)
+ raise "Interrupted Thread " if (!Thread.current.alive?)
+ mutex.synchronize {
+ while @permits <= 0
+ cv.wait(mutex)
+ end
+
+ @permits = @permits - 1
+ cv.signal
+ }
+ end
+
+ def release(mutex,cv)
+ mutex.synchronize{
+ @permits += 1
+ cv.signal
+ }
+ end
+end
+
+########################################################################
+# Class RbProcess
+########################################################################
+class RbProcess < Thread
+ @@nextProcessId = 0
+# Attributes
+ attr_accessor :bind, :id, :properties, :name,
+ :pargs, :schedBegin, :schedEnd, :mutex, :cv
+
+# Initialize : Used from ApplicationHandler to fill it in
+ def initialize(*args)
+
+ argc = args.size
+
+ if argc == 0 # Default initializer
+ super() {
+ @id = 0
+ @bind = 0
+ @name = ""
+ @pargs = Array.new()
+ init_var()
+ start()
+ if $DEBUG
+ puts "Init Default Initializer...Nothing to do...Bye"
+ end
+ }
+
+ # 2 arguments: (HostName,Name) Or (Host , Name)
+ elsif argc == 2
+ super(){
+ type = args[0].type()
+ if ( type.to_s == "String")
+ host = Host.getByName(args[0])
+ elsif ( type.to_s == "MSG::Host")
+ host = args[0]
+ else
+ raise "first argument of type "+args[0].type().to_s+", but expecting either String or MSG::Host"
+ end
+ if $DEBUG
+ puts host
+ end
+ raise "Process name cannot be null" if args[1].empty?
+ @name = args[1]
+ if $DEBUG
+ puts @name
+ end
+ @pargs = Array.new() # No Args[] Passed in Arguments
+ @@nextProcessId += 1
+ @id = @@nextProcessId
+ init_var()
+ start()
+ createProcess(self,host)
+ if $DEBUG
+ puts "Initilize with 2 args"
+ end
+ }
+
+ # 3 arguments: (hostName,Name,args[]) or (Host,Name,args[])
+ elsif argc == 3
+ super(){
+ type = args[0].type()
+ if ( type.to_s == "String")
+ host = Host.getByName(args[0])
+ elsif ( type.to_s == "MSG::Host")
+ host = args[0]
+ else
+ raise "first argument of type "+args[0].type().to_s+", but expecting either String or MSG::Host"
+ end
+ if $DEBUG
+ puts host
+ end
+
+ raise "Process name cannot be null" if args[1].empty?
+ @name = args[1]
+ type = args[2].type()
+ raise "Third argument should be an Array" if type != "Array"
+ @pargs = args[3]
+ @@nextProcessId +=1
+ @id = @@nextProcessId
+ init_var()
+ createProcess(self,host)
+
+ if $DEBUG
+ puts "Initilize with 3 args"
+ end
+
+# sleep #keep the thread running
+ }
+ else
+ raise "Bad number of argument: Expecting either 1, 2 or 3, but got "+argc
+ end
+ end
+
+ # Init_var Called By Initialize
+ def init_var()
+ @proprieties = Hash.new()
+ @mutex = Mutex.new
+ @cv = ConditionVariable.new
+ # Process Synchronization Tools
+ @schedBegin = Semaphore.new(0)
+ @schedEnd = Semaphore.new(0)
+ end
+
+ #main
+ def msg_main(args)
+ # To Be Implemented within The Process...
+ # The Main Code of The Process to be Executed ...
+ end
+
+ # Start : To keep the Process Alive and waitin' via semaphore
+ def start()
+ @schedBegin.acquire(@mutex,@cv)
+ #execute The Main Code of The Process ( Example Master ; Slave ...)
+ msg_main(@pargs)
+ processExit(self) #Exite the Native Process
+ @schedEnd.release(@mutex,@cv)
+ end
+
+# NetxId
+ def nextId ()
+ @@nextProcessId +=1
+ return @@nextProcessId
+ end
+
+ if $DEBUG
+ #Process List
+ def processList()
+ Thread.list.each {|t| p t}
+ end
+ end
+
+ #Get Own ID
+ def getID()
+ return @id
+ end
+
+ # set Id
+ def setID(id)
+ @id = id
+ end
+
+ #Get a Process ID
+ def processID(process)
+ return process.id
+ end
+
+ #Get Own Name
+ def getName()
+ return @name
+ end
+
+ #Get a Process Name
+ def processName(process)
+ return process.name
+ end
+
+ #Get Bind
+ def getBind()
+ return @bind
+ end
+
+ #Get Binds
+ def setBind(bind)
+ @bind = bind
+ end
+
+ def unschedule()
+
+ @schedEnd.release(@mutex,@cv)
+# info("@schedEnd.release(@mutex,@cv)")
+ @schedBegin.acquire(@mutex,@cv)
+# info("@schedBegin.acquire(@mutex,@cv)")
+
+ end
+
+ def schedule()
+ @schedBegin.release(@mutex,@cv)
+ @schedEnd.acquire(@mutex,@cv)
+ end
+
+ #C Simualateur Process Equivalent Management
+ # After Binding Ruby Process to C Process
+
+# pause
+ def pause()
+ processSuspend(self)
+ end
+
+# restart
+ def restart()
+ processResume(self)
+ end
+
+# isSuspended
+ def isSuspended()
+ processIsSuspended(self)
+ end
+
+# getHost
+ def getHost()
+ processGetHost(self)
+ end
+
+# The Rest of Methods !!! To be Continued ...
+end
+
+########################################################################
+# Class ProcessFactory
+########################################################################
+
+class ProcessFactory
+
+# Attributes
+ attr_accessor :args, :proprieties, :hostName, :function
+# Initlialize
+ def initialize()
+
+ @args = Array.new
+ @proprieties = Hash.new
+ @hostName = nil
+ @function = nil
+
+ end
+
+# setProcessIdentity
+ def setProcessIdentity(hostName,function)
+ @hostName = hostName
+ @function = function
+
+ if !args.empty?
+ args.clear
+ end
+
+ if !proprieties.empty?
+ proprieties.clear
+ end
+
+ end
+
+# RegisterProcess
+ def registerProcessArg(arg)
+
+ @args.push(arg)
+
+ end
+
+# CreateProcess
+ def createProcess()
+
+ process = rubyNewInstance(@function) # process = rubyNewInstanceArgs(@function,@args) #
+ size = @args.size
+ for i in 0..size-1
+ process.pargs.push(@args[i])
+ end
+ process.name = @function
+ process.id = process.nextId() # This increment Automaticaly The Static ProcessNextId for The Class RbProces
+ host = RbHost.getByName(@hostName)
+ processCreate(process,host)
+ process.properties = @properties
+ @proprieties = Hash.new
+
+ end
+
+# SetProperty
+ def setProperty(id,value)
+ @proprieties[id] = value
+ end
+end
+
+#########################################################################
+# Class ApplicationHandler
+#########################################################################
+class ApplicationHandler
+ @processFactory
+# Initialize
+ def initialize()
+ #Nothing todo
+ end
+
+ # onStartDocument
+ def onStartDocument()
+
+ @processFactory = ProcessFactory.new
+ if ($DEBUG)
+ puts "onStartDocument"
+ end
+
+ end
+
+# onBeginProcess
+ def onBeginProcess(hostName,function)
+
+ @processFactory.setProcessIdentity(hostName,function)
+
+ if ($DEBUG)
+ puts "onBeginProcess"
+ end
+
+ end
+
+# onProperty
+ def onProperty(id,value)
+
+ @processFactory.setProperty(id,value)
+
+ if ($DEBUG)
+ puts "onProperty"
+ end
+
+ end
+
+# RegisterProcessArg
+ def onProcessArg(arg)
+
+ @processFactory.registerProcessArg(arg)
+
+ if ($DEBUG)
+ puts "onProcessArg"
+ end
+
+ end
+
+# OnEndProcess
+ def onEndProcess()
+
+ @processFactory.createProcess()
+
+ if ($DEBUG)
+ puts "onEndProcess"
+ end
+
+ end
+
+ # onEndDocument
+ def onEndDocument()
+# Erm... Actually nothing to do !!
+
+ if($DEBUG)
+ puts "onEndDocument"
+ end
+ end
+
+ # End Class
+ end
+
+#########################
+# Class RbHost
+#########################
+
+class RbHost < Host
+# Attributes
+ attr_accessor :bind, :data
+
+# Initialize
+ def initialize()
+ super()
+ @bind = 0
+ @data = nil
+ end
+
+end
+
+#########################
+# Class RbTask
+#########################
+class RbTask < Task
+ attr_accessor :bind
+
+ def initialize(name,comp_size,comm_size)
+ super(name,comp_size,comm_size)
+ end
+
+end
+
+#########################
+# Main chunck
+#########################
+MSG.init(ARGV)
--- /dev/null
+/* SimGrid Ruby bindings */
+
+/* Copyright (c) 2010, the SimGrid team. All right reserved. */
+
+/* This program is free software; you can redistribute it and/or modify it
+ * under the terms of the license (GNU LGPL) which comes with this package. */
+
+#include "xbt.h"
+#include "bindings/ruby_bindings.h"
+
+XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(ruby);
+
+// MSG Module
+VALUE rb_msg;
+// MSG Classes
+VALUE rb_task;
+VALUE rb_host;
+
+
+//Init Msg From Ruby
+static void msg_init(VALUE Class,VALUE args)
+{
+ char **argv=NULL;
+ const char *tmp;
+ int argc,type,i;
+ VALUE *ptr ;
+ // Testing The Args Type
+ type = TYPE(args);
+ if (type != T_ARRAY )
+ {
+ rb_raise(rb_eRuntimeError,"Argh!!! Bad Arguments to msg_init");
+ return;
+ }
+ ptr= RARRAY(args)->ptr;
+ argc= RARRAY(args)->len;
+ // Create C Array to Hold Data_Get_Struct
+ argc++;
+ argv = xbt_new0(char *, argc);
+ argv[0] = strdup("ruby");
+ for (i=0;i<argc-1;i++)
+ {
+ VALUE value = ptr[i];
+ type = TYPE(value);
+ // if (type == T_STRING)
+ tmp = RSTRING(value)->ptr;
+ argv[i+1] = strdup(tmp);
+ }
+ // Calling C Msg_Init Method
+ MSG_global_init(&argc,argv);
+ MSG_set_channel_number(10); // Okey !! Okey !! This Must Be Fixed Dynamiclly , But Later ;)
+ SIMIX_context_select_factory("ruby");
+
+ // Free Stuffs
+ for (i=0;i<argc;i++)
+ free(argv[i]) ;
+
+ free (argv);
+ DEBUG0("Msg Init...Done");
+ return;
+}
+//Init Msg_Run From Ruby
+static void msg_run(VALUE class) {
+ DEBUG0("Start Running...");
+ m_host_t *hosts;
+ int cpt,host_count;
+ VALUE rbHost;
+ // Let's Run
+ //printf("msg_run3\n");
+ if (MSG_OK != MSG_main()){
+ rb_raise(rb_eRuntimeError,"MSG_main() failed");
+ }
+
+ DEBUG0
+ ("MSG_main finished. Bail out before cleanup since there is a bug in this part.");
+ /* Cleanup Ruby hosts */
+ DEBUG0("Clean Ruby World");
+ hosts = MSG_get_host_table();
+ host_count = MSG_get_host_number();
+ for (cpt=0;cpt<host_count;cpt++) {
+ rbHost = (VALUE)((hosts[cpt])->data);// ??!!
+ }
+
+ if (MSG_OK != MSG_clean()){
+ rb_raise(rb_eRuntimeError,"MSG_clean() failed");
+ }
+ return;
+}
+
+static void msg_createEnvironment(VALUE class,VALUE plateformFile) {
+
+ int type = TYPE(plateformFile);
+ if ( type != T_STRING )
+ rb_raise(rb_eRuntimeError,"Bad Argument's Type");
+ const char * platform = RSTRING(plateformFile)->ptr;
+ MSG_create_environment(platform);
+ DEBUG1("Create Environment (%s)...Done",platform);
+}
+
+//deploy Application
+static void msg_deployApplication(VALUE class,VALUE deploymentFile ) {
+
+ int type = TYPE(deploymentFile);
+ if ( type != T_STRING )
+ rb_raise(rb_eRuntimeError,"Bad Argument's Type for deployApplication ");
+ const char *dep_file = RSTRING(deploymentFile)->ptr;
+ surf_parse_reset_parser();
+ surfxml_add_callback(STag_surfxml_process_cb_list,
+ rb_application_handler_on_begin_process);
+
+ surfxml_add_callback(ETag_surfxml_argument_cb_list,
+ rb_application_handler_on_process_arg);
+
+ surfxml_add_callback(STag_surfxml_prop_cb_list,
+ rb_application_handler_on_property);
+
+ surfxml_add_callback(ETag_surfxml_process_cb_list,
+ rb_application_handler_on_end_process);
+
+ surf_parse_open(dep_file);
+ rb_application_handler_on_start_document();
+ if(surf_parse())
+ rb_raise(rb_eRuntimeError,"surf_parse() failed");
+ surf_parse_close();
+ rb_application_handler_on_end_document();
+
+ DEBUG1("Deploy Application(%s)...Done",dep_file);
+}
+
+// INFO
+static void msg_info(VALUE class,VALUE msg) {
+ const char *s = RSTRING(msg)->ptr;
+ INFO1("%s",s);
+}
+
+// Get Clock
+static void msg_get_clock(VALUE class) {
+
+ printf("Simulation time %f\n",MSG_get_clock());
+
+}
+
+// Ruby intropspection : Instanciate a ruby Class From its Name
+// Used by ProcessFactory::createProcess
+
+static VALUE msg_new_ruby_instance(VALUE class,VALUE className) {
+ ruby_init();
+ ruby_init_loadpath();
+ char * p_className = RSTRING(className)->ptr;
+
+ return rb_funcall3(rb_const_get(rb_cObject, rb_intern(p_className)),rb_intern("new"),0, 0);
+}
+
+//This Time With Args
+static VALUE msg_new_ruby_instance_with_args(VALUE class,VALUE className,VALUE args) {
+ ruby_init();
+ ruby_init_loadpath();
+ char * p_className = RSTRING(className)->ptr;
+ return rb_funcall(rb_const_get(rb_cObject, rb_intern(p_className)),rb_intern("new"), 1, args);
+}
+
+
+
+typedef VALUE(*rb_meth)(ANYARGS);
+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,"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);
+
+ // Associated Process Methods
+ rb_define_method(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,"processKill",(rb_meth)rb_process_kill_up,1);
+ rb_define_method(rb_msg,"processGetHost",(rb_meth)rb_process_getHost,1);
+ rb_define_method(rb_msg,"processExit",(rb_meth)rb_process_exit,1);
+
+ //Classes
+ rb_task = rb_define_class_under(rb_msg,"Task",rb_cObject);
+ rb_host = rb_define_class_under(rb_msg,"Host",rb_cObject);
+
+ //Task 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,"execute",(rb_meth)rb_task_execute,1);
+ rb_define_module_function(rb_task,"send",(rb_meth)rb_task_send,2);
+ rb_define_module_function(rb_task,"receive",(rb_meth)rb_task_receive,1);
+ rb_define_module_function(rb_task,"sender",(rb_meth)rb_task_sender,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);
+
+ //Host Methods
+ rb_define_module_function(rb_host,"getByName",(rb_meth)rb_host_get_by_name,1);
+ rb_define_module_function(rb_host,"name",(rb_meth)rb_host_name,1);
+ rb_define_module_function(rb_host,"speed",(rb_meth)rb_host_speed,1);
+ rb_define_module_function(rb_host,"number",(rb_meth)rb_host_number,0);
+ 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,"hasData",host_has_data,1);
+ rb_define_module_function(rb_host,"isAvail",(rb_meth)rb_host_is_avail,1);
+
+}
--- /dev/null
+../../.libs/simgrid_ruby.so
\ No newline at end of file
+++ /dev/null
-/* $Id$ */
-
-/* context_Ruby - implementation of context switching with lua coroutines */
-
-/* Copyright (c) 2004-2008 the SimGrid team. All right reserved */
-
-/* This program is free software; you can redistribute it and/or modify it
- * under the terms of the license (GNU LGPL) which comes with this package. */
-#include <ruby.h>
-#include "private.h"
-#include "xbt/function_types.h"
-#include "context_sysv_config.h"
-
-typedef struct s_smx_ctx_ruby
-{
- SMX_CTX_BASE_T;
- VALUE process; // The Process Ruby Instance
- //...
-}s_smx_ctx_ruby_t,*smx_ctx_ruby_t;
-
-static smx_context_t
-smx_ctx_ruby_create_context(xbt_main_func_t code,int argc,char** argv,
- void_f_pvoid_t cleanup_func,void *cleanup_arg);
-
-
-static int smx_ctx_ruby_factory_finalize(smx_context_factory_t *factory);
-
-static void smx_ctx_ruby_free(smx_context_t context);
-
-static void smx_ctx_ruby_start(smx_context_t context);
-
-static void smx_ctx_ruby_stop(smx_context_t context);
-
-static void smx_ctx_ruby_suspend(smx_context_t context);
-
-static void
- smx_ctx_ruby_resume(smx_context_t old_context,smx_context_t new_context);
-
-static void smx_ctx_ruby_wrapper(void); //??!!
-
-
-
-void SIMIX_ctx_ruby_factory_init(smx_context_factory_t *factory)
-{
-
- *factory = xbt_new0(s_smx_context_factory_t,1);
-
- (*factory)->create_context = smx_ctx_ruby_create_context;
- (*factory)->finalize = smx_ctx_ruby_factory_finalize;
- (*factory)->free = smx_ctx_ruby_free;
- (*factory)->start = smx_ctx_ruby_start;
- (*factory)->stop = smx_ctx_ruby_stop;
- (*factory)->suspend = smx_ctx_ruby_suspend;
- (*factory)->resume = smx_ctx_ruby_resume;
- (*factory)->name = "smx_ruby_context_factory";
-
- ruby_init();
- ruby_init_loadpath();
-
-}
-
-static int smx_ctx_ruby_factory_finalize(smx_context_factory_t *factory)
-{
-
- free(*factory);
- *factory = NULL;
- return 0;
-
-}
-
-static smx_context_t
- smx_ctx_ruby_create_context(xbt_main_func_t code,int argc,char** argv,
- void_f_pvoid_t cleanup_func,void* cleanup_arg)
-{
-
- smx_ctx_ruby_t context = xbt_new0(s_smx_ruby_t,1);
-
- /*if the user provided a function for the process , then use it
- Otherwise it's the context for maestro */
- if( code )
- {
- context->cleanup_func = cleanup_func;
- context->cleanup_arg = cleanup_arg;
- context->process = rb_funcall3(rb_const_get(rb_cObject, rb_intern("RbProcess")), rb_intern("new"), 0, 0);
- //context->process = rb_thread_main(); // Or VALUE rb_thread_create ( VALUE(*(ANYARGS), void *) )
-
-
- }
- return (smx_context_t) context;
-
-}
-
-static void smx_ctx_ruby_free(smx_context_t context)
-{
-
- if (context)
- {
- smx_ctx_ruby_t ctx_ruby = (smx_ctx_ruby_t) context;
-
- if (ctx_ruby->process)
- VALUE process = ctx_ruby->process;
-
- ctx_ruby->process = Qnil;
-
- // if the Ruby Process is Alive , Join it
-
- if ( process_isAlive(process) )
- process_join(process);
-
- }
-
- free(context);
- context = NULL;
-
-
- }
-
-
-}
-
-
-static void smx_ctx_ruby_start(smx_context_t context)
-{
-
-
-
-}
-
-
-static void smx_ctx_ruby_stop(smx_context_t context)
-{
-
- VALUE process = Qnil;
- smx_ctx_ruby_t ctx_ruby;
-
- if ( context->cleanup_func)
- (*(context->cleanup_func)) (context->cleanup_arg);
-
- ctx_ruby = (smx_ctx_ruby_t) context;
-
- // Well , Let's Do The Same as JNI Stoppin' Process
- if ( simix_gloabl->current_process->iwannadie )
- {
- if( ctx_ruby->process )
- {
- //if the Ruby Process still Alive ,let's Schedule it
- if ( process_isAlive( ctx_ruby->process ) )
- {
-
- current = (smx_ctx_ruby_t)simix_gloabl->current_process->context:
- process_schedule(current->process);
-
- process = ctx_ruby->process;
-
- // interupt/kill The Ruby Process
- process_kill(process);
-
- }
- }
- }else {
-
- process = ctx_ruby->process;
- ctx_ruby->process = Qnil;
-
- }
-
-
-}
-
-static void smx_ctx_ruby_suspend(smx_context_t context)
-{
-
-if ( context )
-{
-smx_ctx_ruby_t ctx_ruby = (smx_ctx_ruby_t) context;
- if (ctx_ruby->process)
- process_unschedule( ctx_ruby->process ) ;
-}
-
- else
- rb_raise(rb_eRuntimeError,"smx_ctx_ruby_suspend failed");
-
-}
-
-static void smx_ctx_ruby_resume(smx_context_t old_context,smx_context_t new_context)
-{
-
- smx_ctx_ruby_t ctx_ruby = (smx_ctx_ruby_t) new_context;
-
- process_schedule( ctx_ruby->process );
-
-
-}
}s_smx_ctx_ruby_t,*smx_ctx_ruby_t;
void SIMIX_ctx_ruby_factory_init(smx_context_factory_t *factory);
-
+void Init_simgrid_ruby(void); /* Load the bindings */
void initRuby(void); // Mandatory to call Ruby methods from C
/* *********************************************** *
VALUE rb_task_listen(VALUE Class,VALUE task,VALUE alias); //Listen From Alias (=mailbox)
VALUE rb_task_listen_host(VALUE Class,VALUE task,VALUE alias,VALUE host); //Listen from Host
+/* Upcalls for the application handler */
+void rb_application_handler_on_start_document(void);
+void rb_application_handler_on_end_document(void);
+void rb_application_handler_on_begin_process(void);
+void rb_application_handler_on_process_arg(void);
+void rb_application_handler_on_property(void);
+void rb_application_handler_on_end_process(void);
+
#endif /* RB_SG_BINDINGS */
double timeout)
{
xbt_ex_t e;
- size_t task_size = sizeof(void*);
MSG_error_t ret = MSG_OK;
smx_comm_t comm;
CHECK_HOST();
+ memset(&comm,0,sizeof(comm));
/* Kept for compatibility with older implementation */
xbt_assert1(!MSG_mailbox_get_cond(mailbox),
"A process is already blocked on this channel %s",
/* Try to receive it by calling SIMIX network layer */
TRY{
- SIMIX_network_recv(mailbox->rdv, timeout, task, &task_size, &comm);
+ SIMIX_network_recv(mailbox->rdv, timeout, task, NULL, &comm);
(*task)->simdata->refcount--;
}
CATCH(e){
/* Data to be transfered */
void *src_buff;
- size_t src_buff_size;
void *dst_buff;
+ size_t src_buff_size;
size_t *dst_buff_size;
void *data; /* User data associated to communication */
} s_smx_comm_t;
#include "bindings/ruby_bindings.h"
+XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(ruby);
+
static smx_context_t
smx_ctx_ruby_create_context(xbt_main_func_t code,int argc,char** argv,
void_f_pvoid_t cleanup_func,void *cleanup_arg);
if(!comm->src_buff || !comm->dst_buff)
return;
- size_t src_buff_size = comm->src_buff_size;
- size_t dst_buff_size = *comm->dst_buff_size;
-
/* Copy at most dst_buff_size bytes of the message to receiver's buffer */
- dst_buff_size = MIN(dst_buff_size, src_buff_size);
+ size_t buff_size = comm->src_buff_size;
+ if (comm->dst_buff_size)
+ buff_size = MIN(buff_size,*(comm->dst_buff_size));
/* Update the receiver's buffer size to the copied amount */
if (comm->dst_buff_size)
- *comm->dst_buff_size = dst_buff_size;
+ *comm->dst_buff_size = buff_size;
- if(dst_buff_size == 0)
+ if(buff_size == 0)
return;
- memcpy(comm->dst_buff, comm->src_buff, dst_buff_size);
-
- DEBUG4("Copying comm %p data from %s -> %s (%zu bytes)",
+ DEBUG4("Copying comm %p data from %s -> %s (%zu bytes)",
comm, comm->src_proc->smx_host->name, comm->dst_proc->smx_host->name,
- dst_buff_size);
+ buff_size);
+
+ memcpy(comm->dst_buff, comm->src_buff, buff_size);
}
/**