1 /* Copyright (c) 2006-2018. 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"
9 XBT_LOG_NEW_DEFAULT_CATEGORY(sd_comm_throttling, "Logging specific to this SimDag example");
11 int main(int argc, char **argv)
15 xbt_dynar_t changed_tasks = xbt_dynar_new(sizeof(SD_task_t), NULL);
18 xbt_assert(argc > 1, "Usage: %s platform_file\n\nExample: %s two_clusters.xml", argv[0], argv[0]);
20 SD_create_environment(argv[1]);
22 sg_host_t *hosts = sg_host_list();
24 /* creation of some typed tasks and their dependencies */
25 /* chain of five tasks, three compute tasks with two data transfers in between */
26 SD_task_t taskA = SD_task_create_comp_seq("Task A", NULL, 5e9);
27 SD_task_t taskB = SD_task_create_comm_e2e("Task B", NULL, 1e7);
28 SD_task_t taskC = SD_task_create_comp_seq("Task C", NULL, 5e9);
29 SD_task_t taskD = SD_task_create_comm_e2e("Task D", NULL, 1e7);
30 SD_task_t taskE = SD_task_create_comp_seq("Task E", NULL, 5e9);
32 SD_task_dependency_add(taskA, taskB);
33 SD_task_dependency_add(taskB, taskC);
34 SD_task_dependency_add(taskC, taskD);
35 SD_task_dependency_add(taskD, taskE);
37 /* Add watchpoints on completion of compute tasks */
38 SD_task_watch(taskA, SD_DONE);
39 SD_task_watch(taskC, SD_DONE);
40 SD_task_watch(taskE, SD_DONE);
42 /* Auto-schedule the compute tasks on three different workstations */
43 /* Data transfer tasks taskB and taskD are automagically scheduled */
44 SD_task_schedulel(taskA, 1, hosts[0]);
45 SD_task_schedulel(taskC, 1, hosts[1]);
46 SD_task_schedulel(taskE, 1, hosts[0]);
48 SD_simulate_with_update(-1.0, changed_tasks);
49 while (!xbt_dynar_is_empty(changed_tasks)) {
50 XBT_INFO("Simulation stopped after %.4f seconds", SD_get_clock());
51 xbt_dynar_foreach(changed_tasks, ctr, task) {
52 XBT_INFO("Task '%s' start time: %f, finish time: %f", SD_task_get_name(task), SD_task_get_start_time(task),
53 SD_task_get_finish_time(task));
55 xbt_dynar_reset(changed_tasks);
57 /* let throttle the communication for taskD if its parent is SD_DONE */
58 /* the bandwidth is 1.25e8, the data size is 1e7, and we want to throttle the bandwidth by a factor 2.
59 * The rate is then 1.25e8/(2*1e7)=6.25
60 * Changing the rate is possible before the task execution starts (in SD_RUNNING state).
62 if (SD_task_get_state(taskC) == SD_DONE && SD_task_get_state(taskD) < SD_RUNNING)
63 SD_task_set_rate(taskD, 6.25);
64 SD_simulate_with_update(-1.0, changed_tasks);
67 xbt_dynar_free(&changed_tasks);
69 XBT_DEBUG("Destroying tasks...");
70 SD_task_destroy(taskA);
71 SD_task_destroy(taskB);
72 SD_task_destroy(taskC);
73 SD_task_destroy(taskD);
74 SD_task_destroy(taskE);
76 XBT_DEBUG("Tasks destroyed. Exiting SimDag...");