Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Remove useless include that makes projects outside of Simgrid uncompilable.
[simgrid.git] / teshsuite / simdag / availability / availability_test.c
1 /* Copyright (c) 2013-2015. The SimGrid Team.
2  * All rights reserved.                                                     */
3
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. */
6
7 #include <string.h>
8 #include <simgrid/simdag.h>
9 #include <xbt/log.h>
10
11 XBT_LOG_NEW_DEFAULT_CATEGORY(test,"Logging for the current example");
12
13 static int name_compare_hosts(const void *n1, const void *n2)
14 {
15   return strcmp(sg_host_get_name(*(sg_host_t *) n1), sg_host_get_name(*(sg_host_t *) n2));
16 }
17
18 static void scheduleDAX(xbt_dynar_t dax)
19 {
20   unsigned int cursor;
21   SD_task_t task;
22
23   const sg_host_t *ws_list = sg_host_list();
24   int totalHosts = sg_host_count();
25   qsort((void *) ws_list, totalHosts, sizeof(sg_host_t), name_compare_hosts);
26
27   xbt_dynar_foreach(dax, cursor, task) {
28     if (SD_task_get_kind(task) == SD_TASK_COMP_SEQ) {
29       if (!strcmp(SD_task_get_name(task), "end") || !strcmp(SD_task_get_name(task), "root")) {
30         XBT_INFO("Scheduling %s to node: %s", SD_task_get_name(task), sg_host_get_name(ws_list[0]));
31         SD_task_schedulel(task, 1, ws_list[0]);
32       } else {
33         XBT_INFO("Scheduling %s to node: %s", SD_task_get_name(task), sg_host_get_name(ws_list[(cursor) % totalHosts]));
34         SD_task_schedulel(task, 1, ws_list[(cursor) % totalHosts]);
35       }
36     }
37   }
38 }
39
40 int main(int argc, char *argv[])
41 {
42   SD_init(&argc, argv);
43   xbt_assert(argc > 2, "Usage: %s platform_file dax_file\n"
44              "\tExample: %s simulacrum_7_hosts.xml Montage_25.xml", argv[0], argv[0]);
45
46   SD_create_environment(argv[1]);
47   xbt_dynar_t dax = SD_daxload(argv[2]);
48
49   XBT_INFO("Scheduling DAX...");
50   scheduleDAX(dax);
51   XBT_INFO("DAX scheduled");
52   SD_simulate(-1);
53   XBT_INFO("Simulation done.");
54
55   // Free memory
56   while (!xbt_dynar_is_empty(dax)) {
57     SD_task_t task = xbt_dynar_pop_as(dax, SD_task_t);
58     SD_task_destroy(task);
59   }
60   xbt_dynar_free(&dax);
61   SD_exit();
62   return 0;
63 }