Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
c3993a084281aedf908d57b7f4322a58a57a311f
[simgrid.git] / src / bindings / rubyDag / example.rb
1 require 'simdag'
2 include DAG
3
4 # Still using the old method to run :
5 #>> make     ( to generate dag.so)
6 #>> ruby example.rb   ( to run )
7 # FIXME if using valgrind , you will get Some 'Invalid Read of Size" When Calling rb_task_schedule  '
8
9
10 class Example
11
12   def initialize()
13     DAG.init(ARGV)
14     
15     if (ARGV.length == 1)
16       DAG.init(ARGV[0])
17     else 
18       DAG.createEnvironment("platform.xml")
19     end
20    
21     taskA = DAG::Task.new("Tache A",10)
22     taskB = DAG::Task.new("Tache B",40)
23     taskC = DAG::Task.new("Tache C",30)
24     taskD = DAG::Task.new("Tache D",60)
25     
26 #     Adding dependency
27     DAG::Task::addDependency(taskB,taskA)
28     DAG::Task::addDependency(taskC,taskA)
29     DAG::Task::addDependency(taskD,taskB)
30     DAG::Task::addDependency(taskD,taskC)
31
32 #      Execution Params
33     
34     workstation_number = 2
35     workstation_list = DAG::Workstation.getList()
36     w1 = workstation_list[0]
37     w2 = workstation_list[1]
38     
39      p "workstation 1 : "+ w1.name
40      p "workstation 2 : "+ w2.name
41     
42     computation_amount = Array.new()
43     communication_amount = Array.new()
44     
45     computation_amount << 2000000 << 1000000
46     communication_amount << 200000 << 300000
47     
48     rate = -1
49     
50 #     Scheduling
51     
52     DAG::Task.schedule(taskA,workstation_number,workstation_list,computation_amount,communication_amount,rate)
53     DAG::Task.schedule(taskB,workstation_number,workstation_list,computation_amount,communication_amount,rate)
54     DAG::Task.schedule(taskC,workstation_number,workstation_list,computation_amount,communication_amount,rate)
55     DAG::Task.schedule(taskD,workstation_number,workstation_list,computation_amount,communication_amount,rate)
56    
57     changed_tasks = Array.new()
58     changed_tasks = DAG::Task.simulate(-1.0)
59
60     for i in 0..changed_tasks.size-1
61       puts "Task "+ changed_tasks[i].name + " Started at " + changed_tasks[i].startTime.to_s + " has been done at "+ changed_tasks[i].finishTime.to_s
62       
63     end
64         
65     puts "Everything's Done ... Bye!!"
66
67     end
68 end
69
70 expl = Example.new