Logo AND Algorithmique Numérique Distribuée

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