1 /* Copyright (c) 2010-2015. The SimGrid Team.
2 * All rights reserved. */
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. */
7 #include "simgrid/msg.h" /* Yeah! If you want to use msg, you need to include simgrid/msg.h */
9 XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test, "Messages specific for this msg example");
11 static const char* mailbox = "comm";
13 static int master(int argc, char *argv[])
15 msg_host_t jupiter = MSG_host_by_name("Jupiter");
17 XBT_INFO("Master starting");
18 MSG_process_sleep(0.5);
20 msg_task_t task = MSG_task_create("COMM", 0, 100000000, NULL);
21 msg_comm_t comm = MSG_task_isend(task, mailbox);
23 MSG_process_sleep(0.5);
25 XBT_INFO("Turning off the slave host");
26 MSG_host_off(jupiter);
29 MSG_comm_wait(comm, -1);
30 MSG_comm_destroy(comm);
32 XBT_INFO("Master has finished");
37 static int slave(int argc, char *argv[])
39 XBT_INFO("Slave receiving");
40 msg_task_t task = NULL;
41 msg_error_t error = MSG_task_receive(&(task), mailbox);
43 XBT_ERROR("Error while receiving message");
47 XBT_ERROR("Slave should be off already.");
51 int main(int argc, char *argv[])
55 MSG_init(&argc, argv);
56 xbt_assert(argc == 2, "Usage: %s platform_file\n\tExample: %s msg_platform.xml\n", argv[0], argv[0]);
58 MSG_create_environment(argv[1]);
60 MSG_process_create("master", master, NULL, MSG_get_host_by_name("Tremblay"));
61 MSG_process_create("slave", slave, NULL, MSG_get_host_by_name("Jupiter"));
65 XBT_INFO("Simulation time %g", MSG_get_clock());