Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
cosmetics in the coordinate-based platform files
[simgrid.git] / examples / simdag / sd_comm_throttling.c
1 /* Copyright (c) 2006-2010, 2012-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 <stdio.h>
8 #include "simgrid/simdag.h"
9 #include "xbt/log.h"
10
11 XBT_LOG_NEW_DEFAULT_CATEGORY(sd_comm_throttling, "Logging specific to this SimDag example");
12
13 int main(int argc, char **argv)
14 {
15   unsigned int ctr;
16   const sg_host_t *hosts;
17   SD_task_t task, taskA, taskB, taskC, taskD, taskE;
18   xbt_dynar_t changed_tasks;
19
20   SD_init(&argc, argv);
21   xbt_assert(argc > 1, "Usage: %s platform_file\n\nExample: %s two_clusters.xml", argv[0], argv[0]);
22
23   /* creation of the environment */
24   SD_create_environment(argv[1]);
25
26   hosts = sg_host_list();
27
28   /* creation of some typed tasks and their dependencies */
29   /* chain of five tasks, three compute tasks with two data transfers in between */
30   taskA = SD_task_create_comp_seq("Task A", NULL, 5e9);
31   taskB = SD_task_create_comm_e2e("Task B", NULL, 1e7);
32   taskC = SD_task_create_comp_seq("Task C", NULL, 5e9);
33   taskD = SD_task_create_comm_e2e("Task D", NULL, 1e7);
34   taskE = SD_task_create_comp_seq("Task E", NULL, 5e9);
35
36   SD_task_dependency_add(NULL, NULL, taskA, taskB);
37   SD_task_dependency_add(NULL, NULL, taskB, taskC);
38   SD_task_dependency_add(NULL, NULL, taskC, taskD);
39   SD_task_dependency_add(NULL, NULL, taskD, taskE);
40
41   /* Add watchpoints on completion of compute tasks */
42   SD_task_watch(taskA, SD_DONE);
43   SD_task_watch(taskC, SD_DONE);
44   SD_task_watch(taskE, SD_DONE);
45
46   /* Auto-schedule the compute tasks on three different workstations */
47   /* Data transfer tasks taskB and taskD are automagically scheduled */
48   SD_task_schedulel(taskA, 1, hosts[0]);
49   SD_task_schedulel(taskC, 1, hosts[1]);
50   SD_task_schedulel(taskE, 1, hosts[0]);
51   while (!xbt_dynar_is_empty((changed_tasks = SD_simulate(-1.0)))) {
52     XBT_INFO("Simulation stopped after %.4f seconds", SD_get_clock());
53     xbt_dynar_foreach(changed_tasks, ctr, task) {
54       XBT_INFO("Task '%s' start time: %f, finish time: %f", SD_task_get_name(task), SD_task_get_start_time(task),
55                SD_task_get_finish_time(task));
56     }
57
58     /* let throttle the communication for taskD if its parent is SD_DONE */
59     /* the bandwidth is 1.25e8, the data size is 1e7, and we want to throttle the bandwidth by a factor 2.
60      * The rate is then 1.25e8/(2*1e7)=6.25
61      * Changing the rate is possible before the task execution starts (in SD_RUNNING state).
62      */
63     if (SD_task_get_state(taskC) == SD_DONE && SD_task_get_state(taskD) < SD_RUNNING)
64       SD_task_set_rate(taskD, 6.25);
65   }
66
67   XBT_DEBUG("Destroying tasks...");
68   SD_task_destroy(taskA);
69   SD_task_destroy(taskB);
70   SD_task_destroy(taskC);
71   SD_task_destroy(taskD);
72   SD_task_destroy(taskE);
73
74   XBT_DEBUG("Tasks destroyed. Exiting SimDag...");
75   SD_exit();
76   return 0;
77 }