1 /* Copyright (c) 2006-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. */
7 #include "simgrid/simdag.h"
11 XBT_LOG_NEW_DEFAULT_CATEGORY(sd_test, "Logging specific to this SimDag example");
13 int main(int argc, char **argv)
17 const sg_host_t *hosts;
18 const char *name1, *name2;
19 double comp_amount1, comp_amount2;
20 double comm_amount12, comm_amount21;
21 const SD_link_t *route;
23 SD_task_t task, taskA, taskB, taskC, taskD, checkB, checkD;
24 xbt_dynar_t changed_tasks;
26 const int host_count = 2;
27 sg_host_t host_list[2];
28 double computation_amount[2];
29 double communication_amount[4] = { 0 };
33 /* initialization of SD */
36 xbt_assert(argc > 1, "Usage: %s platform_file\n\nExample: %s two_clusters.xml", argv[0], argv[0]);
37 SD_create_environment(argv[1]);
39 /* test the estimation functions */
40 hosts = sg_host_list();
43 name1 = sg_host_get_name(h1);
44 name2 = sg_host_get_name(h2);
45 comp_amount1 = 2000000;
46 comp_amount2 = 1000000;
47 comm_amount12 = 2000000;
48 comm_amount21 = 3000000;
49 XBT_INFO("Computation time for %f flops on %s: %f", comp_amount1, name1, comp_amount1/sg_host_speed(h1));
50 XBT_INFO("Computation time for %f flops on %s: %f", comp_amount2, name2, comp_amount2/sg_host_speed(h2));
52 XBT_INFO("Route between %s and %s:", name1, name2);
53 route = SD_route_get_list(h1, h2);
54 route_size = SD_route_get_size(h1, h2);
55 for (i = 0; i < route_size; i++) {
56 XBT_INFO(" Link %s: latency = %f, bandwidth = %f", sg_link_name(route[i]), sg_link_latency(route[i]),
57 sg_link_bandwidth(route[i]));
59 XBT_INFO("Route latency = %f, route bandwidth = %f", SD_route_get_latency(h1, h2), SD_route_get_bandwidth(h1, h2));
60 XBT_INFO("Communication time for %f bytes between %s and %s: %f", comm_amount12, name1, name2,
61 SD_route_get_latency(h1, h2) + comm_amount12 / SD_route_get_bandwidth(h1, h2));
62 XBT_INFO("Communication time for %f bytes between %s and %s: %f", comm_amount21, name2, name1,
63 SD_route_get_latency(h2, h1) + comm_amount21 / SD_route_get_bandwidth(h2, h1));
65 /* creation of the tasks and their dependencies */
66 taskA = SD_task_create("Task A", NULL, 10.0);
67 taskB = SD_task_create("Task B", NULL, 40.0);
68 taskC = SD_task_create("Task C", NULL, 30.0);
69 taskD = SD_task_create("Task D", NULL, 60.0);
71 /* try to attach and retrieve user data to a task */
72 SD_task_set_data(taskA, (void*) &comp_amount1);
73 if (comp_amount1 != (*((double*) SD_task_get_data(taskA))))
74 XBT_ERROR("User data was corrupted by a simple set/get");
76 SD_task_dependency_add(NULL, NULL, taskB, taskA);
77 SD_task_dependency_add(NULL, NULL, taskC, taskA);
78 SD_task_dependency_add(NULL, NULL, taskD, taskB);
79 SD_task_dependency_add(NULL, NULL, taskD, taskC);
80 SD_task_dependency_add(NULL, NULL, taskB, taskC);
83 SD_task_dependency_add(NULL, NULL, taskA, taskA); /* shouldn't work and must raise an exception */
84 xbt_die("Hey, I can add a dependency between Task A and Task A!");
87 if (ex.category != arg_error)
88 RETHROW; /* this is a serious error */
93 SD_task_dependency_add(NULL, NULL, taskB, taskA); /* shouldn't work and must raise an exception */
94 xbt_die("Oh oh, I can add an already existing dependency!");
97 if (ex.category != arg_error)
103 SD_task_dependency_remove(taskA, taskC); /* shouldn't work and must raise an exception */
104 xbt_die("Dude, I can remove an unknown dependency!");
107 if (ex.category != arg_error)
113 SD_task_dependency_remove(taskC, taskC); /* shouldn't work and must raise an exception */
114 xbt_die("Wow, I can remove a dependency between Task C and itself!");
117 if (ex.category != arg_error)
122 /* if everything is ok, no exception is forwarded or rethrown by main() */
125 SD_task_watch(taskD, SD_DONE);
126 SD_task_watch(taskB, SD_DONE);
127 SD_task_unwatch(taskD, SD_DONE);
129 /* scheduling parameters */
132 computation_amount[0] = comp_amount1;
133 computation_amount[1] = comp_amount2;
135 communication_amount[1] = comm_amount12;
136 communication_amount[2] = comm_amount21;
140 XBT_INFO("Estimated time for '%s': %f", SD_task_get_name(task), SD_task_get_execution_time(task, host_count,
141 host_list, computation_amount, communication_amount));
143 SD_task_schedule(taskA, host_count, host_list, computation_amount, communication_amount, rate);
144 SD_task_schedule(taskB, host_count, host_list, computation_amount, communication_amount, rate);
145 SD_task_schedule(taskC, host_count, host_list, computation_amount, communication_amount, rate);
146 SD_task_schedule(taskD, host_count, host_list, computation_amount, communication_amount, rate);
148 changed_tasks = SD_simulate(-1.0);
149 xbt_dynar_foreach(changed_tasks, ctr, task) {
150 XBT_INFO("Task '%s' start time: %f, finish time: %f", SD_task_get_name(task),
151 SD_task_get_start_time(task), SD_task_get_finish_time(task));
154 xbt_dynar_get_cpy(changed_tasks, 0, &checkD);
155 xbt_dynar_get_cpy(changed_tasks, 1, &checkB);
157 xbt_assert(checkD == taskD && checkB == taskB, "Unexpected simulation results");
159 XBT_DEBUG("Destroying tasks...");
160 SD_task_destroy(taskA);
161 SD_task_destroy(taskB);
162 SD_task_destroy(taskC);
163 SD_task_destroy(taskD);
165 XBT_DEBUG("Tasks destroyed. Exiting SimDag...");