1 #include "rb_SD_task.h"
4 static void SD_task_free(SD_task_t tk) {
5 // SD_task_destroy(tk);
8 static void rb_SD_task_destroy(VALUE class,VALUE task)
11 Data_Get_Struct(task, SD_task_t, tk);
15 static VALUE rb_SD_task_new(VALUE class, VALUE name,VALUE amount)
18 SD_task_t task = SD_task_create(RSTRING(name)->ptr,NULL,NUM2DBL(amount));
19 // Wrap m_task_t to a Ruby Value
20 return Data_Wrap_Struct(class, 0, SD_task_free, task);
25 static VALUE rb_SD_task_name(VALUE class,VALUE task)
27 // Wrap Ruby Value to m_task_t struct
29 Data_Get_Struct(task, SD_task_t, tk);
30 return rb_str_new2(SD_task_get_name(tk));
35 static void rb_SD_task_schedule(VALUE class,VALUE task,VALUE workstation_nb,VALUE workstation_list,VALUE computation_amount,VALUE communication_amount,VALUE rate)
37 // Wrap Ruby Value to m_task_t struct
38 int i,wrk_nb,comp_nb,comm_nb;
39 double *comp_amount,*comm_amount;
41 VALUE *ptr_wrk,*ptr_comp,*ptr_comm;
43 Data_Get_Struct(task, SD_task_t, tk);
44 wrk_nb = NUM2INT(workstation_nb);
45 comp_nb = RARRAY(computation_amount)->len;
46 comm_nb = RARRAY(communication_amount)->len;
48 SD_workstation_t *wrk_list;
50 ptr_wrk = RARRAY(workstation_list)->ptr;
51 ptr_comp = RARRAY(computation_amount)->ptr;
52 ptr_comm = RARRAY(communication_amount)->ptr;
54 wrk_list = xbt_new0(SD_workstation_t,wrk_nb);
55 comp_amount = xbt_new0(double,wrk_nb);//malloc(sizeof(double)*wrk_nb); //xbt_new0(double,wrk_nb);
56 comm_amount = xbt_new0(double,wrk_nb);//malloc(sizeof(double)*wrk_nb); //xbt_new0(double,wrk_nb);
58 // wrk_nb == comp_nb == comm_nb ???
59 for (i=0;i<wrk_nb;i++)
61 Data_Get_Struct(ptr_wrk[i],SD_workstation_t,wrk_list[i]);
62 comp_amount[i] = NUM2DBL(ptr_comp[i]);
63 comm_amount[i] = NUM2DBL(ptr_comm[i]);
65 /*for (i=0;i<comp_nb;i++)
66 comp_amount[i] = NUM2DBL(ptr_comp[i]);
68 for (i=0;i<comm_nb;i++)
69 comm_amount[i] = NUM2DBL(ptr_comm[i]);*/
72 SD_task_schedule(tk,wrk_nb,wrk_list,comp_amount,comm_amount,rt);
76 // FIXME, used later if wanna calculate start & fininsh time for a task
84 static void rb_SD_task_unschedule(VALUE class,VALUE task)
87 Data_Get_Struct(task,SD_task_t,tk);
88 SD_task_unschedule (tk);
92 // task dependency add
93 static void rb_SD_task_add_dependency(VALUE Class,VALUE task_src,VALUE task_dst)
95 SD_task_t tk_src,tk_dst;
96 Data_Get_Struct(task_src, SD_task_t ,tk_src);
97 Data_Get_Struct(task_dst, SD_task_t ,tk_dst);
98 SD_task_dependency_add(NULL,NULL,tk_src,tk_dst);
102 //task execution time
103 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)
107 double *comp_amount,*comm_amount;
109 VALUE *ptr_wrk,*ptr_comp,*ptr_comm;
111 Data_Get_Struct(task, SD_task_t, tk);
112 wrk_nb = NUM2INT(workstation_nb);
114 SD_workstation_t *wrk_list;
116 ptr_wrk = RARRAY(workstation_list)->ptr;
117 ptr_comp = RARRAY(computation_amount)->ptr;
118 ptr_comm = RARRAY(communication_amount)->ptr;
120 wrk_list = xbt_new0(SD_workstation_t,wrk_nb);
121 comp_amount = xbt_new0(double,wrk_nb);
122 comm_amount = xbt_new0(double,wrk_nb);
124 for (i=0;i<wrk_nb;i++)
126 Data_Get_Struct(ptr_wrk[i],SD_workstation_t,wrk_list[i]);
127 comp_amount[i] = NUM2DBL(ptr_comp[i]);
128 comm_amount[i] = NUM2DBL(ptr_comm[i]);
131 return rb_float_new(SD_task_get_execution_time (tk,wrk_nb,wrk_list,comp_amount,comm_amount,rt));
136 static VALUE rb_SD_task_start_time(VALUE class,VALUE task)
140 Data_Get_Struct(task,SD_task_t,tk);
141 double time=SD_task_get_start_time(tk);
142 return rb_float_new(time);
147 static VALUE rb_SD_task_finish_time(VALUE class,VALUE task)
150 Data_Get_Struct(task,SD_task_t,tk);
151 double time=SD_task_get_finish_time(tk);
152 return rb_float_new(time);
156 // Simulate : return a SD_task
157 static VALUE rb_SD_simulate(VALUE class,VALUE how_long)
160 double hl = NUM2DBL(how_long);
161 SD_task_t * tasks = SD_simulate(hl);
162 VALUE rb_tasks = rb_ary_new();
163 for (i = 0; tasks[i] != NULL; i++)
166 tk = Data_Wrap_Struct(class, 0, SD_task_free, tasks[i]);
167 rb_ary_push(rb_tasks,tk);