Logo AND Algorithmique Numérique Distribuée

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