Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
4d27e38e5d5c993783f10917849f5646a1a6f197
[simgrid.git] / teshsuite / msg / host_on_off_recv / host_on_off_recv.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 const char* mailbox = "comm";
12
13 static int master(int argc, char *argv[])
14 {
15   msg_host_t jupiter = MSG_host_by_name("Jupiter");
16
17   XBT_INFO("Master starting");
18   MSG_process_sleep(0.5);
19
20   msg_comm_t comm = NULL;
21   {
22     msg_task_t task = MSG_task_create("COMM", 0, 100000000, NULL);
23     comm = MSG_task_isend(task, mailbox);
24   }
25
26   MSG_process_sleep(0.5);
27
28   XBT_INFO("Turning off the slave host");
29   MSG_host_off(jupiter);
30
31   if (comm) {
32     MSG_comm_wait(comm, -1);
33     MSG_comm_destroy(comm);
34   }
35   XBT_INFO("Master has finished");
36
37   return 0;
38 }
39
40 static int slave(int argc, char *argv[])
41 {
42   XBT_INFO("Slave receiving");
43   msg_task_t task = NULL;
44   msg_error_t error = MSG_task_receive(&(task), mailbox);
45   if (error) {
46     XBT_ERROR("Error while receiving message");
47     return 1;
48   }
49
50   XBT_ERROR("Slave should be off already.");
51   return 1;
52 }
53
54 int main(int argc, char *argv[])
55 {
56   msg_error_t res;
57
58   MSG_init(&argc, argv);
59   xbt_assert(argc == 2, "Usage: %s platform_file\n\tExample: %s msg_platform.xml\n", argv[0], argv[0]);
60
61   MSG_create_environment(argv[1]);
62
63   MSG_process_create("master", master, NULL, MSG_get_host_by_name("Tremblay"));
64   MSG_process_create("slave", slave, NULL, MSG_get_host_by_name("Jupiter"));
65
66   res = MSG_main();
67
68   XBT_INFO("Simulation time %g", MSG_get_clock());
69
70   return res != MSG_OK;
71 }