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. */
8 #include "simgrid/msg.h" /* Yeah! If you want to use msg, you need to include simgrid/msg.h */
9 #include "xbt/sysdep.h" /* calloc, printf */
12 /* Create a log channel to have nice outputs. */
14 #include "xbt/asserts.h"
15 XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test,
16 "Messages specific for this msg example");
18 int master(int argc, char *argv[]);
19 int slave(int argc, char *argv[]);
21 /** Emitter function */
22 int master(int argc, char *argv[])
26 msg_host_t jupiter = MSG_host_by_name("Jupiter");
27 XBT_INFO("Master waiting");
30 XBT_INFO("Turning off the slave host");
31 MSG_host_off(jupiter);
32 XBT_INFO("Master has finished");
35 xbt_die("Exception caught in the master");
41 /** Receiver function */
42 int slave(int argc, char *argv[])
46 XBT_INFO("Slave waiting");
47 // TODO, This should really be MSG_HOST_FAILURE
49 XBT_ERROR("Slave should be off already.");
53 XBT_ERROR("Exception caught in the slave");
60 int main(int argc, char *argv[])
63 const char *platform_file;
64 const char *application_file;
66 MSG_init(&argc, argv);
67 xbt_assert(argc > 2, "Usage: %s platform_file deployment_file\n"
68 "\tExample: %s msg_platform.xml msg_deployment.xml\n", argv[0], argv[0]);
70 platform_file = argv[1];
71 application_file = argv[2];
73 { /* Simulation setting */
74 MSG_create_environment(platform_file);
76 { /* Application deployment */
77 MSG_function_register("master", master);
78 MSG_function_register("slave", slave);
80 MSG_launch_application(application_file);
84 XBT_INFO("Simulation time %g", MSG_get_clock());