Logo AND Algorithmique Numérique Distribuée

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