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 static const char* mailbox = "comm";
23 /** Emitter function */
24 int master(int argc, char *argv[])
28 msg_host_t jupiter = MSG_host_by_name("Jupiter");
30 XBT_INFO("Master starting");
31 MSG_process_sleep(0.5);
33 msg_comm_t comm = NULL;
35 msg_task_t task = MSG_task_create("COMM", 0, 100000000, NULL);
36 comm = MSG_task_isend(task, mailbox);
39 MSG_process_sleep(0.5);
41 XBT_INFO("Turning off the slave host");
42 MSG_host_off(jupiter);
45 MSG_comm_wait(comm, -1);
46 MSG_comm_destroy(comm);
48 XBT_INFO("Master has finished");
51 xbt_die("Exception caught in the master");
57 /** Receiver function */
58 int slave(int argc, char *argv[])
62 XBT_INFO("Slave receiving");
63 msg_task_t task = NULL;
64 msg_error_t error = MSG_task_receive(&(task), mailbox);
66 XBT_ERROR("Error while receiving message");
70 XBT_ERROR("Slave should be off already.");
74 XBT_ERROR("Exception caught in the slave");
81 int main(int argc, char *argv[])
84 const char *platform_file;
85 const char *application_file;
87 MSG_init(&argc, argv);
88 xbt_assert(argc > 2, "Usage: %s platform_file deployment_file\n"
89 "\tExample: %s msg_platform.xml msg_deployment.xml\n", argv[0], argv[0]);
91 platform_file = argv[1];
92 application_file = argv[2];
94 /* Simulation setting */
95 MSG_create_environment(platform_file);
97 /* Application deployment */
98 MSG_function_register("master", master);
99 MSG_function_register("slave", slave);
100 MSG_launch_application(application_file);
104 XBT_INFO("Simulation time %g", MSG_get_clock());
106 return res != MSG_OK;