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. */
7 /** @addtogroup MSG_examples
9 * - <b>tracing/categories.c</b> example with the declaration of multiple categories
14 #include "xbt/sysdep.h" /* calloc, printf */
16 /* Create a log channel to have nice outputs. */
18 #include "xbt/asserts.h"
19 XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test,
20 "Messages specific for this msg example");
21 int master(int argc, char *argv[]);
22 int slave(int argc, char *argv[]);
24 /** Emitter function */
25 int master(int argc, char *argv[])
27 long number_of_tasks = atol(argv[1]);
28 long slaves_count = atol(argv[4]);
31 for (i = 0; i < number_of_tasks; i++) {
34 //creating task and setting its category
36 task = MSG_task_create("task_compute", 10000000, 0, NULL);
37 TRACE_msg_set_task_category(task, "compute");
39 task = MSG_task_create("task_request", 10, 10, NULL);
40 TRACE_msg_set_task_category(task, "request");
42 task = MSG_task_create("task_data", 10, 10000000, NULL);
43 TRACE_msg_set_task_category(task, "data");
45 MSG_task_send(task, "master_mailbox");
48 for (i = 0; i < slaves_count; i++) {
49 m_task_t finalize = MSG_task_create("finalize", 0, 1000, 0);
50 TRACE_msg_set_task_category(finalize, "finalize");
51 MSG_task_send(finalize, "master_mailbox");
57 /** Receiver function */
58 int slave(int argc, char *argv[])
63 MSG_task_receive(&(task), "master_mailbox");
65 if (!strcmp(MSG_task_get_name(task), "finalize")) {
66 MSG_task_destroy(task);
70 MSG_task_execute(task);
71 MSG_task_destroy(task);
78 int main(int argc, char *argv[])
80 MSG_global_init(&argc, argv);
82 printf("Usage: %s platform_file deployment_file\n", argv[0]);
86 char *platform_file = argv[1];
87 char *deployment_file = argv[2];
88 MSG_create_environment(platform_file);
90 //declaring user categories with RGB colors
91 TRACE_category_with_color ("compute", "1 0 0"); //red
92 TRACE_category_with_color ("request", "0 1 0"); //green
93 TRACE_category_with_color ("data", "0 0 1"); //blue
94 TRACE_category_with_color ("finalize", "0 0 0");//black
96 MSG_function_register("master", master);
97 MSG_function_register("slave", slave);
98 MSG_launch_application(deployment_file);