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_avail.c
1 /* Copyright (c) 2012. 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_avail,
14                              "Logging specific to this SimDag example");
15
16 /* Test of dynamic availability traces
17  * Scenario:
18  *  - A chain of tasks: t1 -> c1 -> t2 -> c2 -> t3 -> c3 -> t4 alternatively
19  *    scheduled across two workstations (Tremblay and Jupiter) connected by a
20  *    single link (link1)
21  *  - Make the characteristics of the resources change across time
22  *      Jupiter
23  *         [0.000000 -> 2.000000[ runs at half speed: 12500000
24  *         [2.000000 -> end[      runs at full speed: 25000000
25  *      Tremblay
26  *         [0.000000 -> 1.000000[ runs at half speed: 15000000
27  *         [1.000000 -> 4.000000[ runs at full speed: 25000000
28  *         [4.000000 -> 6.000000[ runs at half speed: 12500000
29  *         then loop back.
30  *      link1
31  *         [0.000000 -> 2.000000[ bandwidth = 125000000
32  *         [2.000000 -> 4.000000[ bandwidth = 62500000
33  *         [4.000000 -> 6.000000[ bandwidth = 31250000
34  *         then loop back.
35  *  - Adjust tasks' amounts to have comprehensive execution times
36  *      t1: 25000000 flops, should last 2 seconds
37  *      c1: 125000000 bytes, should last 1.0001 seconds
38  *      t2: 25000000 flops, should last 1 second
39  *      c2: 62500000 bytes, should last 1.0001 seconds
40  *      t3: 25000000 flops, should last 1 second
41  *      c3: 31250000 bytes, should last 1.0001 seconds
42  *      t4: 25000000 flops, should last 1 second
43  */
44
45 int main(int argc, char **argv)
46 {
47   unsigned int ctr;
48   const SD_workstation_t *workstations;
49   SD_task_t t1, c1, t2, c2, t3, c3, t4, task;
50   xbt_dynar_t changed_tasks;
51
52   SD_init(&argc, argv);
53   SD_create_environment(argv[1]);
54   workstations = SD_workstation_get_list();
55
56   t1 = SD_task_create_comp_seq("t1", NULL, 25000000);
57   c1 = SD_task_create_comm_e2e("c1", NULL, 125000000);
58   t2 = SD_task_create_comp_seq("t2", NULL, 25000000);
59   c2 = SD_task_create_comm_e2e("c2", NULL, 62500000);
60   t3 = SD_task_create_comp_seq("t3", NULL, 25000000);
61   c3 = SD_task_create_comm_e2e("c3", NULL, 31250000);
62   t4 = SD_task_create_comp_seq("t4", NULL, 25000000);
63
64   /* Add dependencies: t1->c1->t2->c2->t3 */
65   SD_task_dependency_add(NULL, NULL, t1, c1);
66   SD_task_dependency_add(NULL, NULL, c1, t2);
67   SD_task_dependency_add(NULL, NULL, t2, c2);
68   SD_task_dependency_add(NULL, NULL, c2, t3);
69   SD_task_dependency_add(NULL, NULL, t3, c3);
70   SD_task_dependency_add(NULL, NULL, c3, t4);
71
72   /* Schedule tasks t1 and w3 on first host, t2 on second host */
73   /* Transfers are auto-scheduled */
74   SD_task_schedulel(t1, 1, workstations[0]);
75   SD_task_schedulel(t2, 1, workstations[1]);
76   SD_task_schedulel(t3, 1, workstations[0]);
77   SD_task_schedulel(t4, 1, workstations[1]);
78
79   /* Add some watchpoint upon task completion */
80   SD_task_watch(t1, SD_DONE);
81   SD_task_watch(c1, SD_DONE);
82   SD_task_watch(t2, SD_DONE);
83   SD_task_watch(c2, SD_DONE);
84   SD_task_watch(t3, SD_DONE);
85   SD_task_watch(c3, SD_DONE);
86   SD_task_watch(t4, SD_DONE);
87
88   while (!xbt_dynar_is_empty((changed_tasks = SD_simulate(-1.0)))) {    
89     XBT_INFO("link1: bw=%.0f, lat=%f",
90              SD_route_get_current_bandwidth(workstations[0], workstations[1]),
91              SD_route_get_current_latency(workstations[0], workstations[1]));
92     XBT_INFO("Jupiter: power=%.0f",
93              SD_workstation_get_power(workstations[0])*
94              SD_workstation_get_available_power(workstations[0]));
95     XBT_INFO("Tremblay: power=%.0f",
96              SD_workstation_get_power(workstations[1])*
97              SD_workstation_get_available_power(workstations[1]));
98     xbt_dynar_foreach(changed_tasks, ctr, task) {
99       XBT_INFO("Task '%s' start time: %f, finish time: %f",
100            SD_task_get_name(task),
101            SD_task_get_start_time(task), SD_task_get_finish_time(task));
102       if (SD_task_get_state(task)==SD_DONE)
103         SD_task_destroy(task);
104     }
105   }
106   SD_exit();
107   return 0;
108 }