1 /* Copyright (c) 2010. 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. */
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");
16 int master(int argc, char *argv[]);
17 int slave(int argc, char *argv[]);
19 /** Emitter function */
20 int master(int argc, char *argv[])
22 long number_of_tasks = atol(argv[1]);
23 long slaves_count = atol(argv[4]);
26 for (i = 0; i < number_of_tasks; i++) {
29 //creating task and setting its category
31 task = MSG_task_create("task_compute", 10000000, 0, NULL);
32 TRACE_msg_set_task_category(task, "compute");
34 task = MSG_task_create("task_request", 10, 10, NULL);
35 TRACE_msg_set_task_category(task, "request");
37 task = MSG_task_create("task_data", 10, 10000000, NULL);
38 TRACE_msg_set_task_category(task, "data");
40 MSG_task_send(task, "master_mailbox");
43 for (i = 0; i < slaves_count; i++) {
44 m_task_t finalize = MSG_task_create("finalize", 0, 1000, 0);
45 TRACE_msg_set_task_category(finalize, "finalize");
46 MSG_task_send(finalize, "master_mailbox");
52 /** Receiver function */
53 int slave(int argc, char *argv[])
58 MSG_task_receive(&(task), "master_mailbox");
60 if (!strcmp(MSG_task_get_name(task), "finalize")) {
61 MSG_task_destroy(task);
65 MSG_task_execute(task);
66 MSG_task_destroy(task);
73 int main(int argc, char *argv[])
75 MSG_global_init(&argc, argv);
77 printf("Usage: %s platform_file deployment_file\n", argv[0]);
81 char *platform_file = argv[1];
82 char *deployment_file = argv[2];
83 MSG_create_environment(platform_file);
85 //declaring user categories with RGB colors
86 TRACE_category_with_color ("compute", "1 0 0"); //red
87 TRACE_category_with_color ("request", "0 1 0"); //green
88 TRACE_category_with_color ("data", "0 0 1"); //blue
89 TRACE_category_with_color ("finalize", "0 0 0");//black
91 MSG_function_register("master", master);
92 MSG_function_register("slave", slave);
93 MSG_launch_application(deployment_file);