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;
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 MSG_task_send_with_timeout(task, mailbox, 1);
36 MSG_host_off(MSG_get_host_by_name("Jupiter"));
38 task = MSG_task_create("task off", task_comp_size, task_comm_size, NULL);
39 XBT_INFO("Sending \"%s\"", task->name);
40 MSG_task_send_with_timeout(task, mailbox, 1);
42 MSG_host_on(MSG_get_host_by_name("Jupiter"));
44 task = MSG_task_create("task on without proc", task_comp_size, task_comm_size, NULL);
45 XBT_INFO("Sending \"%s\"", task->name);
46 MSG_task_send_with_timeout(task, mailbox, 1);
48 char **argvF = xbt_new(char*, 2);
49 argvF[0] = xbt_strdup("slave");
50 MSG_process_create_with_arguments("slave", slave, NULL, MSG_get_host_by_name("Jupiter"), 1, argvF);
52 task = MSG_task_create("task on with proc", task_comp_size, task_comm_size, NULL);
53 XBT_INFO("Sending \"%s\"", task->name);
54 MSG_task_send_with_timeout(task, mailbox, 1);
56 task = MSG_task_create("finalize", 0, 0, 0);
57 XBT_INFO("Sending \"%s\"", task->name);
58 MSG_task_send_with_timeout(task, mailbox, 1);
60 XBT_INFO("Goodbye now!");
64 /** Receiver function */
65 int slave(int argc, char *argv[])
67 msg_task_t task = NULL;
68 _XBT_GNUC_UNUSED int res;
72 sprintf(mailbox, "jupi");
75 res = MSG_task_receive(&(task), mailbox);
76 xbt_assert(res == MSG_OK, "MSG_task_get failed");
78 if (!strcmp(MSG_task_get_name(task), "finalize")) {
79 MSG_task_destroy(task);
82 MSG_task_execute(task);
83 XBT_INFO("Task \"%s\" done", MSG_task_get_name(task));
85 MSG_task_destroy(task);
89 XBT_INFO("I'm done. See you!");
94 int main(int argc, char *argv[])
97 const char *platform_file;
98 const char *application_file;
100 MSG_init(&argc, argv);
102 printf("Usage: %s platform_file deployment_file\n", argv[0]);
103 printf("example: %s msg_platform.xml msg_deployment.xml\n", argv[0]);
106 platform_file = argv[1];
107 application_file = argv[2];
109 /* MSG_config("workstation/model","KCCFLN05"); */
110 { /* Simulation setting */
111 MSG_create_environment(platform_file);
113 { /* Application deployment */
114 MSG_function_register("master", master);
115 MSG_function_register("slave", slave);
117 MSG_launch_application(application_file);
121 XBT_INFO("Simulation time %g", MSG_get_clock());