Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
add a (simple) test for storage actions
[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 "simgrid/simdag.h"
8
9 XBT_LOG_NEW_DEFAULT_CATEGORY(sd_comm_throttling, "Logging specific to this SimDag example");
10
11 int main(int argc, char **argv)
12 {
13   unsigned int ctr;
14   SD_task_t task;
15   xbt_dynar_t changed_tasks;
16
17   SD_init(&argc, argv);
18   xbt_assert(argc > 1, "Usage: %s platform_file\n\nExample: %s two_clusters.xml", argv[0], argv[0]);
19
20   SD_create_environment(argv[1]);
21
22   const sg_host_t *hosts = sg_host_list();
23
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);
31
32   SD_task_dependency_add(NULL, NULL, taskA, taskB);
33   SD_task_dependency_add(NULL, NULL, taskB, taskC);
34   SD_task_dependency_add(NULL, NULL, taskC, taskD);
35   SD_task_dependency_add(NULL, NULL, taskD, taskE);
36
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);
41
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]);
47   while (!xbt_dynar_is_empty((changed_tasks = SD_simulate(-1.0)))) {
48     XBT_INFO("Simulation stopped after %.4f seconds", SD_get_clock());
49     xbt_dynar_foreach(changed_tasks, ctr, task) {
50       XBT_INFO("Task '%s' start time: %f, finish time: %f", SD_task_get_name(task), SD_task_get_start_time(task),
51                SD_task_get_finish_time(task));
52     }
53
54     /* let throttle the communication for taskD if its parent is SD_DONE */
55     /* the bandwidth is 1.25e8, the data size is 1e7, and we want to throttle the bandwidth by a factor 2.
56      * The rate is then 1.25e8/(2*1e7)=6.25
57      * Changing the rate is possible before the task execution starts (in SD_RUNNING state).
58      */
59     if (SD_task_get_state(taskC) == SD_DONE && SD_task_get_state(taskD) < SD_RUNNING)
60       SD_task_set_rate(taskD, 6.25);
61   }
62
63   XBT_DEBUG("Destroying tasks...");
64   SD_task_destroy(taskA);
65   SD_task_destroy(taskB);
66   SD_task_destroy(taskC);
67   SD_task_destroy(taskD);
68   SD_task_destroy(taskE);
69
70   XBT_DEBUG("Tasks destroyed. Exiting SimDag...");
71   SD_exit();
72   return 0;
73 }