Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
18d8d66039c4050d916b872f125ab4f6a6f3d818
[simgrid.git] / examples / simdag / mixtesim / src / list_scheduling_util.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4
5 #include "mixtesim_prototypes.h"
6 #include "list_scheduling.h"
7
8 #include "simdag/simdag.h"
9 #include "xbt/log.h"
10
11 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mixtesim_list_scheduling, mixtesim,
12                                 "Logging specific to Mixtesim (list scheduling)");
13
14 /*
15  * freeHostAttributes()
16  */
17 void freeHostAttributes()
18 {
19   int i;
20   int nb_hosts = SD_workstation_get_number();
21   const SD_workstation_t *hosts = SD_workstation_get_list();
22
23   for (i=0;i<nb_hosts;i++) {
24     free(SD_workstation_get_data(hosts[i]));
25     SD_workstation_set_data(hosts[i], NULL);
26   }
27   return;
28 }
29
30 /*
31  * allocateHostAttributes()
32  */
33 void allocateHostAttributes()
34 {
35   int i;
36   int nb_hosts = SD_workstation_get_number();
37   const SD_workstation_t *hosts = SD_workstation_get_list();
38   void *data;
39
40   for (i=0;i<nb_hosts;i++) {
41     data = calloc(1,sizeof(struct _HostAttribute));
42     SD_workstation_set_data(hosts[i], data);
43   }
44   return;
45 }
46
47 /*
48  * freeNodeAttributes()
49  */
50 void freeNodeAttributes(DAG dag)
51 {
52   int i;
53
54   for (i=0;i<dag->nb_nodes;i++) {
55     if (dag->nodes[i]->metadata)  {
56       free(dag->nodes[i]->metadata);
57     }
58   }
59   return;
60 }
61
62 /*
63  * allocateNodeAttributes()
64  */
65 void allocateNodeAttributes(DAG dag)
66 {
67   int i;
68
69   for (i=0;i<dag->nb_nodes;i++) {
70     dag->nodes[i]->metadata = 
71             (NodeAttribute)calloc(1,sizeof(struct _NodeAttribute));
72     if (dag->nodes[i]->type == NODE_COMPUTATION)
73       NODE_ATTR(dag->nodes[i])->state = LIST_SCHEDULING_NOT_SCHEDULED;
74   }
75   return;
76 }
77
78 /*
79  * implementSimgridSchedule()
80  */
81 void implementSimgridSchedule(DAG dag, Node *list)
82 {
83   int j,k;
84   Node node;
85   Node grand_parent;
86   SD_workstation_t grand_parent_host;
87   SD_workstation_t host;
88 /*   Link link; */
89 /*  SD_link_t *route;*/
90
91   const double no_cost[] = {0.0, 0.0};
92   const double small_cost = 1.0; /* doesn't work with 0.0 */
93   e_SD_task_state_t state;
94   SD_workstation_t host_list[] = {NULL, NULL};
95   double communication_amount[] = {0.0, 0.0,
96                                    0.0, 0.0};
97
98   /* Schedule Root */
99   if (SD_task_get_state(dag->root->sd_task) == SD_NOT_SCHEDULED) {
100     DEBUG1("Dag root cost = %f", dag->root->cost);
101     DEBUG1("Scheduling root task '%s'", SD_task_get_name(dag->root->sd_task));
102     SD_task_schedule(dag->root->sd_task, 1, SD_workstation_get_list(),
103                      &small_cost, no_cost, -1.0);
104     DEBUG2("Task '%s' state: %d", SD_task_get_name(dag->root->sd_task), SD_task_get_state(dag->root->sd_task));
105   }
106
107   /* Schedule the computation */
108   for (j=0;list[j];j++) {
109     node=list[j];
110
111     /* schedule the task */
112     DEBUG1("Scheduling computation task '%s'", SD_task_get_name(node->sd_task));
113     SD_task_schedule(node->sd_task, 1, &NODE_ATTR(node)->host,
114                      &node->cost, no_cost, -1.0);
115     DEBUG2("Task '%s' state: %d", SD_task_get_name(node->sd_task), SD_task_get_state(node->sd_task));
116
117     /* schedule the parent transfer */
118     for (k=0;k<node->nb_parents;k++) {
119       if (node->parents[k]->type == NODE_ROOT)
120         break;
121       /* no transfer */
122       if (node->parents[k]->type == NODE_COMPUTATION)
123         continue;
124       /* normal case */
125       if (node->parents[k]->type == NODE_TRANSFER) {
126         state = SD_task_get_state(node->parents[k]->sd_task);
127         if (state != SD_RUNNING && state != SD_DONE) {
128           grand_parent=node->parents[k]->parents[0];
129           grand_parent_host=NODE_ATTR(grand_parent)->host;
130           host=NODE_ATTR(node)->host;
131           
132           if (host != grand_parent_host) {
133             host_list[0] = grand_parent_host;
134             host_list[1] = host;
135             communication_amount[1] = node->parents[k]->cost;
136             DEBUG1("Scheduling transfer task '%s'",
137                    SD_task_get_name(node->parents[k]->sd_task));
138             SD_task_schedule(node->parents[k]->sd_task, 2, host_list,
139                              no_cost, communication_amount, -1.0);
140             DEBUG2("Task '%s' state: %d",
141                    SD_task_get_name(node->parents[k]->sd_task),
142                    SD_task_get_state(node->parents[k]->sd_task));
143           } else {
144             SD_task_schedule(node->parents[k]->sd_task, 1, host_list,
145                              no_cost, communication_amount, -1.0);
146 /*          SD_task_schedule(node->parents[k]->sd_task, 1, &host, */
147 /*                           no_cost, &(node->parents[k]->cost), -1.0); */
148           }
149 /*        host_list[0] = grand_parent_host; */
150 /*        host_list[1] = host; */
151 /*        communication_amount[1] = node->parents[k]->cost; */
152 /*        DEBUG1("Scheduling transfer task '%s'", SD_task_get_name(node->parents[k]->sd_task)); */
153 /*        SD_task_schedule(node->parents[k]->sd_task, 2, host_list, */
154 /*                         no_cost, communication_amount, -1.0); */
155 /*        DEBUG2("Task '%s' state: %d", SD_task_get_name(node->parents[k]->sd_task), */
156 /*               SD_task_get_state(node->parents[k]->sd_task)); */
157
158 /* /\*           if (!route) { *\/ */
159 /* /\*             if (SG_scheduleTaskOnResource(node->parents[k]->sg_task, *\/ */
160 /* /\*                                            local_link->sg_link) *\/ */
161 /* /\*          == -1) { *\/ */
162 /* /\*        fprintf(stderr,"Task '%s' already in state %d\n", *\/ */
163 /* /\*                node->parents[k]->sg_task->name, *\/ */
164 /* /\*                node->parents[k]->sg_task->state); *\/ */
165 /* /\*      } *\/ */
166 /* /\*    } else { *\/ */
167 /* /\*             if (SG_scheduleTaskOnResource(node->parents[k]->sg_task, *\/ */
168 /* /\*                                    route)  *\/ */
169 /* /\*          == -1) { *\/ */
170 /* /\*       fprintf(stderr,"Task '%s' already in state %d\n", *\/ */
171 /* /\*                node->parents[k]->sg_task->name, *\/ */
172 /* /\*                node->parents[k]->sg_task->state); *\/ */
173 /* /\*      }  *\/ */
174 /* /\*    } *\/ */
175         }
176       }
177     }
178   }
179
180   /* Schedule End */
181 /*   SG_scheduleTaskOnResource(dag->end->sg_task,local_link->sg_link); */
182   SD_task_schedule(dag->end->sd_task, 1, SD_workstation_get_list(),
183                    &small_cost, no_cost, -1.0);
184
185
186   return;
187 }
188
189