SimGrid 3.6.2
Scalable simulation of distributed systems
Bindings

Lua Binding

Most of Simgrid modules require a good level in C programming, since simgrid is used to be as standard C library. Sometime users prefer using some kind of « easy scripts » or a language easier to code with, for their works, which avoid dealing with C errors, and sometime an important gain of time. Besides Java Binding, Lua and Ruby bindings are available since version 3.4 of Simgrid for MSG Module, and we are currenlty working on bindings for other modules.

What is lua ?

Lua is a lightweight, reflective, imperative and functional programming language, designed as a scripting language with extensible semantics as a primary goal (see official web site here).

Why lua ?

Lua is a fast, portable and powerful script language, quite simple to use for developpers. it combines procedural features with powerful data description facilities, by using a simple, yet powerful, mechanism of tables. Lua has a relatively simple C API compared to other scripting languages, and accordingly it provides a robust, easy to use it.

How to use lua in Simgrid ?

Actually, the use of lua in Simgrid is quite simple, you have just to follow the same steps as coding with C in Simgird :

Master/Slave Example

Exchanging Data

You can also exchange data between Process using lua. for that, you have to deal with lua task as a table, since lua is based itself on a mechanism of tables, so you can exchange any kind of data (tables, matrix, strings,…) between process via tasks.

Bypass XML

maybe you wonder if there is a way to bypass the XML files, and describe your platform directly from the code, with lua bindings it's Possible !! how ? We provide some additional (tricky?) functions in lua that allows you to set up your own platform without using the XML files ( this can be useful for large platforms, so a simple for loop will avoid you to deal with an annoying XML File ;) )

the full example is distributed in the file examples/lua/master_slave_bypass.lua

Ruby Binding

How to install Simgrid-ruby

To use Ruby with Simgrid you have to install some dependancies:

Then Download and install package Simgrid-ruby:

git clone git://scm.gforge.inria.fr/simgrid/simgrid-ruby.git
cd simgrid-ruby
cmake .

Cmake output

-- SITE        : Linux_2.6.38-8-generic_x86_64
-- BUILDNAME   : Simgrid-Ruby
-- Looking for lib SimGrid
-- Looking for lib SimGrid - found
-- Simgrid version : 3.6
-- Looking for gras.h
-- Looking for gras.h - found
-- Found Tesh: /home/user/Bureau/simgrid/git/bin/tesh
-- Found gras_stub_generator: /home/user/Bureau/simgrid/git/bin/gras_stub_generator
-- Found ruby:	/usr/bin/ruby
-- Looking for ruby.h
-- Looking for ruby.h - found
-- Looking for confi.h
-- Looking for config.h - found
-- Looking for lib ruby
-- Looking for lib ruby - found
-- Lib ruby version: 1.9.1
-- Configuring done
-- Generating done
-- Build files have been written to: /home/user/workspace/simgrid-ruby/build

Use Ruby in Simgrid

Since v3.4, the use of ruby in simgrid is available for the MSG Module. you can find almost all MSG functionalities in Ruby code, that allows you to set up your environment, manage tasks between hosts and run the simulation.

Master/Slave Ruby Application

for each process method(master and slave in this example), you have to associate a ruby class, that should inherit from MSG::Process ruby class, with a 'main' function that describe the behaviour of the process during the simulation.

the class MSG::Task contains methods that allows the management of the native MSG tasks. in master ruby code we used :

Exchanging data

ruby bindings provides two ways to exchange data between ruby processes.

the MSG::Task class contains 2 methods that allows a data exchange between 2 process.

-MSG::Task.join : makes possible to join any kind of ruby data within a task.

   ...
   myTable = Array.new
   myTable <<1<<-2<<45<<67<<87<<76<<89<<56<<78<<3<<-4<<99
   # Creates and send Task With the Table inside
   task = MSG::Task.new("quicksort_task",taskComputeSize, taskCommunicationSize);
   task.join(myTable);
   ...
   task.send(mailbox);
   

-MSG::Task.data : to access to the data contained into the task.

   ...
   task = MSG::Task.receive(recv_mailbox.to_s)
   table = task.data
   quicksort(table,0,table.size-1)
   ...
   

you can find a complet example illustrating the use of those methods in file /example/ruby/Quicksort.rb

another 'object-oriented' way to do it, is to make your own 'task' class that inherit from MSG::Task , and contains data you want to deal with, the only 'tricky' thing is that "the initializer" method has no effect !

the use of some getter/setter methods would be the simple way to manage your data :)

class PingPongTask < MSG::Task
  # The initialize method has no effect 
  @time 
  def setTime(t)
    @time = t
  end
  def getTime()
    return @time
  end
end
 

you can find an example of use in file example/ruby/PingPong.rb

Java Binding

How to install Simgrid-java

To use java with Simgrid you have to install some dependancies:

Then Download and install package Simgrid-java:

git clone git://scm.gforge.inria.fr/simgrid/simgrid-java.git
cd simgrid-java
cmake .

Cmake output

-- SITE        : Linux_2.6.38-8-generic_x86_64
-- BUILDNAME   : Simgrid-Java
-- Looking for lib SimGrid
-- Looking for lib SimGrid - found
-- Simgrid version : 3.6
-- Looking for gras.h
-- Looking for gras.h - found
-- Found Tesh: /home/user/Bureau/simgrid/git/bin/tesh
-- Found gras_stub_generator: /home/user/Bureau/simgrid/git/bin/gras_stub_generator
-- Java version 1.6.0.22 configured successfully!
-- Looking for jni.h
-- Looking for jni.h - found
-- Add flags -I/usr/lib/jvm/java-6-openjdk/include
-- Looking for jni_md.h
-- Looking for jni_md.h - found
-- Found javac: /usr/bin/javac
-- Found jar: /usr/bin/jar
-- Configuring done
-- Generating done
-- Build files have been written to: /home/user/workspace/simgrid-java/build

Use Java in Simgrid

The use of java in simgrid is available for the MSG Module. You can find almost all MSG functionalities in Java code (jMSG).


Back to the main Simgrid Documentation page The version of Simgrid documented here is v3.6.2.
Documentation of other versions can be found in their respective archive files (directory doc/html).
Generated for SimGridAPI by doxygen