Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
995932aded55d20435c12b4cbd43285898088554
[simgrid.git] / examples / simdag / fail / sd_fail.c
1 /* Copyright (c) 2006-2010, 2012-2016. 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_fail, "Logging specific to this SimDag example");
10
11 int main(int argc, char **argv)
12 {
13   double computation_amount[1];
14   double communication_amount[2] = { 0 };
15   sg_host_t hosts[1];
16
17   /* initialization of SD */
18   SD_init(&argc, argv);
19
20   /* creation of the environment */
21   SD_create_environment(argv[1]);
22
23   /* creation of a single task that will poorly fail when the workstation will stop */
24   XBT_INFO("First test: COMP_SEQ task");
25   SD_task_t task = SD_task_create_comp_seq("Poor task", NULL, 2e10);
26   SD_task_watch(task, SD_FAILED);
27   SD_task_watch(task, SD_DONE);
28
29   XBT_INFO("Schedule task '%s' on 'Faulty Host'", SD_task_get_name(task));
30
31   SD_task_schedulel(task, 1, sg_host_by_name("Faulty Host"));
32
33   xbt_dynar_t tasks = SD_simulate(-1.0);
34   xbt_dynar_free(&tasks);
35
36   SD_task_dump(task);
37
38   XBT_INFO("Task '%s' has failed. %.f flops remain to be done", SD_task_get_name(task),
39            SD_task_get_remaining_amount(task));
40
41   XBT_INFO("let's unschedule task '%s' and reschedule it on the 'Safe Host'", SD_task_get_name(task));
42   SD_task_unschedule(task);
43   SD_task_schedulel(task, 1, sg_host_by_name("Safe Host"));
44
45   XBT_INFO("Run the simulation again");
46   tasks = SD_simulate(-1.0);
47   xbt_dynar_free(&tasks);
48
49   SD_task_dump(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   SD_task_destroy(task);
54
55   XBT_INFO("Second test: NON TYPED task");
56
57   task = SD_task_create("Poor parallel task", NULL, 2e10);
58   SD_task_watch(task, SD_FAILED);
59   SD_task_watch(task, SD_DONE);
60
61   computation_amount[0] = 2e10;
62
63   XBT_INFO("Schedule task '%s' on 'Faulty Host'", SD_task_get_name(task));
64
65   hosts[0] = sg_host_by_name("Faulty Host");
66   SD_task_schedule(task, 1, hosts, computation_amount, communication_amount,-1);
67
68   tasks = SD_simulate(-1.0);
69   xbt_dynar_free(&tasks);
70
71   SD_task_dump(task);
72
73   XBT_INFO("Task '%s' has failed. %.f flops remain to be done", SD_task_get_name(task),
74             SD_task_get_remaining_amount(task));
75
76   XBT_INFO("let's unschedule task '%s' and reschedule it on the 'Safe Host'", SD_task_get_name(task));
77   SD_task_unschedule(task);
78
79   hosts[0] = sg_host_by_name("Safe Host");
80
81   SD_task_schedule(task, 1, hosts, computation_amount, communication_amount,-1);
82
83   XBT_INFO("Run the simulation again");
84   tasks = SD_simulate(-1.0);
85   xbt_dynar_free(&tasks);
86
87   SD_task_dump(task);
88   XBT_INFO("Task '%s' start time: %f, finish time: %f", SD_task_get_name(task), SD_task_get_start_time(task),
89            SD_task_get_finish_time(task));
90
91   SD_task_destroy(task);
92   SD_exit();
93   return 0;
94 }