Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of git+ssh://scm.gforge.inria.fr//gitroot/simgrid/simgrid
[simgrid.git] / examples / simdag / sd_comm_throttling.c
1 /* Copyright (c) 2006, 2007, 2008, 2009, 2010. 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 "simdag/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 SD_workstation_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   if (argc < 2) {
30     XBT_INFO("Usage: %s platform_file", argv[0]);
31     XBT_INFO("example: %s sd_platform.xml", argv[0]);
32     exit(1);
33   }
34
35   /* creation of the environment */
36   platform_file = argv[1];
37   SD_create_environment(platform_file);
38  
39   workstations = SD_workstation_get_list();
40
41   /* creation of some typed tasks and their dependencies */
42   /* chain of five tasks, three compute tasks with two data transfers */
43   /* in between */
44   taskA = SD_task_create_comp_seq("Task A", NULL, 5e9);
45   taskB = SD_task_create_comm_e2e("Task B", NULL, 1e7);
46   taskC = SD_task_create_comp_seq("Task C", NULL, 5e9);
47   taskD = SD_task_create_comm_e2e("Task D", NULL, 1e7);
48   taskE = SD_task_create_comp_seq("Task E", NULL, 5e9);
49
50   SD_task_dependency_add(NULL, NULL, taskA, taskB);
51   SD_task_dependency_add(NULL, NULL, taskB, taskC);
52   SD_task_dependency_add(NULL, NULL, taskC, taskD);
53   SD_task_dependency_add(NULL, NULL, taskD, taskE);
54
55   /* Add watchpoints on completion of compute tasks */
56   SD_task_watch(taskA, SD_DONE);
57   SD_task_watch(taskC, SD_DONE);
58   SD_task_watch(taskE, SD_DONE);
59
60   /* Auto-schedule the compute tasks on three different workstations */
61   /* Data transfer tasks taskB and taskD are automagically scheduled */
62   SD_task_schedulel(taskA, 1, workstations[0]);
63   SD_task_schedulel(taskC, 1, workstations[1]);
64   SD_task_schedulel(taskE, 1, workstations[0]);
65   while (!xbt_dynar_is_empty((changed_tasks = SD_simulate(-1.0)))) {
66     XBT_INFO("Simulation stopped after %.4f seconds", SD_get_clock());
67     xbt_dynar_foreach(changed_tasks, ctr, task) {
68       XBT_INFO("Task '%s' start time: %f, finish time: %f",
69          SD_task_get_name(task),
70          SD_task_get_start_time(task), 
71          SD_task_get_finish_time(task));
72  
73     }
74     /* let throttle the communication for taskD if its parent is SD_DONE */
75     /* the bandwidth is 1.25e8, the data size is 1e7, and we want to throttle
76      * the bandwidth by a factor 2. the rate is then 1.25e8/(2*1e7)=6.25
77      */
78     if (SD_task_get_state(taskC) == SD_DONE)
79       SD_task_set_rate(taskD, 6.25);
80     xbt_dynar_free_container(&changed_tasks);
81   }
82   xbt_dynar_free_container(&changed_tasks);
83
84   XBT_DEBUG("Destroying tasks...");
85
86   SD_task_destroy(taskA);
87   SD_task_destroy(taskB);
88   SD_task_destroy(taskC);
89   SD_task_destroy(taskD);
90   SD_task_destroy(taskE);
91
92   XBT_DEBUG("Tasks destroyed. Exiting SimDag...");
93
94   SD_exit();
95   return 0;
96 }