1 /* Copyright (c) 2010. The SimGrid Team.
2 * All rights reserved. */
4 /* This program is free software; you can redistribute it and/or modify it
5 * under the terms of the license (GNU LGPL) which comes with this package. */
7 //#include "ruby_simdag.h"
8 #include "rb_SD_task.h"
11 static void SD_task_free(SD_task_t tk) {
12 // SD_task_destroy(tk);
15 static void rb_SD_task_destroy(VALUE class,VALUE task)
18 Data_Get_Struct(task, SD_task_t, tk);
22 static VALUE rb_SD_task_new(VALUE class, VALUE name,VALUE amount)
25 SD_task_t task = SD_task_create(RSTRING(name)->ptr,NULL,NUM2DBL(amount));
26 // Wrap m_task_t to a Ruby Value
27 return Data_Wrap_Struct(class, 0, SD_task_free, task);
32 static VALUE rb_SD_task_name(VALUE class,VALUE task)
34 // Wrap Ruby Value to m_task_t struct
36 Data_Get_Struct(task, SD_task_t, tk);
37 return rb_str_new2(SD_task_get_name(tk));
42 static void rb_SD_task_schedule(VALUE class,VALUE task,VALUE workstation_nb,VALUE workstation_list,VALUE computation_amount,VALUE communication_amount,VALUE rate)
44 // Wrap Ruby Value to m_task_t struct
45 int i,wrk_nb,comp_nb,comm_nb;
46 double *comp_amount,*comm_amount;
48 VALUE *ptr_wrk,*ptr_comp,*ptr_comm;
50 Data_Get_Struct(task, SD_task_t, tk);
51 wrk_nb = NUM2INT(workstation_nb);
52 comp_nb = RARRAY(computation_amount)->len;
53 comm_nb = RARRAY(communication_amount)->len;
55 SD_workstation_t *wrk_list;
57 ptr_wrk = RARRAY(workstation_list)->ptr;
58 ptr_comp = RARRAY(computation_amount)->ptr;
59 ptr_comm = RARRAY(communication_amount)->ptr;
61 wrk_list = xbt_new0(SD_workstation_t,wrk_nb);
62 comp_amount = xbt_new0(double,wrk_nb);
63 comm_amount = xbt_new0(double,wrk_nb);
65 // wrk_nb == comp_nb == comm_nb ???
66 for (i=0;i<wrk_nb;i++)
68 Data_Get_Struct(ptr_wrk[i],SD_workstation_t,wrk_list[i]);
69 comp_amount[i] = NUM2DBL(ptr_comp[i]);
70 comm_amount[i] = NUM2DBL(ptr_comm[i]);
72 /*for (i=0;i<comp_nb;i++)
73 comp_amount[i] = NUM2DBL(ptr_comp[i]);
75 for (i=0;i<comm_nb;i++)
76 comm_amount[i] = NUM2DBL(ptr_comm[i]);*/
78 SD_task_schedule(tk,wrk_nb,wrk_list,comp_amount,comm_amount,rt);
81 xbt_free(comp_amount);
82 xbt_free(comm_amount);
88 static void rb_SD_task_unschedule(VALUE class,VALUE task)
91 Data_Get_Struct(task,SD_task_t,tk);
92 SD_task_unschedule (tk);
96 // task dependency add
97 static void rb_SD_task_add_dependency(VALUE Class,VALUE task_src,VALUE task_dst)
99 SD_task_t tk_src,tk_dst;
100 Data_Get_Struct(task_src, SD_task_t ,tk_src);
101 Data_Get_Struct(task_dst, SD_task_t ,tk_dst);
102 SD_task_dependency_add(NULL,NULL,tk_src,tk_dst);
106 //task execution time
107 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)
111 double *comp_amount,*comm_amount;
113 VALUE *ptr_wrk,*ptr_comp,*ptr_comm;
115 Data_Get_Struct(task, SD_task_t, tk);
116 wrk_nb = NUM2INT(workstation_nb);
118 SD_workstation_t *wrk_list;
120 ptr_wrk = RARRAY(workstation_list)->ptr;
121 ptr_comp = RARRAY(computation_amount)->ptr;
122 ptr_comm = RARRAY(communication_amount)->ptr;
124 wrk_list = xbt_new0(SD_workstation_t,wrk_nb);
125 comp_amount = xbt_new0(double,wrk_nb);
126 comm_amount = xbt_new0(double,wrk_nb);
128 for (i=0;i<wrk_nb;i++)
130 Data_Get_Struct(ptr_wrk[i],SD_workstation_t,wrk_list[i]);
131 comp_amount[i] = NUM2DBL(ptr_comp[i]);
132 comm_amount[i] = NUM2DBL(ptr_comm[i]);
135 return rb_float_new(SD_task_get_execution_time (tk,wrk_nb,wrk_list,comp_amount,comm_amount,rt));
140 static VALUE rb_SD_task_start_time(VALUE class,VALUE task)
144 Data_Get_Struct(task,SD_task_t,tk);
145 double time=SD_task_get_start_time(tk);
146 return rb_float_new(time);
151 static VALUE rb_SD_task_finish_time(VALUE class,VALUE task)
154 Data_Get_Struct(task,SD_task_t,tk);
155 double time=SD_task_get_finish_time(tk);
156 return rb_float_new(time);
160 // Simulate : return a SD_task
161 static VALUE rb_SD_simulate(VALUE class,VALUE how_long)
165 double hl = NUM2DBL(how_long);
166 xbt_dynar_t simulated_tasks = SD_simulate(hl) ;
168 VALUE rb_tasks = rb_ary_new();
169 xbt_dynar_foreach(simulated_tasks, i, task){
171 tk = Data_Wrap_Struct(class, 0, SD_task_free, task);
172 rb_ary_push(rb_tasks,tk);