SimGrid 3.6.2
Scalable simulation of distributed systems
|
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.
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).
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.
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 Function function Master(...) simgrid.info("Hello from lua, I'm the master") for i,v in ipairs(arg) do simgrid.info("Got "..v) end nb_task = arg[1]; comp_size = arg[2]; comm_size = arg[3]; slave_count = arg[4]; if (#arg ~= 4) then error("Argc should be 4"); end simgrid.info("Argc="..(#arg).." (should be 4)") -- Dispatch the tasks for i=1,nb_task do tk = simgrid.Task.new("Task "..i,comp_size,comm_size); alias = "slave "..(i%slave_count); simgrid.info("Master sending '" .. simgrid.Task.name(tk) .."' To '" .. alias .."'"); simgrid.Task.send(tk,alias); -- C user data set to NULL simgrid.info("Master done sending '".. simgrid.Task.name(tk) .."' To '" .. alias .."'"); end -- Sending Finalize Message To Others simgrid.info("Master: All tasks have been dispatched. Let's tell everybody the computation is over."); for i=0,slave_count-1 do alias = "slave "..i; simgrid.info("Master: sending finalize to "..alias); finalize = simgrid.Task.new("finalize",comp_size,comm_size); simgrid.Task.send(finalize,alias) end simgrid.info("Master: Everything's done."); end --end_of_master
-- Slave Function --------------------------------------------------------- function Slave(...) local my_mailbox="slave "..arg[1] simgrid.info("Hello from lua, I'm a poor slave with mbox: "..my_mailbox) while true do local tk = simgrid.Task.recv(my_mailbox); if (simgrid.Task.name(tk) == "finalize") then simgrid.info("Slave '" ..my_mailbox.."' got finalize msg"); break end --local tk_name = simgrid.Task.name(tk) simgrid.info("Slave '" ..my_mailbox.."' processing "..simgrid.Task.name(tk)) simgrid.Task.execute(tk) simgrid.info("Slave '" ..my_mailbox.."': task "..simgrid.Task.name(tk) .. " done") end -- while simgrid.info("Slave '" ..my_mailbox.."': I'm Done . See You !!"); end -- end_of_slave
dofile 'master.lua' dofile 'slave.lua' -- Simulation Code ---------------------------------------------------------- require "simgrid" if (#arg == 2) then simgrid.platform(arg[1]) simgrid.application(arg[2]) else simgrid.platform("../../msg/small_platform.xml") simgrid.application("../deploy.xml") end simgrid.run() simgrid.info("Simulation's over.See you.") simgrid.clean()
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.
task = simgrid.Task.new("data_task",task_comp,task_comm); task['matrix'] = my_matrix; task['table'] = my_table; task['message'] = "Hello from (Lua || Simgrid ) !! " … simgrid.Task.send(task,alias)
task = simgrid.Task.recv(alias); sender_matrix = task['matrix']; sender_table = task['table']; sender_message = task['message'] ...
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 ;) )
simgrid.AS.new{id="AS0",mode="Full"};
simgrid.Host.new{id="Tremblay",power=98095000}; simgrid.Host.new{id="Jupiter",power=76296000}; simgrid.Host.new{id="Fafard",power=76296000}; simgrid.Host.new{id="Ginette",power=48492000}; simgrid.Host.new{id="Bourassa",power=48492000};
for i=0,11 do simgrid.Link.new{id=i,bandwidth=252750+ i*768,latency=0.000270544+i*0.087}; -- some crazy values ;) end
-- simgrid.Route.new(src_id,des_id,links_nb,links_list) simgrid.Route.new("Tremblay","Jupiter",1,{"1"}); simgrid.Route.new("Tremblay","Fafard",6,{"0","1","2","3","4","8"}); simgrid.Route.new("Tremblay","Ginette",3,{"3","4","5"}); simgrid.Route.new("Tremblay","Bourassa",7,{"0","1","3","2","4","6","7"}); simgrid.Route.new("Jupiter","Tremblay",1,{"1"}); simgrid.Route.new("Jupiter","Fafard",7,{"0","1","2","3","4","8","9"}); simgrid.Route.new("Jupiter","Ginette",4,{"3","4","5","9"}); simgrid.Route.new("Jupiter","Bourassa",8,{"0","1","2","3","4","6","7","9"}); ...
simgrid.register_platform();
simgrid.Host.setFunction("Tremblay","Master",4,{"20","550000000","1000000","4"}); simgrid.Host.setFunction("Bourassa","Slave",1,{"0"}); simgrid.Host.setFunction("Jupiter","Slave",1,{"1"}); simgrid.Host.setFunction("Fafard","Slave",1,{"2"}); simgrid.Host.setFunction("Ginette","Slave",1,{"3"});
simgrid.register_application();
the full example is distributed in the file examples/lua/master_slave_bypass.lua
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
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.
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.
require 'simgrid' include MSG
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 MSG::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]) # Creates and sends the tasks for i in 0..numberOfTask-1 task = Task.new("Task_"+ i.to_s, taskComputeSize , taskCommunicationSize); mailbox = "slave " + (i%slaveCount).to_s MSG::info("Master Sending "+ task.name + " to " + mailbox + " with Comput Size " + task.compSize.to_s) task.send(mailbox) MSG::info("Master Done Sending " + task.name + " to " + mailbox) end # 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 finalize_task = Task.new("finalize",0,0) finalize_task.send(mailbox) end MSG::info("Master : Everything's Done") end end
the class MSG::Task contains methods that allows the management of the native MSG tasks. in master ruby code we used :
class Slave < MSG::Process def main(args) mailbox = "slave " + args[0] for i in 0..args.size-1 MSG::debug("args["+String(i)+"]="+args[i]) end while true MSG::info("Slave '"+ mailbox +"' waiting for new task"); task = Task.receive(mailbox) if (task.name == "finalize") break end task.execute MSG::info("Slave '" + mailbox + "' done executing task "+ task.name + ".") end MSG::info("I'm done, see you") end end \enverbatim to receive a task, we use the method <i>MSG::Task.receive(mailbox)</i> that return a MSG:Task object (received task). \li Main chunk \verbatim require 'simgrid' include MSG (...) if (ARGV.length == 2) MSG.createEnvironment(ARGV[0]) MSG.deployApplication(ARGV[1]) else MSG.createEnvironment("platform.xml") MSG.deployApplication("deploy.xml") end MSG.run puts "Simulation time : " + MSG.getClock.to_s MSG.exit
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
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
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
![]() |