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 "msg/msg.h" /* Yeah! If you want to use msg, you need to include msg/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 xbt_swag_t process_list = MSG_host_get_process_list(MSG_host_self());
24 msg_process_t process = NULL;
26 xbt_swag_foreach(process, process_list) {
27 XBT_INFO("Process(pid=%d, ppid=%d, name=%s)", MSG_process_get_PID(process), MSG_process_get_PPID(process), MSG_process_get_name(process));
28 if (MSG_process_self_PID()!=MSG_process_get_PID(process))
29 MSG_process_kill(process);
31 process = MSG_process_create("slave from master", slave, NULL, MSG_host_self());
34 XBT_INFO("Suspend Process(pid=%d)", MSG_process_get_PID(process));
35 MSG_process_suspend(process);
37 XBT_INFO("Process(pid=%d) is %ssuspended"
38 ,MSG_process_get_PID(process)
39 ,(MSG_process_is_suspended(process)) ? "" : "not ");
42 XBT_INFO("Resume Process(pid=%d)", MSG_process_get_PID(process));
43 MSG_process_resume(process);
45 XBT_INFO("Process(pid=%d) is %ssuspended"
46 ,MSG_process_get_PID(process)
47 ,(MSG_process_is_suspended(process)) ? "" : "not ");
49 MSG_process_kill(process);
51 XBT_INFO("Goodbye now!");
55 /** Receiver function */
56 int slave(int argc, char *argv[])
58 MSG_process_sleep(.5);
59 XBT_INFO("Slave started (PID:%d, PPID:%d)", MSG_process_self_PID(), MSG_process_self_PPID());
61 XBT_INFO("Plop i am %ssuspended", (MSG_process_is_suspended(MSG_process_self())) ? "" : "not ");
63 //MSG_process_suspend(MSG_process_self());
65 XBT_INFO("I'm done. See you!");
70 int main(int argc, char *argv[])
73 const char *platform_file;
74 const char *application_file;
76 MSG_init(&argc, argv);
78 printf("Usage: %s platform_file deployment_file\n", argv[0]);
79 printf("example: %s msg_platform.xml msg_deployment.xml\n", argv[0]);
82 platform_file = argv[1];
83 application_file = argv[1];
85 /* MSG_config("workstation/model","KCCFLN05"); */
86 { /* Simulation setting */
87 MSG_create_environment(platform_file);
89 { /* Application deployment */
90 MSG_function_register("master", master);
91 MSG_function_register("slave", slave);
93 MSG_launch_application(application_file);
97 XBT_INFO("Simulation time %g", MSG_get_clock());