Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
circumvent the fact that if you let the simulation runs, trace events
[simgrid.git] / examples / simdag / sd_fail.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_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   /* initialization of SD */
23   SD_init(&argc, argv);
24
25   /* creation of the environment */
26   SD_create_environment("./faulty_host.xml");
27  
28   /* creation of a single task that will poorly fail when the workstation
29    * will stop */
30   XBT_INFO("First test: COMP_SEQ task");
31   task = SD_task_create_comp_seq("Poor task", NULL, 2e10);
32   SD_task_watch(task, SD_FAILED);
33   SD_task_watch(task, SD_DONE);
34
35   XBT_INFO("Schedule task '%s' on workstation 'Faulty Host'",
36            SD_task_get_name(task));
37
38   SD_task_schedulel(task, 1, SD_workstation_get_by_name("Faulty Host"));
39
40   SD_simulate(-1.0);
41
42   SD_task_dump(task);
43
44   XBT_INFO("Task '%s' has failed. %.f flops remain to be done",
45            SD_task_get_name(task),
46            SD_task_get_remaining_amount(task));
47
48   XBT_INFO("let's unschedule task '%s' and reschedule it on the 'Safe Host'",
49            SD_task_get_name(task));
50   SD_task_unschedule(task);
51   SD_task_schedulel(task, 1, SD_workstation_get_by_name("Safe Host"));
52
53   XBT_INFO("Run the simulation again");
54   SD_simulate(-1.0);
55
56   SD_task_dump(task);
57   XBT_INFO("Task '%s' start time: %f, finish time: %f",
58       SD_task_get_name(task),
59       SD_task_get_start_time(task),
60       SD_task_get_finish_time(task));
61
62   SD_task_destroy(task);
63   task=NULL;
64
65   XBT_INFO("Second test: NON TYPED task");
66
67   task = SD_task_create("Poor parallel task", NULL, 2e10);
68   SD_task_watch(task, SD_FAILED);
69   SD_task_watch(task, SD_DONE);
70
71   computation_amount[0] = 2e10;
72
73   XBT_INFO("Schedule task '%s' on workstation 'Faulty Host'",
74              SD_task_get_name(task));
75
76   workstation_list[0] = SD_workstation_get_by_name("Faulty Host");
77   SD_task_schedule(task, 1, workstation_list,
78           computation_amount, communication_amount,-1);
79
80   SD_simulate(-1.0);
81
82   SD_task_dump(task);
83
84   XBT_INFO("Task '%s' has failed. %.f flops remain to be done",
85             SD_task_get_name(task),
86             SD_task_get_remaining_amount(task));
87
88   XBT_INFO("let's unschedule task '%s' and reschedule it on the 'Safe Host'",
89            SD_task_get_name(task));
90   SD_task_unschedule(task);
91
92   workstation_list[0] = SD_workstation_get_by_name("Safe Host");
93
94   SD_task_schedule(task, 1, workstation_list,
95                    computation_amount, communication_amount,-1);
96
97   XBT_INFO("Run the simulation again");
98   SD_simulate(-1.0);
99
100   SD_task_dump(task);
101   XBT_INFO("Task '%s' start time: %f, finish time: %f",
102            SD_task_get_name(task),
103            SD_task_get_start_time(task),
104            SD_task_get_finish_time(task));
105
106   SD_task_destroy(task);
107   SD_exit();
108   return 0;
109 }