1 /* Copyright (c) 2013-2015. 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. */
12 #include <simgrid/simdag.h>
24 static void usage(char *name)
26 fprintf(stdout, "Error on parameters.\n");
27 fprintf(stdout, "usage: %s <XML environment file> <DAX file>\n", name);
30 static void checkParameters(int argc, char *argv[])
34 printf("====%d===\n",argc);
35 for(i=0; i<argc; i++) {
36 printf("\t%s\n",argv[i]);
42 /* Check that files exist */
44 if ((xmlFiles.envFile = fopen(argv[1], "r")) == NULL) {
45 fprintf(stderr, "Error while opening XML file %s.\n", argv[1]);
48 fclose(xmlFiles.envFile);
50 if ((xmlFiles.daxFile = fopen(argv[2], "r")) == NULL) {
51 fprintf(stderr, "Error while opening DAX file %s.\n", argv[2]);
54 fclose(xmlFiles.daxFile);
57 static int name_compare_hosts(const void *n1, const void *n2)
59 char name1[80], name2[80];
60 strcpy(name1, sg_host_get_name(*((sg_host_t *) n1)));
61 strcpy(name2, sg_host_get_name(*((sg_host_t *) n2)));
63 return strcmp(name1, name2);
66 static void scheduleDAX(xbt_dynar_t dax)
71 const sg_host_t *ws_list = sg_host_list();
72 int totalHosts = sg_host_count();
73 qsort((void *) ws_list, totalHosts, sizeof(sg_host_t),
76 //fprintf(stdout, "No. workstations: %d, %d\n", totalHosts, (dax != NULL));
78 xbt_dynar_foreach(dax, cursor, task) {
79 if (SD_task_get_kind(task) == SD_TASK_COMP_SEQ) {
80 if (!strcmp(SD_task_get_name(task), "end")
81 || !strcmp(SD_task_get_name(task), "root")) {
82 fprintf(stdout, "Scheduling %s to node: %s\n", SD_task_get_name(task),
83 sg_host_get_name(ws_list[0]));
84 SD_task_schedulel(task, 1, ws_list[0]);
86 fprintf(stdout, "Scheduling %s to node: %s\n", SD_task_get_name(task),
87 sg_host_get_name(ws_list[(cursor) % totalHosts]));
88 SD_task_schedulel(task, 1, ws_list[(cursor) % totalHosts]);
94 /* static void printTasks(xbt_dynar_t completedTasks) */
96 /* unsigned int cursor; */
99 /* xbt_dynar_foreach(completedTasks, cursor, task) */
101 /* if(SD_task_get_state(task) == SD_DONE) */
103 /* fprintf(stdout, "Task done: %s, %f, %f\n", */
104 /* SD_task_get_name(task), SD_task_get_start_time(task), SD_task_get_finish_time(task)); */
110 /* void createDottyFile(xbt_dynar_t dax, char *filename) */
112 /* char filename2[1000]; */
113 /* unsigned int cursor; */
114 /* SD_task_t task; */
116 /* sprintf(filename2, "%s.dot", filename); */
117 /* FILE *dotout = fopen(filename2, "w"); */
118 /* fprintf(dotout, "digraph A {\n"); */
119 /* xbt_dynar_foreach(dax, cursor, task) */
121 /* SD_task_dotty(task, dotout); */
123 /* fprintf(dotout, "}\n"); */
124 /* fclose(dotout); */
127 static xbt_dynar_t initDynamicThrottling(int *argc, char *argv[])
132 /* Check parameters */
133 checkParameters(*argc,argv);
135 /* Create environment */
136 SD_create_environment(argv[1]);
138 xbt_dynar_t dax = SD_daxload(argv[2]);
140 // createDottyFile(dax, argv[2]);
143 fprintf(stdout, "Scheduling DAX...\n");
145 fprintf(stdout, "DAX scheduled\n");
147 fprintf(stdout, "Simulation end. Time: %f\n", SD_get_clock());
153 * Garbage collector :D
155 static void garbageCollector(xbt_dynar_t dax)
157 while (!xbt_dynar_is_empty(dax)) {
158 SD_task_t task = xbt_dynar_pop_as(dax, SD_task_t);
159 SD_task_destroy(task);
161 xbt_dynar_free(&dax);
173 int main(int argc, char *argv[])
176 /* Start process... */
177 xbt_dynar_t dax = initDynamicThrottling(&argc, argv);
180 garbageCollector(dax);