1 /* Copyright (c) 2012-2016. The SimGrid Team.
2 * All rights reserved. */
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. */
7 #include "simgrid/simdag.h"
9 XBT_LOG_NEW_DEFAULT_CATEGORY(sd_avail, "Logging specific to this SimDag example");
11 /* Test of dynamic availability traces
13 * - A chain of tasks: t1 -> c1 -> t2 -> c2 -> t3 -> c3 -> t4 alternatively
14 * scheduled across two workstations (Tremblay and Jupiter) connected by a
16 * - Make the characteristics of the resources change across time
18 * [0.000000 -> 2.000000[ runs at half speed: 12500000
19 * [2.000000 -> end[ runs at full speed: 25000000
21 * [0.000000 -> 1.000000[ runs at half speed: 15000000
22 * [1.000000 -> 4.000000[ runs at full speed: 25000000
23 * [4.000000 -> 6.000000[ runs at half speed: 12500000
26 * [0.000000 -> 2.000000[ bandwidth = 125000000
27 * [2.000000 -> 4.000000[ bandwidth = 62500000
28 * [4.000000 -> 6.000000[ bandwidth = 31250000
30 * - Adjust tasks' amounts to have comprehensive execution times
31 * t1: 25000000 flops, should last 2 seconds
32 * c1: 125000000 bytes, should last 1.0001 seconds
33 * t2: 25000000 flops, should last 1 second
34 * c2: 62500000 bytes, should last 1.0001 seconds
35 * t3: 25000000 flops, should last 1 second
36 * c3: 31250000 bytes, should last 1.0001 seconds
37 * t4: 25000000 flops, should last 1 second
40 int main(int argc, char **argv)
43 SD_create_environment(argv[1]);
44 sg_host_t *hosts = sg_host_list();
46 SD_task_t t1 = SD_task_create_comp_seq("t1", NULL, 25000000);
47 SD_task_t c1 = SD_task_create_comm_e2e("c1", NULL, 125000000);
48 SD_task_t t2 = SD_task_create_comp_seq("t2", NULL, 25000000);
49 SD_task_t c2 = SD_task_create_comm_e2e("c2", NULL, 62500000);
50 SD_task_t t3 = SD_task_create_comp_seq("t3", NULL, 25000000);
51 SD_task_t c3 = SD_task_create_comm_e2e("c3", NULL, 31250000);
52 SD_task_t t4 = SD_task_create_comp_seq("t4", NULL, 25000000);
54 /* Add dependencies: t1->c1->t2->c2->t3 */
55 SD_task_dependency_add(NULL, NULL, t1, c1);
56 SD_task_dependency_add(NULL, NULL, c1, t2);
57 SD_task_dependency_add(NULL, NULL, t2, c2);
58 SD_task_dependency_add(NULL, NULL, c2, t3);
59 SD_task_dependency_add(NULL, NULL, t3, c3);
60 SD_task_dependency_add(NULL, NULL, c3, t4);
62 /* Schedule tasks t1 and w3 on first host, t2 on second host */
63 /* Transfers are auto-scheduled */
64 SD_task_schedulel(t1, 1, hosts[0]);
65 SD_task_schedulel(t2, 1, hosts[1]);
66 SD_task_schedulel(t3, 1, hosts[0]);
67 SD_task_schedulel(t4, 1, hosts[1]);
69 /* Add some watchpoint upon task completion */
70 SD_task_watch(t1, SD_DONE);
71 SD_task_watch(c1, SD_DONE);
72 SD_task_watch(t2, SD_DONE);
73 SD_task_watch(c2, SD_DONE);
74 SD_task_watch(t3, SD_DONE);
75 SD_task_watch(c3, SD_DONE);
76 SD_task_watch(t4, SD_DONE);
77 xbt_dynar_t changed_tasks = xbt_dynar_new(sizeof(SD_task_t), NULL);
79 SD_simulate_with_update(-1.0, changed_tasks);
80 if (xbt_dynar_is_empty(changed_tasks))
82 XBT_INFO("link1: bw=%.0f, lat=%f", sg_host_route_bandwidth(hosts[0], hosts[1]),
83 sg_host_route_latency(hosts[0], hosts[1]));
84 XBT_INFO("Jupiter: speed=%.0f", sg_host_speed(hosts[0])* sg_host_get_available_speed(hosts[0]));
85 XBT_INFO("Tremblay: speed=%.0f", sg_host_speed(hosts[1])* sg_host_get_available_speed(hosts[1]));
89 xbt_dynar_foreach(changed_tasks, ctr, task) {
90 XBT_INFO("Task '%s' start time: %f, finish time: %f", SD_task_get_name(task),
91 SD_task_get_start_time(task), SD_task_get_finish_time(task));
92 if (SD_task_get_state(task)==SD_DONE)
93 SD_task_destroy(task);
95 xbt_dynar_reset(changed_tasks);
99 xbt_dynar_free(&changed_tasks);