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. */
7 /** @addtogroup MSG_examples
9 * - <b>tracing/categories.c</b> This is a master/slave program where the master creates
10 * tasks, send them to the slaves. For each task received, the slave executes
11 * it and then destroys it. This program declares several tracing categories that are
12 * used to classify tasks. When the program is executed, the tracing mechanism registers
13 * the resource utilization of hosts and links according to these categories. You might
14 * want to run this program with the following parameters:
16 * --cfg=tracing/categorized:yes
17 * --cfg=tracing/uncategorized:yes
18 * --cfg=viva/categorized:viva_cat.plist
19 * --cfg=viva/uncategorized:viva_uncat.plist
20 * (See \ref tracing_tracing_options for details)
25 #include "xbt/sysdep.h" /* calloc, printf */
27 /* Create a log channel to have nice outputs. */
29 #include "xbt/asserts.h"
30 XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test,
31 "Messages specific for this msg example");
32 int master(int argc, char *argv[]);
33 int slave(int argc, char *argv[]);
35 /** Emitter function */
36 int master(int argc, char *argv[])
38 long number_of_tasks = atol(argv[1]);
39 long slaves_count = atol(argv[4]);
42 for (i = 0; i < number_of_tasks; i++) {
43 msg_task_t task = NULL;
45 //creating task and setting its category
47 task = MSG_task_create("task_compute", 10000000, 0, NULL);
48 MSG_task_set_category(task, "compute");
50 task = MSG_task_create("task_request", 10, 10, NULL);
51 MSG_task_set_category(task, "request");
53 task = MSG_task_create("task_data", 10, 10000000, NULL);
54 MSG_task_set_category(task, "data");
56 MSG_task_send(task, "master_mailbox");
59 for (i = 0; i < slaves_count; i++) {
60 msg_task_t finalize = MSG_task_create("finalize", 0, 1000, 0);
61 MSG_task_set_category(finalize, "finalize");
62 MSG_task_send(finalize, "master_mailbox");
68 /** Receiver function */
69 int slave(int argc, char *argv[])
71 msg_task_t task = NULL;
74 MSG_task_receive(&(task), "master_mailbox");
76 if (!strcmp(MSG_task_get_name(task), "finalize")) {
77 MSG_task_destroy(task);
81 MSG_task_execute(task);
82 MSG_task_destroy(task);
89 int main(int argc, char *argv[])
91 MSG_init(&argc, argv);
93 printf("Usage: %s platform_file deployment_file\n", argv[0]);
97 char *platform_file = argv[1];
98 char *deployment_file = argv[2];
99 MSG_create_environment(platform_file);
101 //declaring user categories with RGB colors
102 TRACE_category_with_color ("compute", "1 0 0"); //red
103 TRACE_category_with_color ("request", "0 1 0"); //green
104 TRACE_category_with_color ("data", "0 0 1"); //blue
105 TRACE_category_with_color ("finalize", "0 0 0");//black
107 MSG_function_register("master", master);
108 MSG_function_register("slave", slave);
109 MSG_launch_application(deployment_file);