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 double task_comp_size = 5E7;
24 double task_comm_size = 1E6;
27 msg_task_t task = NULL;
28 msg_host_t jupiter = MSG_get_host_by_name("Jupiter");
29 sprintf(mailbox, "jupi");
31 task = MSG_task_create("task on", task_comp_size, task_comm_size, NULL);
32 XBT_INFO("Sending \"%s\"", task->name);
33 if (MSG_task_send_with_timeout(task, mailbox, 1) != MSG_OK)
34 MSG_task_destroy(task);
37 MSG_host_off(jupiter);
39 task = MSG_task_create("task off", task_comp_size, task_comm_size, NULL);
40 XBT_INFO("Sending \"%s\"", task->name);
41 if (MSG_task_send_with_timeout(task, mailbox, 1) != MSG_OK)
42 MSG_task_destroy(task);
45 xbt_swag_t jupi_processes = MSG_host_get_process_list(jupiter);
47 xbt_swag_foreach(process, jupi_processes) {
48 MSG_process_kill(process);
51 task = MSG_task_create("task on without proc", task_comp_size, task_comm_size, NULL);
52 XBT_INFO("Sending \"%s\"", task->name);
53 if (MSG_task_send_with_timeout(task, mailbox, 1) != MSG_OK)
54 MSG_task_destroy(task);
56 char **argvF = xbt_new(char*, 2);
57 argvF[0] = xbt_strdup("slave");
58 MSG_process_create_with_arguments("slave", slave, NULL, MSG_get_host_by_name("Jupiter"), 1, argvF);
60 task = MSG_task_create("task on with proc", task_comp_size, task_comm_size, NULL);
61 XBT_INFO("Sending \"%s\"", task->name);
62 if (MSG_task_send_with_timeout(task, mailbox, 1) != MSG_OK)
63 MSG_task_destroy(task);
65 task = MSG_task_create("finalize", 0, 0, 0);
66 XBT_INFO("Sending \"%s\"", task->name);
67 if (MSG_task_send_with_timeout(task, mailbox, 1) != MSG_OK)
68 MSG_task_destroy(task);
70 XBT_INFO("Goodbye now!");
74 /** Receiver function */
75 int slave(int argc, char *argv[])
77 msg_task_t task = NULL;
78 _XBT_GNUC_UNUSED int res;
82 sprintf(mailbox, "jupi");
85 res = MSG_task_receive(&(task), mailbox);
86 xbt_assert(res == MSG_OK, "MSG_task_get failed");
88 if (!strcmp(MSG_task_get_name(task), "finalize")) {
89 MSG_task_destroy(task);
92 MSG_task_execute(task);
93 XBT_INFO("Task \"%s\" done", MSG_task_get_name(task));
95 MSG_task_destroy(task);
99 XBT_INFO("I'm done. See you!");
104 int main(int argc, char *argv[])
107 const char *platform_file;
108 const char *application_file;
110 MSG_init(&argc, argv);
112 printf("Usage: %s platform_file deployment_file\n", argv[0]);
113 printf("example: %s msg_platform.xml msg_deployment.xml\n", argv[0]);
116 platform_file = argv[1];
117 application_file = argv[2];
119 /* MSG_config("workstation/model","KCCFLN05"); */
120 { /* Simulation setting */
121 MSG_create_environment(platform_file);
123 { /* Application deployment */
124 MSG_function_register("master", master);
125 MSG_function_register("slave", slave);
127 MSG_launch_application(application_file);
131 XBT_INFO("Simulation time %g", MSG_get_clock());