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 "rb_SD_task.h"
10 static void SD_task_free(SD_task_t tk) {
11 // SD_task_destroy(tk);
14 static void rb_SD_task_destroy(VALUE class,VALUE task)
17 Data_Get_Struct(task, SD_task_t, tk);
21 static VALUE rb_SD_task_new(VALUE class, VALUE name,VALUE amount)
24 SD_task_t task = SD_task_create(RSTRING(name)->ptr,NULL,NUM2DBL(amount));
25 // Wrap m_task_t to a Ruby Value
26 return Data_Wrap_Struct(class, 0, SD_task_free, task);
31 static VALUE rb_SD_task_name(VALUE class,VALUE task)
33 // Wrap Ruby Value to m_task_t struct
35 Data_Get_Struct(task, SD_task_t, tk);
36 return rb_str_new2(SD_task_get_name(tk));
41 static void rb_SD_task_schedule(VALUE class,VALUE task,VALUE workstation_nb,VALUE workstation_list,VALUE computation_amount,VALUE communication_amount,VALUE rate)
43 // Wrap Ruby Value to m_task_t struct
44 int i,wrk_nb,comp_nb,comm_nb;
45 double *comp_amount,*comm_amount;
47 VALUE *ptr_wrk,*ptr_comp,*ptr_comm;
49 Data_Get_Struct(task, SD_task_t, tk);
50 wrk_nb = NUM2INT(workstation_nb);
51 comp_nb = RARRAY(computation_amount)->len;
52 comm_nb = RARRAY(communication_amount)->len;
54 SD_workstation_t *wrk_list;
56 ptr_wrk = RARRAY(workstation_list)->ptr;
57 ptr_comp = RARRAY(computation_amount)->ptr;
58 ptr_comm = RARRAY(communication_amount)->ptr;
60 wrk_list = xbt_new0(SD_workstation_t,wrk_nb);
61 comp_amount = xbt_new0(double,wrk_nb);
62 comm_amount = xbt_new0(double,wrk_nb);
64 // wrk_nb == comp_nb == comm_nb ???
65 for (i=0;i<wrk_nb;i++)
67 Data_Get_Struct(ptr_wrk[i],SD_workstation_t,wrk_list[i]);
68 comp_amount[i] = NUM2DBL(ptr_comp[i]);
69 comm_amount[i] = NUM2DBL(ptr_comm[i]);
71 /*for (i=0;i<comp_nb;i++)
72 comp_amount[i] = NUM2DBL(ptr_comp[i]);
74 for (i=0;i<comm_nb;i++)
75 comm_amount[i] = NUM2DBL(ptr_comm[i]);*/
77 SD_task_schedule(tk,wrk_nb,wrk_list,comp_amount,comm_amount,rt);
80 xbt_free(comp_amount);
81 xbt_free(comm_amount);
87 static void rb_SD_task_unschedule(VALUE class,VALUE task)
90 Data_Get_Struct(task,SD_task_t,tk);
91 SD_task_unschedule (tk);
95 // task dependency add
96 static void rb_SD_task_add_dependency(VALUE Class,VALUE task_src,VALUE task_dst)
98 SD_task_t tk_src,tk_dst;
99 Data_Get_Struct(task_src, SD_task_t ,tk_src);
100 Data_Get_Struct(task_dst, SD_task_t ,tk_dst);
101 SD_task_dependency_add(NULL,NULL,tk_src,tk_dst);
105 //task execution time
106 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)
110 double *comp_amount,*comm_amount;
112 VALUE *ptr_wrk,*ptr_comp,*ptr_comm;
114 Data_Get_Struct(task, SD_task_t, tk);
115 wrk_nb = NUM2INT(workstation_nb);
117 SD_workstation_t *wrk_list;
119 ptr_wrk = RARRAY(workstation_list)->ptr;
120 ptr_comp = RARRAY(computation_amount)->ptr;
121 ptr_comm = RARRAY(communication_amount)->ptr;
123 wrk_list = xbt_new0(SD_workstation_t,wrk_nb);
124 comp_amount = xbt_new0(double,wrk_nb);
125 comm_amount = xbt_new0(double,wrk_nb);
127 for (i=0;i<wrk_nb;i++)
129 Data_Get_Struct(ptr_wrk[i],SD_workstation_t,wrk_list[i]);
130 comp_amount[i] = NUM2DBL(ptr_comp[i]);
131 comm_amount[i] = NUM2DBL(ptr_comm[i]);
134 return rb_float_new(SD_task_get_execution_time (tk,wrk_nb,wrk_list,comp_amount,comm_amount,rt));
139 static VALUE rb_SD_task_start_time(VALUE class,VALUE task)
143 Data_Get_Struct(task,SD_task_t,tk);
144 double time=SD_task_get_start_time(tk);
145 return rb_float_new(time);
150 static VALUE rb_SD_task_finish_time(VALUE class,VALUE task)
153 Data_Get_Struct(task,SD_task_t,tk);
154 double time=SD_task_get_finish_time(tk);
155 return rb_float_new(time);
159 // Simulate : return a SD_task
160 static VALUE rb_SD_simulate(VALUE class,VALUE how_long)
163 double hl = NUM2DBL(how_long);
164 SD_task_t * tasks = SD_simulate(hl);
165 VALUE rb_tasks = rb_ary_new();
166 for (i = 0; tasks[i] != NULL; i++)
169 tk = Data_Wrap_Struct(class, 0, SD_task_free, tasks[i]);
170 rb_ary_push(rb_tasks,tk);