1 /* Copyright (c) 2010-2014. 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 */
11 /* Create a log channel to have nice outputs. */
13 #include "xbt/asserts.h"
14 XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test,
15 "Messages specific for this msg example");
17 int master(int argc, char *argv[]);
18 int slave(int argc, char *argv[]);
20 /** Emitter function */
21 int master(int argc, char *argv[])
23 msg_process_t process;
25 XBT_INFO("Start slave");
26 process = MSG_process_create("slave from master",
27 slave, NULL, MSG_host_self());
28 XBT_INFO("Join the slave (timeout 2)");
29 MSG_process_join(process, 2);
31 XBT_INFO("Start slave");
32 process = MSG_process_create("slave from master",
33 slave, NULL, MSG_host_self());
34 XBT_INFO("Join the slave (timeout 4)");
35 MSG_process_join(process, 4);
37 XBT_INFO("Start slave");
38 process = MSG_process_create("slave from master",
39 slave, NULL, MSG_host_self());
40 XBT_INFO("Join the slave (timeout 2)");
41 MSG_process_join(process, 2);
43 XBT_INFO("Goodbye now!");
47 XBT_INFO("Goodbye now!");
51 /** Receiver function */
52 int slave(int argc, char *argv[])
54 XBT_INFO("Slave started");
56 XBT_INFO("I'm done. See you!");
61 int main(int argc, char *argv[])
64 const char *platform_file;
65 const char *application_file;
67 MSG_init(&argc, argv);
69 printf("Usage: %s platform_file deployment_file\n", argv[0]);
70 printf("example: %s msg_platform.xml msg_deployment.xml\n", argv[0]);
73 platform_file = argv[1];
74 application_file = argv[2];
76 { /* Simulation setting */
77 MSG_create_environment(platform_file);
79 { /* Application deployment */
80 MSG_function_register("master", master);
81 MSG_function_register("slave", slave);
83 MSG_launch_application(application_file);
87 XBT_INFO("Simulation time %g", MSG_get_clock());