Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
simple example ruby using simdag (first tests)
authorcoldpeace <coldpeace@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Thu, 18 Mar 2010 16:23:40 +0000 (16:23 +0000)
committercoldpeace <coldpeace@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Thu, 18 Mar 2010 16:23:40 +0000 (16:23 +0000)
git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@7270 48e7efb5-ca39-0410-a469-dd3cf9ba447f

src/bindings/rubyDag/Makefile [new file with mode: 0644]
src/bindings/rubyDag/example.rb [new file with mode: 0644]
src/bindings/rubyDag/extconfig.rb [new file with mode: 0644]
src/bindings/rubyDag/platform.xml [new file with mode: 0644]
src/bindings/rubyDag/platform_.xml [new file with mode: 0644]
src/bindings/rubyDag/rb_SD_task.c [new file with mode: 0644]
src/bindings/rubyDag/rb_SD_task.h [new file with mode: 0644]
src/bindings/rubyDag/rb_SD_workstation.c [new file with mode: 0644]
src/bindings/rubyDag/rb_SD_workstation.h [new file with mode: 0644]
src/bindings/rubyDag/rb_simdag.c [new file with mode: 0644]
src/bindings/rubyDag/simdag.rb [new file with mode: 0644]

diff --git a/src/bindings/rubyDag/Makefile b/src/bindings/rubyDag/Makefile
new file mode 100644 (file)
index 0000000..48d3c0d
--- /dev/null
@@ -0,0 +1,157 @@
+
+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 -I /usr/include/lua5.1/ -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)
+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_SD_task.c rb_SD_workstation.c rb_simdag.c
+OBJS = rb_SD_task.o rb_SD_workstation.o rb_simdag.o
+TARGET = dag
+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
diff --git a/src/bindings/rubyDag/example.rb b/src/bindings/rubyDag/example.rb
new file mode 100644 (file)
index 0000000..c3993a0
--- /dev/null
@@ -0,0 +1,70 @@
+require 'simdag'
+include DAG
+
+# Still using the old method to run :
+#>> make     ( to generate dag.so)
+#>> ruby example.rb   ( to run )
+# FIXME if using valgrind , you will get Some 'Invalid Read of Size" When Calling rb_task_schedule  '
+
+
+class Example
+
+  def initialize()
+    DAG.init(ARGV)
+    
+    if (ARGV.length == 1)
+      DAG.init(ARGV[0])
+    else 
+      DAG.createEnvironment("platform.xml")
+    end
+   
+    taskA = DAG::Task.new("Tache A",10)
+    taskB = DAG::Task.new("Tache B",40)
+    taskC = DAG::Task.new("Tache C",30)
+    taskD = DAG::Task.new("Tache D",60)
+    
+#     Adding dependency
+    DAG::Task::addDependency(taskB,taskA)
+    DAG::Task::addDependency(taskC,taskA)
+    DAG::Task::addDependency(taskD,taskB)
+    DAG::Task::addDependency(taskD,taskC)
+
+#      Execution Params
+    
+    workstation_number = 2
+    workstation_list = DAG::Workstation.getList()
+    w1 = workstation_list[0]
+    w2 = workstation_list[1]
+    
+     p "workstation 1 : "+ w1.name
+     p "workstation 2 : "+ w2.name
+    
+    computation_amount = Array.new()
+    communication_amount = Array.new()
+    
+    computation_amount << 2000000 << 1000000
+    communication_amount << 200000 << 300000
+    
+    rate = -1
+    
+#     Scheduling
+    
+    DAG::Task.schedule(taskA,workstation_number,workstation_list,computation_amount,communication_amount,rate)
+    DAG::Task.schedule(taskB,workstation_number,workstation_list,computation_amount,communication_amount,rate)
+    DAG::Task.schedule(taskC,workstation_number,workstation_list,computation_amount,communication_amount,rate)
+    DAG::Task.schedule(taskD,workstation_number,workstation_list,computation_amount,communication_amount,rate)
+   
+    changed_tasks = Array.new()
+    changed_tasks = DAG::Task.simulate(-1.0)
+
+    for i in 0..changed_tasks.size-1
+      puts "Task "+ changed_tasks[i].name + " Started at " + changed_tasks[i].startTime.to_s + " has been done at "+ changed_tasks[i].finishTime.to_s
+      
+    end
+        
+    puts "Everything's Done ... Bye!!"
+
+    end
+end
+
+expl = Example.new 
\ No newline at end of file
diff --git a/src/bindings/rubyDag/extconfig.rb b/src/bindings/rubyDag/extconfig.rb
new file mode 100644 (file)
index 0000000..f557573
--- /dev/null
@@ -0,0 +1,4 @@
+require 'mkmf'
+extension_name ='dag'
+dir_config(extension_name)
+create_makefile(extension_name)
diff --git a/src/bindings/rubyDag/platform.xml b/src/bindings/rubyDag/platform.xml
new file mode 100644 (file)
index 0000000..3fa9afd
--- /dev/null
@@ -0,0 +1,89 @@
+<?xml version='1.0'?>
+<!DOCTYPE platform SYSTEM "simgrid.dtd">
+<platform version="2">
+  <!-- ljlkj -->
+  <host id="Tremblay" power="98095000"/>
+  <host id="Jupiter" 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" bandwidth="498000000" latency="0.000015" sharing_policy="FATPIPE"/>
+  <route src="Tremblay" dst="Tremblay"><link:ctn id="loopback"/></route>
+  <route src="Jupiter" dst="Jupiter"><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="Tremblay" dst="Jupiter">
+    <link:ctn id="9"/>
+  </route>
+  <route src="Tremblay" 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="Tremblay" dst="Ginette">
+    <link:ctn id="4"/><link:ctn id="3"/><link:ctn id="5"/>
+  </route>
+  <route src="Tremblay" 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="Jupiter" dst="Tremblay">
+    <link:ctn id="9"/>
+  </route>
+  <route src="Jupiter" 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="Jupiter" dst="Ginette">
+    <link:ctn id="9"/><link:ctn id="4"/><link:ctn id="3"/><link:ctn id="5"/>
+  </route>
+  <route src="Jupiter" 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="Tremblay">
+    <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="Jupiter">
+    <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="Tremblay">
+    <link:ctn id="5"/><link:ctn id="3"/><link:ctn id="4"/>
+  </route>
+  <route src="Ginette" dst="Jupiter">
+    <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="Tremblay">
+    <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="Jupiter">
+    <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>
diff --git a/src/bindings/rubyDag/platform_.xml b/src/bindings/rubyDag/platform_.xml
new file mode 100644 (file)
index 0000000..3fa9afd
--- /dev/null
@@ -0,0 +1,89 @@
+<?xml version='1.0'?>
+<!DOCTYPE platform SYSTEM "simgrid.dtd">
+<platform version="2">
+  <!-- ljlkj -->
+  <host id="Tremblay" power="98095000"/>
+  <host id="Jupiter" 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" bandwidth="498000000" latency="0.000015" sharing_policy="FATPIPE"/>
+  <route src="Tremblay" dst="Tremblay"><link:ctn id="loopback"/></route>
+  <route src="Jupiter" dst="Jupiter"><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="Tremblay" dst="Jupiter">
+    <link:ctn id="9"/>
+  </route>
+  <route src="Tremblay" 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="Tremblay" dst="Ginette">
+    <link:ctn id="4"/><link:ctn id="3"/><link:ctn id="5"/>
+  </route>
+  <route src="Tremblay" 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="Jupiter" dst="Tremblay">
+    <link:ctn id="9"/>
+  </route>
+  <route src="Jupiter" 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="Jupiter" dst="Ginette">
+    <link:ctn id="9"/><link:ctn id="4"/><link:ctn id="3"/><link:ctn id="5"/>
+  </route>
+  <route src="Jupiter" 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="Tremblay">
+    <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="Jupiter">
+    <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="Tremblay">
+    <link:ctn id="5"/><link:ctn id="3"/><link:ctn id="4"/>
+  </route>
+  <route src="Ginette" dst="Jupiter">
+    <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="Tremblay">
+    <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="Jupiter">
+    <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>
diff --git a/src/bindings/rubyDag/rb_SD_task.c b/src/bindings/rubyDag/rb_SD_task.c
new file mode 100644 (file)
index 0000000..b2dadc4
--- /dev/null
@@ -0,0 +1,172 @@
+#include "rb_SD_task.h"
+
+// Free Method
+static void SD_task_free(SD_task_t tk) {
+//   SD_task_destroy(tk);
+}
+
+static void rb_SD_task_destroy(VALUE class,VALUE task)
+{
+ SD_task_t tk ;
+ Data_Get_Struct(task, SD_task_t, tk);
+ SD_task_destroy(tk); 
+}
+// New Method
+static VALUE rb_SD_task_new(VALUE class, VALUE name,VALUE amount)
+{
+  //data Set to NULL
+  SD_task_t task = SD_task_create(RSTRING(name)->ptr,NULL,NUM2DBL(amount));
+  // Wrap m_task_t to a Ruby Value
+  return Data_Wrap_Struct(class, 0, SD_task_free, task);
+
+}
+
+//Get Name
+static VALUE rb_SD_task_name(VALUE class,VALUE task)
+{
+  // Wrap Ruby Value to m_task_t struct
+  SD_task_t tk;
+  Data_Get_Struct(task, SD_task_t, tk);
+  return rb_str_new2(SD_task_get_name(tk));
+   
+}
+
+// Schedule Task
+static void rb_SD_task_schedule(VALUE class,VALUE task,VALUE workstation_nb,VALUE workstation_list,VALUE computation_amount,VALUE communication_amount,VALUE rate)
+{
+  // Wrap Ruby Value to m_task_t struct
+  int i,wrk_nb,comp_nb,comm_nb;
+  double *comp_amount,*comm_amount;
+  double rt;
+  VALUE *ptr_wrk,*ptr_comp,*ptr_comm;
+  SD_task_t tk;
+  Data_Get_Struct(task, SD_task_t, tk);
+  wrk_nb = NUM2INT(workstation_nb);
+  comp_nb = RARRAY(computation_amount)->len;
+  comm_nb = RARRAY(communication_amount)->len;
+  rt = NUM2DBL(rate);
+  SD_workstation_t *wrk_list;
+  
+  ptr_wrk = RARRAY(workstation_list)->ptr;
+  ptr_comp = RARRAY(computation_amount)->ptr;
+  ptr_comm = RARRAY(communication_amount)->ptr;
+  
+  wrk_list = xbt_new0(SD_workstation_t,wrk_nb);
+  comp_amount = xbt_new0(double,wrk_nb);//malloc(sizeof(double)*wrk_nb); //xbt_new0(double,wrk_nb);
+  comm_amount = xbt_new0(double,wrk_nb);//malloc(sizeof(double)*wrk_nb); //xbt_new0(double,wrk_nb);
+  
+  // wrk_nb == comp_nb == comm_nb ???
+  for (i=0;i<wrk_nb;i++)
+  {
+    Data_Get_Struct(ptr_wrk[i],SD_workstation_t,wrk_list[i]); 
+    comp_amount[i] = NUM2DBL(ptr_comp[i]);
+    comm_amount[i] = NUM2DBL(ptr_comm[i]);
+  }
+  /*for (i=0;i<comp_nb;i++)
+    comp_amount[i] = NUM2DBL(ptr_comp[i]);
+  
+  for (i=0;i<comm_nb;i++)
+    comm_amount[i] = NUM2DBL(ptr_comm[i]);*/
+  
+  
+  SD_task_schedule(tk,wrk_nb,wrk_list,comp_amount,comm_amount,rt);
+  
+  xbt_free(wrk_list);
+  printf("CoOoOoL\n");
+  // FIXME, used later if wanna calculate start & fininsh time for a task
+  free(comp_amount);
+  free(comm_amount);
+  
+
+}
+
+//unschedule
+static void rb_SD_task_unschedule(VALUE class,VALUE task)
+{
+  SD_task_t tk;
+  Data_Get_Struct(task,SD_task_t,tk);
+  SD_task_unschedule (tk);
+  
+}
+
+// task dependency add
+static void rb_SD_task_add_dependency(VALUE Class,VALUE task_src,VALUE task_dst)
+{
+  SD_task_t tk_src,tk_dst;
+  Data_Get_Struct(task_src, SD_task_t ,tk_src);
+  Data_Get_Struct(task_dst, SD_task_t ,tk_dst);
+  SD_task_dependency_add(NULL,NULL,tk_src,tk_dst);
+  
+}
+
+//task execution time
+static VALUE rb_SD_task_execution_time(VALUE class,VALUE task,VALUE workstation_nb,VALUE workstation_list,VALUE computation_amount,VALUE communication_amount,VALUE rate)
+{
+  
+  int i,wrk_nb;
+  double *comp_amount,*comm_amount;
+  double rt;
+  VALUE *ptr_wrk,*ptr_comp,*ptr_comm;
+  SD_task_t tk;
+  Data_Get_Struct(task, SD_task_t, tk);
+  wrk_nb = NUM2INT(workstation_nb);
+  rt = NUM2DBL(rate);
+  SD_workstation_t *wrk_list;
+  
+  ptr_wrk = RARRAY(workstation_list)->ptr;
+  ptr_comp = RARRAY(computation_amount)->ptr;
+  ptr_comm = RARRAY(communication_amount)->ptr;
+  
+  wrk_list = xbt_new0(SD_workstation_t,wrk_nb);
+  comp_amount = xbt_new0(double,wrk_nb);
+  comm_amount = xbt_new0(double,wrk_nb);
+  
+  for (i=0;i<wrk_nb;i++)
+  {
+    Data_Get_Struct(ptr_wrk[i],SD_workstation_t,wrk_list[i]); 
+    comp_amount[i] = NUM2DBL(ptr_comp[i]);
+    comm_amount[i] = NUM2DBL(ptr_comm[i]);
+  }
+  
+  return rb_float_new(SD_task_get_execution_time (tk,wrk_nb,wrk_list,comp_amount,comm_amount,rt));
+  
+}
+
+//task start time
+static VALUE rb_SD_task_start_time(VALUE class,VALUE task)
+{
+
+  SD_task_t tk;
+  Data_Get_Struct(task,SD_task_t,tk);
+  double time=SD_task_get_start_time(tk);
+  return rb_float_new(time);
+  
+}
+
+//task fininsh time
+static VALUE rb_SD_task_finish_time(VALUE class,VALUE task)
+{
+  SD_task_t tk;
+  Data_Get_Struct(task,SD_task_t,tk);
+  double time=SD_task_get_finish_time(tk);
+  return rb_float_new(time);
+  
+}
+
+// Simulate : return a SD_task
+static VALUE rb_SD_simulate(VALUE class,VALUE how_long)
+{
+  int i;
+  double hl = NUM2DBL(how_long);
+  SD_task_t * tasks = SD_simulate(hl); 
+  VALUE rb_tasks = rb_ary_new();
+  for (i = 0; tasks[i] != NULL; i++)
+    {
+      VALUE tk = Qnil;
+      tk = Data_Wrap_Struct(class, 0, SD_task_free, tasks[i]);
+      rb_ary_push(rb_tasks,tk);
+      
+    }
+  return  rb_tasks;
+}
diff --git a/src/bindings/rubyDag/rb_SD_task.h b/src/bindings/rubyDag/rb_SD_task.h
new file mode 100644 (file)
index 0000000..b308ccb
--- /dev/null
@@ -0,0 +1,42 @@
+#ifndef RB_SD_TASK_H
+#define RB_SD_TASK_H
+
+#include <ruby.h>
+#include <simdag/simdag.h>
+#include "xbt/sysdep.h" 
+
+
+// Free Method
+static void SD_task_free(SD_task_t tk); // needed by ruby while wrapping
+
+//destroy
+static void rb_SD_task_destory(VALUE Class,VALUE task);
+
+// New Method  
+static VALUE rb_SD_task_new(VALUE Class, VALUE name,VALUE amount); //data set to NULL
+
+//Get Name
+static VALUE rb_SD_task_name(VALUE Class,VALUE task);
+
+// Schedule Task
+static void rb_SD_task_schedule(VALUE Class,VALUE task,VALUE workstation_nb,VALUE workstation_list,VALUE comp_amount,VALUE comm_amount,VALUE rate);
+
+// unschedule Task
+static void rb_SD_task_unschedule(VALUE Class,VALUE task);
+
+// task dependency Add ( name & data set to NULL)
+static void rb_SD_task_add_dependency(VALUE Class,VALUE task_src,VALUE task_dst);
+
+// task execution time
+static VALUE rb_SD_task_execution_time(VALUE Class,VALUE task,VALUE workstation_nb,VALUE workstation_list,VALUE comp_amount,VALUE comm_amount,VALUE rate);
+
+// task start time
+static VALUE rb_SD_task_start_time(VALUE Class,VALUE task);
+
+// task finish time
+static VALUE rb_SD_task_finish_time(VALUE Class,VALUE task);
+
+// simulation
+static VALUE rb_SD_simulate(VALUE Class,VALUE how_long);
+
+#endif
\ No newline at end of file
diff --git a/src/bindings/rubyDag/rb_SD_workstation.c b/src/bindings/rubyDag/rb_SD_workstation.c
new file mode 100644 (file)
index 0000000..2be055d
--- /dev/null
@@ -0,0 +1,38 @@
+#include "rb_SD_workstation.h"
+
+static void SD_workstation_free(SD_workstation_t wrk)
+{
+  //NOTHING TO DO
+}
+// Workstation list
+static VALUE rb_SD_workstation_list(VALUE class)
+{
+  int i,nb;
+  nb = SD_workstation_get_number();
+  VALUE workstation_list = rb_ary_new2(nb);
+  for (i=0;i<nb;i++)
+  {
+   VALUE wrk = Qnil;
+   wrk = Data_Wrap_Struct(class, 0, SD_workstation_free, SD_workstation_get_list()[i]);
+   rb_ary_push(workstation_list,wrk);
+    
+  }
+  return workstation_list;
+}
+
+// Workstation number
+static VALUE rb_SD_workstation_number(VALUE class)
+{
+  int nb = SD_workstation_get_number();
+  return INT2NUM(nb);
+}
+
+// Workstation name
+static VALUE rb_SD_workstation_name(VALUE class,VALUE workstation)
+{
+ SD_workstation_t wk;
+ Data_Get_Struct(workstation, SD_workstation_t, wk);
+ return rb_str_new2(SD_workstation_get_name(wk));
+}
\ No newline at end of file
diff --git a/src/bindings/rubyDag/rb_SD_workstation.h b/src/bindings/rubyDag/rb_SD_workstation.h
new file mode 100644 (file)
index 0000000..8fadfec
--- /dev/null
@@ -0,0 +1,19 @@
+#ifndef RB_SD_WORKSTATION_H
+#define RB_SD_WORKSTATION_H
+
+#include <ruby.h>
+#include <simdag/simdag.h>
+
+// free
+static void SD_workstation_free(SD_workstation_t);
+
+// Workstation List
+static VALUE rb_SD_workstation_list(VALUE Class);
+
+// Workstation number
+static VALUE rb_SD_workstation_number(VALUE Class);
+
+// Workstation name
+static VALUE rb_SD_workstation_name(VALUE Class,VALUE workstation);
+
+#endif
\ No newline at end of file
diff --git a/src/bindings/rubyDag/rb_simdag.c b/src/bindings/rubyDag/rb_simdag.c
new file mode 100644 (file)
index 0000000..55aff59
--- /dev/null
@@ -0,0 +1,126 @@
+/* 
+ * $Id$
+ *
+ * Copyright 2010 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 "rb_SD_task.c"
+#include "rb_SD_workstation.c"
+#include <simdag/simdag.h>
+#define MY_DEBUG
+
+// XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(ruby);
+
+// MSG Module
+VALUE rb_dag;
+// MSG Classes
+VALUE rb_task;
+VALUE rb_workstation;
+
+//Init Msg_Init From Ruby
+static void sd_init(VALUE Class,VALUE args)
+{ 
+  char **argv=NULL;
+  const char *tmp;
+  int argc,type,i;
+  VALUE *ptr;
+  type = TYPE(args);
+  if ( type != T_ARRAY )
+  {
+   rb_raise(rb_eRuntimeError,"Bad Argument to SD_init");
+   return;
+  }
+  ptr = RARRAY(args)->ptr;
+  argc= RARRAY(args)->len;
+  argc++;
+  argv= xbt_new0(char*,argc);
+  argv[0] = strdup("ruby");
+  for (i=0;i<argc-1;i++)
+  {
+   VALUE value = ptr[i];
+   type = TYPE(value);
+   tmp = RSTRING(value)->ptr;
+   argv[i+1] = strdup(tmp); 
+  }
+  SD_init(&argc,argv);
+  free(argv);
+//   INFO0("SD Init...Done");
+  printf("SD Init...Done\n");
+  return;
+  
+}
+
+//Init Msg_Run From Ruby
+static void sd_reinit(VALUE class)
+{
+  SD_application_reinit();
+}
+//deploy Application
+static void sd_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;
+   SD_create_environment(platform);
+   printf("Create Environment...Done\n");
+
+ return;  
+}
+
+// INFO
+static void sd_info(VALUE class,VALUE msg)
+{
+ const char *s = RSTRING(msg)->ptr;
+//  INFO1("%s",s);
+ printf("%s\n",s);
+}
+
+// Get Clock
+static VALUE sd_get_clock(VALUE class)
+{
+  return rb_float_new(SD_get_clock());
+}   
+
+void Init_dag()
+{
+   // Modules
+   rb_dag = rb_define_module("DAG");
+    
+   // Classes
+   //Associated Environment Methods!
+   rb_define_method(rb_dag,"init",sd_init,1);
+   rb_define_method(rb_dag,"reinit",sd_reinit,0);
+   rb_define_method(rb_dag,"createEnvironment",sd_createEnvironment,1);
+   rb_define_method(rb_dag,"info",sd_info,1);
+   rb_define_method(rb_dag,"getClock",sd_get_clock,0);
+   
+   //Classes       
+   rb_task = rb_define_class_under(rb_dag,"SdTask",rb_cObject);
+   rb_workstation = rb_define_class_under(rb_dag,"SdWorkstation",rb_cObject);
+//    TODO Link Class
+    
+   //Task Methods    
+   rb_define_module_function(rb_task,"new",rb_SD_task_new,2);
+//    rb_define_module_function(rb_task,"free",rb_SD_task_destroy,1);
+   rb_define_module_function(rb_task,"name",rb_SD_task_name,1);
+   rb_define_module_function(rb_task,"schedule",rb_SD_task_schedule,6);
+   rb_define_module_function(rb_task,"unschedule",rb_SD_task_unschedule,1); 
+   rb_define_module_function(rb_task,"addDependency",rb_SD_task_add_dependency,2);
+   rb_define_module_function(rb_task,"executionTime",rb_SD_task_execution_time,6);
+   rb_define_module_function(rb_task,"startTime",rb_SD_task_start_time,1);
+   rb_define_module_function(rb_task,"finishTime",rb_SD_task_finish_time,1);
+   rb_define_module_function(rb_task,"simulate",rb_SD_simulate,1);
+   
+   //Worstation Methods  
+   rb_define_module_function(rb_workstation,"getList",rb_SD_workstation_list,0);
+   rb_define_module_function(rb_workstation,"getNumber",rb_SD_workstation_number,0);
+   rb_define_module_function(rb_workstation,"name",rb_SD_workstation_name,1);
+}  
diff --git a/src/bindings/rubyDag/simdag.rb b/src/bindings/rubyDag/simdag.rb
new file mode 100644 (file)
index 0000000..a4bccca
--- /dev/null
@@ -0,0 +1,39 @@
+require 'dag'
+
+#===========================
+# Task Class
+# ==========================
+class DAG::Task < DAG::SdTask
+  
+  def initialize(*args)
+    super(args)
+  end
+  
+  def name()
+    super(self)
+  end
+  
+  def startTime()
+    super(self)
+  end
+  
+  def finishTime()
+    super(self)
+  end
+  
+end
+
+#=============================
+# WorkStation Class
+#=============================
+class DAG::Workstation < DAG::SdWorkstation
+  
+  def initialize()
+    super()
+  end
+  
+  def name()
+    super(self)
+  end
+  
+end
\ No newline at end of file