Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
3b84c4d35b0c4565811e90820614a12f365a8be4
[simgrid.git] / teshsuite / msg / host_on_off_wait / host_on_off_wait.c
1 /* Copyright (c) 2010-2015. 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/msg.h"            /* Yeah! If you want to use msg, you need to include simgrid/msg.h */
8
9 XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test, "Messages specific for this msg example");
10
11 static int master(int argc, char *argv[])
12 {
13   xbt_ex_t e;
14   TRY {
15     msg_host_t jupiter = MSG_host_by_name("Jupiter");
16     XBT_INFO("Master waiting");
17     MSG_process_sleep(1);
18
19     XBT_INFO("Turning off the slave host");
20     MSG_host_off(jupiter);
21     XBT_INFO("Master has finished");
22   }
23   CATCH(e) {
24     xbt_die("Exception caught in the master");
25     return 1;
26   }
27   return 0;
28 }
29
30 static int slave(int argc, char *argv[])
31 {
32   xbt_ex_t e;
33   TRY {
34     XBT_INFO("Slave waiting");
35     // TODO, This should really be MSG_HOST_FAILURE
36     MSG_process_sleep(5);
37     XBT_ERROR("Slave should be off already.");
38     return 1;
39   }
40   CATCH(e) {
41     XBT_ERROR("Exception caught in the slave");
42     return 1;
43   }
44   return 0;
45 }
46
47 int main(int argc, char *argv[])
48 {
49   msg_error_t res;
50
51   MSG_init(&argc, argv);
52   xbt_assert(argc == 2, "Usage: %s platform_file\n\tExample: %s msg_platform.xml\n", argv[0], argv[0]);
53
54   MSG_create_environment(argv[1]);
55
56   MSG_process_create("master", master, NULL, MSG_get_host_by_name("Tremblay"));
57   MSG_process_create("slave", slave, NULL, MSG_get_host_by_name("Jupiter"));
58
59   res = MSG_main();
60
61   XBT_INFO("Simulation time %g", MSG_get_clock());
62
63   return res != MSG_OK;
64 }